static void qinit_common(struct queue *q) { spinlock_init_irqsave(&q->lock); qlock_init(&q->rlock); qlock_init(&q->wlock); rendez_init(&q->rr); rendez_init(&q->wr); }
void udpnewconv(struct Proto *udp, struct conv *conv) { /* Fsprotoclone alloc'd our priv struct and attached it to conv already. * Now we need to init it */ struct Udpcb *ucb = (struct Udpcb *)conv->ptcl; qlock_init(&ucb->qlock); }
void netloginit(struct Fs *f) { f->alog = kzmalloc(sizeof(struct Netlog), 0); spinlock_init(&f->alog->lock); qlock_init(&f->alog->qlock); rendez_init(&f->alog->r); }
void ipifcinit(struct Fs *f) { struct Proto *ipifc; ipifc = kzmalloc(sizeof(struct Proto), 0); ipifc->name = "ipifc"; ipifc->connect = ipifcconnect; ipifc->announce = NULL; ipifc->bind = ipifcbind; ipifc->state = ipifcstate; ipifc->create = ipifccreate; ipifc->close = ipifcclose; ipifc->rcv = NULL; ipifc->ctl = ipifcctl; ipifc->advise = NULL; ipifc->stats = ipifcstats; ipifc->inuse = ipifcinuse; ipifc->local = ipifclocal; ipifc->ipproto = -1; ipifc->nc = Maxmedia; ipifc->ptclsize = sizeof(struct Ipifc); f->ipifc = ipifc; /* hack for ipifcremroute, findipifc, ... */ f->self = kzmalloc(sizeof(struct Ipselftab), 0); /* hack for ipforme */ qlock_init(&f->self->qlock); Fsproto(f, ipifc); }
void arpinit(struct Fs *f) { f->arp = kzmalloc(sizeof(struct arp), MEM_WAIT); qlock_init(&f->arp->qlock); rendez_init(&f->arp->rxmtq); f->arp->f = f; f->arp->rxmt = NULL; f->arp->dropf = f->arp->dropl = NULL; ktask("rxmitproc", rxmitproc, f->arp); }
/* * Increment the reference count of a network device. * If id < 0, return an unused ether device. */ static int openfile(struct ether *nif, int id) { ERRSTACK(1); struct netfile *f, **fp, **efp; if (id >= 0) { f = nif->f[id]; if (f == 0) error(Enodev); qlock(&f->qlock); qreopen(f->in); f->inuse++; qunlock(&f->qlock); return id; } qlock(&nif->qlock); if (waserror()) { qunlock(&nif->qlock); nexterror(); } efp = &nif->f[nif->nfile]; for (fp = nif->f; fp < efp; fp++) { f = *fp; if (f == 0) { f = kzmalloc(sizeof(struct netfile), 0); if (f == 0) exhausted("memory"); /* since we lock before netifinit (if we ever call that...) */ qlock_init(&f->qlock); f->in = qopen(nif->limit, Qmsg, 0, 0); if (f->in == NULL) { kfree(f); exhausted("memory"); } *fp = f; qlock(&f->qlock); } else { qlock(&f->qlock); if (f->inuse) { qunlock(&f->qlock); continue; } } f->inuse = 1; qreopen(f->in); netown(f, current->user, 0); qunlock(&f->qlock); qunlock(&nif->qlock); poperror(); return fp - nif->f; } error(Enodev); return -1; /* not reached */ }
/* * set up a new network interface */ void netifinit(struct ether *nif, char *name, int nfile, uint32_t limit) { qlock_init(&nif->qlock); strlcpy(nif->name, name, KNAMELEN); nif->nfile = nfile; nif->f = kzmalloc(nfile * sizeof(struct netfile *), 0); if (nif->f) memset(nif->f, 0, nfile * sizeof(struct netfile *)); else nif->nfile = 0; nif->limit = limit; }
/* * create a pipe, no streams are created until an open */ static struct chan *pipeattach(char *spec) { ERRSTACK(2); Pipe *p; struct chan *c; c = devattach(devname(), spec); p = kzmalloc(sizeof(Pipe), 0); if (p == 0) error(ENOMEM, ERROR_FIXME); if (waserror()) { freepipe(p); nexterror(); } p->pipedir = kzmalloc(sizeof(pipedir), 0); if (p->pipedir == 0) error(ENOMEM, ERROR_FIXME); memmove(p->pipedir, pipedir, sizeof(pipedir)); kstrdup(&p->user, current->user); kref_init(&p->ref, pipe_release, 1); qlock_init(&p->qlock); p->q[0] = qopen(pipealloc.pipeqsize, Qcoalesce, 0, 0); if (p->q[0] == 0) error(ENOMEM, ERROR_FIXME); p->q[1] = qopen(pipealloc.pipeqsize, Qcoalesce, 0, 0); if (p->q[1] == 0) error(ENOMEM, ERROR_FIXME); poperror(); spin_lock(&(&pipealloc)->lock); p->path = ++pipealloc.path; spin_unlock(&(&pipealloc)->lock); c->qid.path = NETQID(2 * p->path, Qdir); c->qid.vers = 0; c->qid.type = QTDIR; c->aux = p; c->dev = 0; /* taps. */ SLIST_INIT(&p->data_taps[0]); /* already = 0; set to be futureproof */ SLIST_INIT(&p->data_taps[1]); spinlock_init(&p->tap_lock); return c; }
struct chan *newchan(void) { struct chan *c; spin_lock(&(&chanalloc)->lock); c = chanalloc.free; if (c != 0) chanalloc.free = c->next; spin_unlock(&(&chanalloc)->lock); if (c == NULL) { c = kzmalloc(sizeof(struct chan), 0); spin_lock(&(&chanalloc)->lock); c->fid = ++chanalloc.fid; c->link = chanalloc.list; chanalloc.list = c; spin_unlock(&(&chanalloc)->lock); spinlock_init(&c->lock); qlock_init(&c->umqlock); } /* if you get an error before associating with a dev, cclose skips calling * the dev's close */ c->type = -1; c->flag = 0; kref_init(&c->ref, chan_release, 1); c->dev = 0; c->offset = 0; c->iounit = 0; c->umh = 0; c->uri = 0; c->dri = 0; c->aux = 0; c->mchan = 0; c->mcp = 0; c->mux = 0; c->mqid.path = 0; c->mqid.vers = 0; c->mqid.type = 0; c->name = 0; c->buf = NULL; c->mountpoint = NULL; return c; }
static void *mlx4_en_add(struct mlx4_dev *dev) { struct mlx4_en_dev *mdev; int i; printk_once(KERN_INFO "%s", mlx4_en_version); mdev = kzmalloc(sizeof(*mdev), KMALLOC_WAIT); if (!mdev) goto err_free_res; if (mlx4_pd_alloc(dev, &mdev->priv_pdn)) goto err_free_dev; if (mlx4_uar_alloc(dev, &mdev->priv_uar)) goto err_pd; mdev->uar_map = ioremap((phys_addr_t) mdev->priv_uar.pfn << PAGE_SHIFT, PAGE_SIZE); if (!mdev->uar_map) goto err_uar; spinlock_init_irqsave(&mdev->uar_lock); mdev->dev = dev; #if 0 // AKAROS_PORT mdev->dma_device = &dev->persist->pdev->dev; #else mdev->dma_device = 0; #endif mdev->pdev = dev->persist->pdev; mdev->device_up = false; mdev->LSO_support = !!(dev->caps.flags & (1 << 15)); if (!mdev->LSO_support) mlx4_warn(mdev, "LSO not supported, please upgrade to later FW version to enable LSO\n"); if (mlx4_mr_alloc(mdev->dev, mdev->priv_pdn, 0, ~0ull, MLX4_PERM_LOCAL_WRITE | MLX4_PERM_LOCAL_READ, 0, 0, &mdev->mr)) { mlx4_err(mdev, "Failed allocating memory region\n"); goto err_map; } if (mlx4_mr_enable(mdev->dev, &mdev->mr)) { mlx4_err(mdev, "Failed enabling memory region\n"); goto err_mr; } /* Build device profile according to supplied module parameters */ if (mlx4_en_get_profile(mdev)) { mlx4_err(mdev, "Bad module parameters, aborting\n"); goto err_mr; } /* Configure which ports to start according to module parameters */ mdev->port_cnt = 0; mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_ETH) mdev->port_cnt++; #if 0 // AKAROS_PORT /* Initialize time stamp mechanism */ if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS) mlx4_en_init_timestamp(mdev); #endif /* Set default number of RX rings*/ mlx4_en_set_num_rx_rings(mdev); /* Create our own workqueue for reset/multicast tasks * Note: we cannot use the shared workqueue because of deadlocks caused * by the rtnl lock */ mdev->workqueue = create_singlethread_workqueue("mlx4_en"); if (!mdev->workqueue) goto err_mr; /* At this stage all non-port specific tasks are complete: * mark the card state as up */ qlock_init(&mdev->state_lock); mdev->device_up = true; /* Setup ports */ #if 0 // AKAROS_PORT /* Create a netdev for each port */ mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_ETH) { mlx4_info(mdev, "Activating port:%d\n", i); if (mlx4_en_init_netdev(mdev, i, &mdev->profile.prof[i])) mdev->pndev[i] = NULL; }