Exemplo n.º 1
0
/*
 * open the VCC
 */
void
patm_rx_vcc_open(struct patm_softc *sc, struct patm_vcc *vcc)
{
	uint32_t w1 = IDT_RCT_OPEN;

	patm_debug(sc, VCC, "%u.%u RX opening", vcc->vcc.vpi, vcc->vcc.vci);

	switch (vcc->vcc.aal) {
	  case ATMIO_AAL_0:
		w1 |= IDT_RCT_AAL0 | IDT_RCT_FBP2 | IDT_RCT_RCI;
		break;
	  case ATMIO_AAL_34:
		w1 |= IDT_RCT_AAL34;
		break;
	  case ATMIO_AAL_5:
		w1 |= IDT_RCT_AAL5;
		break;
	  case ATMIO_AAL_RAW:
		w1 |= IDT_RCT_AALRAW | IDT_RCT_RCI;
		break;
	}

	if (vcc->cid != 0)
		patm_sram_write4(sc, sc->mmap->rct + vcc->cid *
		    IDT_RCT_ENTRY_SIZE, w1, 0, 0, 0xffffffff);
	else {
		/* switch the interface into promiscuous mode */
		patm_nor_write(sc, IDT_NOR_CFG, patm_nor_read(sc, IDT_NOR_CFG) |
		    IDT_CFG_ICAPT | IDT_CFG_VPECA);
	}

	vcc->vflags |= PATM_VCC_RX_OPEN;
}
Exemplo n.º 2
0
/*
 * Try to close the given VCC
 */
static int
patm_close_vcc(struct patm_softc *sc, struct atmio_closevcc *arg)
{
	u_int cid;
	struct patm_vcc *vcc;
	int error = 0;

	patm_debug(sc, VCC, "Close VCC: %u.%u", arg->vpi, arg->vci);

	if (!LEGAL_VPI(sc, arg->vpi) || !LEGAL_VCI(sc, arg->vci))
		return (EINVAL);
	cid = PATM_CID(sc, arg->vpi, arg->vci);

	mtx_lock(&sc->mtx);
	if (!(sc->ifp->if_drv_flags & IFF_DRV_RUNNING)) {
		/* stopped while we have analyzed the arguments */
		error = EIO;
		goto done;
	}

	vcc = sc->vccs[cid];
	if (vcc == NULL || !(vcc->vflags & PATM_VCC_OPEN)) {
		error = ENOENT;
		goto done;
	}

	if (vcc->vflags & PATM_VCC_TX_OPEN)
		patm_tx_vcc_close(sc, vcc);
	if (vcc->vflags & PATM_VCC_RX_OPEN)
		patm_rx_vcc_close(sc, vcc);

	if (vcc->vcc.flags & ATMIO_FLAG_ASYNC)
		goto done;

	while (vcc->vflags & (PATM_VCC_TX_CLOSING | PATM_VCC_RX_CLOSING)) {
		cv_wait(&sc->vcc_cv, &sc->mtx);
		if (!(sc->ifp->if_drv_flags & IFF_DRV_RUNNING)) {
			/* ups, has been stopped */
			error = EIO;
			goto done;
		}
	}

	if (!(vcc->vcc.flags & ATMIO_FLAG_NOTX))
		patm_tx_vcc_closed(sc, vcc);
	if (!(vcc->vcc.flags & ATMIO_FLAG_NORX))
		patm_rx_vcc_closed(sc, vcc);

	patm_vcc_closed(sc, vcc);

  done:
	mtx_unlock(&sc->mtx);

	return (error);
}
Exemplo n.º 3
0
void
patm_load_vc(struct patm_softc *sc, struct patm_vcc *vcc, int reload)
{

	patm_debug(sc, VCC, "Open VCC: opening");
	if (!(vcc->vcc.flags & ATMIO_FLAG_NOTX))
		patm_tx_vcc_open(sc, vcc);
	if (!(vcc->vcc.flags & ATMIO_FLAG_NORX))
		patm_rx_vcc_open(sc, vcc);

	if (!reload) {
		/* inform management about non-NG and NG-PVCs */
		if (!(vcc->vcc.flags & ATMIO_FLAG_NG) ||
		     (vcc->vcc.flags & ATMIO_FLAG_PVC))
			ATMEV_SEND_VCC_CHANGED(IFP2IFATM(sc->ifp), vcc->vcc.vpi,
			    vcc->vcc.vci, 1);
	}

	patm_debug(sc, VCC, "Open VCC: now open");
}
Exemplo n.º 4
0
/*
 * Stop the card and reset it
 */
void
patm_reset(struct patm_softc *sc)
{

	patm_debug(sc, ATTACH, "resetting...");

	patm_nor_write(sc, IDT_NOR_CFG, IDT_CFG_SWRST);
	DELAY(200);
	patm_nor_write(sc, IDT_NOR_CFG, 0);
	DELAY(200);

	patm_nor_write(sc, IDT_NOR_RSQH, 0);
	patm_nor_write(sc, IDT_NOR_TSQH, 0);

	patm_nor_write(sc, IDT_NOR_GP, IDT_GP_PHY_RST);
	DELAY(50);
	patm_nor_write(sc, IDT_NOR_GP, IDT_GP_EEDO | IDT_GP_EECS);
	DELAY(50);
}
Exemplo n.º 5
0
/* close the given vcc for transmission */
void
patm_rx_vcc_close(struct patm_softc *sc, struct patm_vcc *vcc)
{
	u_int w1;

	patm_debug(sc, VCC, "%u.%u RX closing", vcc->vcc.vpi, vcc->vcc.vci);

	if (vcc->cid == 0) {
		/* switch off promiscuous mode */
		patm_nor_write(sc, IDT_NOR_CFG, patm_nor_read(sc, IDT_NOR_CFG) &
		    ~(IDT_CFG_ICAPT | IDT_CFG_VPECA));
		vcc->vflags &= ~PATM_VCC_RX_OPEN;
		return;
	}

	/* close the connection but keep state */
	w1 = rct_read(sc, vcc->cid, 0);
	w1 &= ~IDT_RCT_OPEN;
	rct_write(sc, vcc->cid, 0, w1);

	/* minimum idle count */
	w1 = (w1 & ~IDT_RCT_IACT_CNT_MASK) | (1 << IDT_RCT_IACT_CNT_SHIFT);
	rct_write(sc, vcc->cid, 0, w1);

	/* initialize scan */
	patm_nor_write(sc, IDT_NOR_IRCP, vcc->cid);

	vcc->vflags &= ~PATM_VCC_RX_OPEN;
	vcc->vflags |= PATM_VCC_RX_CLOSING;

	/*
	 * check the RSQ
	 * This is a hack. The problem is, that although an entry is written
	 * to the RSQ, no interrupt is generated. Also we must wait 1 cell
	 * time for the SAR to process the scan of our connection.
	 */
	DELAY(1);
	patm_intr_rsq(sc);
}
Exemplo n.º 6
0
/*
 * Handle the given receive status queue entry
 */
void
patm_rx(struct patm_softc *sc, struct idt_rsqe *rsqe)
{
	struct mbuf *m;
	void *buf;
	u_int stat, cid, w, cells, len, h;
	struct patm_vcc *vcc;
	struct atm_pseudohdr aph;
	u_char *trail;

	cid = le32toh(rsqe->cid);
	stat = le32toh(rsqe->stat);
	h = le32toh(rsqe->handle);

	cid = PATM_CID(sc, IDT_RSQE_VPI(cid), IDT_RSQE_VCI(cid));
	vcc = sc->vccs[cid];

	if (IDT_RSQE_TYPE(stat) == IDT_RSQE_IDLE) {
		/* connection has gone idle */
		if (stat & IDT_RSQE_BUF)
			patm_rcv_free(sc, patm_rcv_handle(sc, h), h);

		w = rct_read(sc, cid, 0);
		if (w != 0 && !(w & IDT_RCT_OPEN))
			rct_write(sc, cid, 0, 0);
		if (vcc != NULL && (vcc->vflags & PATM_VCC_RX_CLOSING)) {
			patm_debug(sc, VCC, "%u.%u RX closed", vcc->vcc.vpi,
			    vcc->vcc.vci);
			vcc->vflags &= ~PATM_VCC_RX_CLOSING;
			if (vcc->vcc.flags & ATMIO_FLAG_ASYNC) {
				patm_rx_vcc_closed(sc, vcc);
				if (!(vcc->vflags & PATM_VCC_OPEN))
					patm_vcc_closed(sc, vcc);
			} else
				cv_signal(&sc->vcc_cv);
		}
		return;
	}

	buf = patm_rcv_handle(sc, h);

	if (vcc == NULL || (vcc->vflags & PATM_VCC_RX_OPEN) == 0) {
		patm_rcv_free(sc, buf, h);
		return;
	}

	cells = IDT_RSQE_CNT(stat);
	KASSERT(cells > 0, ("zero cell count"));

	if (vcc->vcc.aal == ATMIO_AAL_0) {
		/* deliver this packet as it is */
		if ((m = patm_rcv_mbuf(sc, buf, h, 1)) == NULL)
			return;

		m->m_len = cells * 48;
		m->m_pkthdr.len = m->m_len;
		m->m_pkthdr.rcvif = sc->ifp;

	} else if (vcc->vcc.aal == ATMIO_AAL_34) {
		/* XXX AAL3/4 */
		patm_rcv_free(sc, buf, h);
		return;

	} else if (vcc->vcc.aal == ATMIO_AAL_5) {
		if (stat & IDT_RSQE_CRC) {
			if_inc_counter(sc->ifp, IFCOUNTER_IERRORS, 1);
			if (vcc->chain != NULL) {
				m_freem(vcc->chain);
				vcc->chain = vcc->last = NULL;
			}
			return;
		}

		/* append to current chain */
		if (vcc->chain == NULL) {
			if ((m = patm_rcv_mbuf(sc, buf, h, 1)) == NULL)
				return;
			m->m_len = cells * 48;
			m->m_pkthdr.len = m->m_len;
			m->m_pkthdr.rcvif = sc->ifp;
			vcc->chain = vcc->last = m;
		} else {
			if ((m = patm_rcv_mbuf(sc, buf, h, 0)) == NULL)
				return;
			m->m_len = cells * 48;
			vcc->last->m_next = m;
			vcc->last = m;
			vcc->chain->m_pkthdr.len += m->m_len;
		}

		if (!(stat & IDT_RSQE_EPDU))
			return;

		trail = mtod(m, u_char *) + m->m_len - 6;
		len = (trail[0] << 8) + trail[1];

		if ((u_int)vcc->chain->m_pkthdr.len < len + 8) {
			patm_printf(sc, "%s: bad aal5 lengths %u %u\n",
			    __func__, (u_int)m->m_pkthdr.len, len);
			m_freem(vcc->chain);
			vcc->chain = vcc->last = NULL;
			return;
		}
		m->m_len -= vcc->chain->m_pkthdr.len - len;
		KASSERT(m->m_len >= 0, ("bad last mbuf"));

		m = vcc->chain;
		vcc->chain = vcc->last = NULL;
		m->m_pkthdr.len = len;
	} else
Exemplo n.º 7
0
/* transmission side finally closed */
void
patm_rx_vcc_closed(struct patm_softc *sc, struct patm_vcc *vcc)
{
	patm_debug(sc, VCC, "%u.%u RX finally closed",
	    vcc->vcc.vpi, vcc->vcc.vci);
}
Exemplo n.º 8
0
/*
 * Open the VCC with the given parameters
 */
static int
patm_open_vcc(struct patm_softc *sc, struct atmio_openvcc *arg)
{
	u_int cid;
	struct patm_vcc *vcc;
	int error = 0;

	patm_debug(sc, VCC, "Open VCC: %u.%u flags=%#x", arg->param.vpi,
	    arg->param.vci, arg->param.flags);

	if (!LEGAL_VPI(sc, arg->param.vpi) || !LEGAL_VCI(sc, arg->param.vci))
		return (EINVAL);
	if (arg->param.vci == 0 && (arg->param.vpi != 0 ||
	    !(arg->param.flags & ATMIO_FLAG_NOTX) ||
	    arg->param.aal != ATMIO_AAL_RAW))
		return (EINVAL);
	cid = PATM_CID(sc, arg->param.vpi, arg->param.vci);

	if ((arg->param.flags & ATMIO_FLAG_NOTX) &&
	    (arg->param.flags & ATMIO_FLAG_NORX))
		return (EINVAL);

	if ((arg->param.traffic == ATMIO_TRAFFIC_ABR) &&
	    (arg->param.flags & (ATMIO_FLAG_NOTX | ATMIO_FLAG_NORX)))
		return (EINVAL);

	/* allocate vcc */
	vcc = uma_zalloc(sc->vcc_zone, M_NOWAIT | M_ZERO);
	if (vcc == NULL)
		return (ENOMEM);

	mtx_lock(&sc->mtx);
	if (!(sc->ifp->if_drv_flags & IFF_DRV_RUNNING)) {
		/* stopped while we have analyzed the arguments */
		error = EIO;
		goto done;
	}
	if (sc->vccs[cid] != NULL) {
		/* ups, already open */
		error = EBUSY;
		goto done;
	}

	/* check some parameters */
	vcc->cid = cid;
	vcc->vcc = arg->param;
	vcc->vflags = 0;
	vcc->rxhand = arg->rxhand;
	switch (vcc->vcc.aal) {

	  case ATMIO_AAL_0:
	  case ATMIO_AAL_34:
	  case ATMIO_AAL_5:
		break;

	  case ATMIO_AAL_RAW:
		if (arg->param.vci == 0 &&
		    !(arg->param.flags & ATMIO_FLAG_NOTX)) {
			error = EINVAL;
			goto done;
		}
		break;

	  default:
		error = EINVAL;
		goto done;
	}
	switch (vcc->vcc.traffic) {

	  case ATMIO_TRAFFIC_VBR:
	  case ATMIO_TRAFFIC_UBR:
	  case ATMIO_TRAFFIC_CBR:
	  case ATMIO_TRAFFIC_ABR:
		break;

	  default:
		error = EINVAL;
		goto done;
	}

	/* initialize */
	vcc->chain = NULL;
	vcc->last = NULL;
	vcc->ibytes = vcc->ipackets = 0;
	vcc->obytes = vcc->opackets = 0;

	/* ask the TX and RX sides */
	patm_debug(sc, VCC, "Open VCC: asking Rx/Tx");
	if (!(vcc->vcc.flags & ATMIO_FLAG_NOTX) &&
	     (error = patm_tx_vcc_can_open(sc, vcc)) != 0)
		goto done;
	if (!(vcc->vcc.flags & ATMIO_FLAG_NORX) &&
	     (error = patm_rx_vcc_can_open(sc, vcc)) != 0)
		goto done;

	/* ok - go ahead */
	sc->vccs[cid] = vcc;
	patm_load_vc(sc, vcc, 0);

	/* don't free below */
	vcc = NULL;
	sc->vccs_open++;

	/* done */
  done:
	mtx_unlock(&sc->mtx);
	if (vcc != NULL)
		uma_zfree(sc->vcc_zone, vcc);
	return (error);
}
Exemplo n.º 9
0
int
patm_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
{
	struct ifreq *ifr = (struct ifreq *)data;
	struct ifaddr *ifa = (struct ifaddr *)data;
	struct patm_softc *sc = ifp->if_softc;
	int error = 0;
	uint32_t cfg;
	struct atmio_vcctable *vtab;

	switch (cmd) {

	  case SIOCSIFADDR:
		mtx_lock(&sc->mtx);
		ifp->if_flags |= IFF_UP;
		if (!(ifp->if_drv_flags & IFF_DRV_RUNNING))
			patm_initialize(sc);
		switch (ifa->ifa_addr->sa_family) {

#ifdef INET
		  case AF_INET:
		  case AF_INET6:
			ifa->ifa_rtrequest = atm_rtrequest;
			break;
#endif
		  default:
			break;
		}
		mtx_unlock(&sc->mtx);
		break;

	  case SIOCSIFFLAGS:
		mtx_lock(&sc->mtx);
		if (ifp->if_flags & IFF_UP) {
			if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
				patm_initialize(sc);
			}
		} else {
			if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
				patm_stop(sc);
			}
		}
		mtx_unlock(&sc->mtx);
		break;

	  case SIOCGIFMEDIA:
	  case SIOCSIFMEDIA:
		error = ifmedia_ioctl(ifp, ifr, &sc->media, cmd);

		/*
		 * We need to toggle unassigned/idle cells ourself because
		 * the 77252 generates null cells for spacing. When switching
		 * null cells of it gets the timing wrong.
		 */
		mtx_lock(&sc->mtx);
		if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
			if (sc->utopia.state & UTP_ST_UNASS) {
				if (!(sc->flags & PATM_UNASS)) {
					cfg = patm_nor_read(sc, IDT_NOR_CFG);
					cfg &= ~IDT_CFG_IDLECLP;
					patm_nor_write(sc, IDT_NOR_CFG, cfg);
					sc->flags |= PATM_UNASS;
				}
			} else {
				if (sc->flags & PATM_UNASS) {
					cfg = patm_nor_read(sc, IDT_NOR_CFG);
					cfg |= IDT_CFG_IDLECLP;
					patm_nor_write(sc, IDT_NOR_CFG, cfg);
					sc->flags &= ~PATM_UNASS;
				}
			}
		} else {
			if (sc->utopia.state & UTP_ST_UNASS)
				sc->flags |= PATM_UNASS;
			else
				sc->flags &= ~PATM_UNASS;
		}
		mtx_unlock(&sc->mtx);
		break;

	  case SIOCSIFMTU:
		/*
		 * Set the interface MTU.
		 */
		if (ifr->ifr_mtu > ATMMTU)
			error = EINVAL;
		else
			ifp->if_mtu = ifr->ifr_mtu;
		break;

	  case SIOCATMOPENVCC:		/* kernel internal use */
		error = patm_open_vcc(sc, (struct atmio_openvcc *)data);
		break;

	  case SIOCATMCLOSEVCC:		/* kernel internal use */
		error = patm_close_vcc(sc, (struct atmio_closevcc *)data);
		break;

	  case SIOCATMGVCCS:	/* external use */
#ifdef CPU_CHERI
#error Unvalidatable ifr_data use.  Unsafe with CheriABI.
#endif
		/* return vcc table */
		vtab = atm_getvccs((struct atmio_vcc **)sc->vccs,
		    sc->mmap->max_conn, sc->vccs_open, &sc->mtx, 1);
		error = copyout(vtab, ifr->ifr_data, sizeof(*vtab) +
		    vtab->count * sizeof(vtab->vccs[0]));
		free(vtab, M_DEVBUF);
		break;

	  case SIOCATMGETVCCS:	/* netgraph internal use */
		vtab = atm_getvccs((struct atmio_vcc **)sc->vccs,
		    sc->mmap->max_conn, sc->vccs_open, &sc->mtx, 0);
		if (vtab == NULL) {
			error = ENOMEM;
			break;
		}
		*(void **)data = vtab;
		break;

	  default:
		patm_debug(sc, IOCTL, "unknown cmd=%08lx arg=%p", cmd, data);
		error = EINVAL;
		break;
	}

	return (error);
}
Exemplo n.º 10
0
/*
 * Start the card. This assumes the mutex to be held
 */
void
patm_initialize(struct patm_softc *sc)
{
	uint32_t cfg;
	u_int i;

	patm_debug(sc, ATTACH, "configuring...");

	/* clear SRAM */
	for (i = 0; i < sc->mmap->sram * 1024; i += 4)
		patm_sram_write4(sc, i, 0, 0, 0, 0);
	patm_scd_init(sc);

	/* configuration register. Setting NOIDLE makes the timing wrong! */
	cfg = IDT_CFG_TXFIFO9 | IDT_CFG_RXQ512 | PATM_CFG_VPI |
	    /* IDT_CFG_NOIDLE | */ sc->mmap->rxtab;
	if (!(sc->flags & PATM_UNASS))
		cfg |= IDT_CFG_IDLECLP;
	patm_nor_write(sc, IDT_NOR_CFG, cfg);

	/* clean all the status queues and the Raw handle */
	memset(sc->tsq, 0, sc->sq_size);

	/* initialize RSQ */
	patm_debug(sc, ATTACH, "RSQ %llx", (unsigned long long)sc->rsq_phy);
	patm_nor_write(sc, IDT_NOR_RSQB, sc->rsq_phy);
	patm_nor_write(sc, IDT_NOR_RSQT, sc->rsq_phy);
	patm_nor_write(sc, IDT_NOR_RSQH, 0);
	sc->rsq_last = PATM_RSQ_SIZE - 1;

	/* initialize TSTB */
	patm_nor_write(sc, IDT_NOR_TSTB, sc->mmap->tst1base << 2);
	patm_tst_init(sc);

	/* initialize TSQ */
	for (i = 0; i < IDT_TSQ_SIZE; i++)
		sc->tsq[i].stamp = htole32(IDT_TSQE_EMPTY);
	patm_nor_write(sc, IDT_NOR_TSQB, sc->tsq_phy);
	patm_nor_write(sc, IDT_NOR_TSQH, 0);
	patm_nor_write(sc, IDT_NOR_TSQT, 0);
	sc->tsq_next = sc->tsq;

	/* GP */
#if BYTE_ORDER == BIG_ENDIAN && 0
	patm_nor_write(sc, IDT_NOR_GP, IDT_GP_BIGE);
#else
	patm_nor_write(sc, IDT_NOR_GP, 0);
#endif

	/* VPM */
	patm_nor_write(sc, IDT_NOR_VPM, 0);

	/* RxFIFO */
	patm_nor_write(sc, IDT_NOR_RXFD,
	    IDT_RXFD(sc->mmap->rxfifo_addr, sc->mmap->rxfifo_code));
	patm_nor_write(sc, IDT_NOR_RXFT, 0);
	patm_nor_write(sc, IDT_NOR_RXFH, 0);

	/* RAWHND */
	patm_debug(sc, ATTACH, "RWH %llx",
	    (unsigned long long)sc->rawhnd_phy);
	patm_nor_write(sc, IDT_NOR_RAWHND, sc->rawhnd_phy);

	/* ABRSTD */
	patm_nor_write(sc, IDT_NOR_ABRSTD,
	    IDT_ABRSTD(sc->mmap->abrstd_addr, sc->mmap->abrstd_code));
	for (i = 0; i < sc->mmap->abrstd_size; i++)
		patm_sram_write(sc, sc->mmap->abrstd_addr + i, 0);
	patm_nor_write(sc, IDT_NOR_ABRRQ, 0);
	patm_nor_write(sc, IDT_NOR_VBRRQ, 0);

	/* rate tables */
	if (sc->flags & PATM_25M) {
		for (i = 0; i < patm_rtables_size; i++)
			patm_sram_write(sc, sc->mmap->rtables + i,
			    patm_rtables25[i]);
	} else {
		for (i = 0; i < patm_rtables_size; i++)
			patm_sram_write(sc, sc->mmap->rtables + i,
			    patm_rtables155[i]);
	}
	patm_nor_write(sc, IDT_NOR_RTBL, sc->mmap->rtables << 2);

	/* Maximum deficit */
	patm_nor_write(sc, IDT_NOR_MXDFCT, 32 | IDT_MDFCT_LCI | IDT_MDFCT_LNI);

	/* Free buffer queues */
	patm_nor_write(sc, IDT_NOR_FBQP0, 0);
	patm_nor_write(sc, IDT_NOR_FBQP1, 0);
	patm_nor_write(sc, IDT_NOR_FBQP2, 0);
	patm_nor_write(sc, IDT_NOR_FBQP3, 0);

	patm_nor_write(sc, IDT_NOR_FBQWP0, 0);
	patm_nor_write(sc, IDT_NOR_FBQWP1, 0);
	patm_nor_write(sc, IDT_NOR_FBQWP2, 0);
	patm_nor_write(sc, IDT_NOR_FBQWP3, 0);

	patm_nor_write(sc, IDT_NOR_FBQS0,
	    (SMBUF_THRESHOLD << 28) |
	    (SMBUF_NI_THRESH << 24) |
	    (SMBUF_CI_THRESH << 20) |
	    SMBUF_CELLS);
	patm_nor_write(sc, IDT_NOR_FBQS1,
	    (LMBUF_THRESHOLD << 28) |
	    (LMBUF_NI_THRESH << 24) |
	    (LMBUF_CI_THRESH << 20) |
	    LMBUF_CELLS);
	patm_nor_write(sc, IDT_NOR_FBQS2,
	    (VMBUF_THRESHOLD << 28) | VMBUF_CELLS);
	patm_nor_write(sc, IDT_NOR_FBQS3, 0);

	/* make SCD0 for UBR0 */
	if ((sc->scd0 = patm_scd_alloc(sc)) == NULL) {
		patm_printf(sc, "cannot create UBR0 SCD\n");
		patm_reset(sc);
		return;
	}
	sc->scd0->q.ifq_maxlen = PATM_DLFT_MAXQ;

	patm_scd_setup(sc, sc->scd0);
	patm_tct_setup(sc, sc->scd0, NULL);

	patm_debug(sc, ATTACH, "go...");

	sc->utopia.flags &= ~UTP_FL_POLL_CARRIER;
	sc->ifp->if_drv_flags |= IFF_DRV_RUNNING;

	/* enable interrupts, Tx and Rx paths */
	cfg |= IDT_CFG_RXPTH | IDT_CFG_RXIIMM | IDT_CFG_RAWIE | IDT_CFG_RQFIE |
	    IDT_CFG_TIMOIE | IDT_CFG_FBIE | IDT_CFG_TXENB | IDT_CFG_TXINT |
	    IDT_CFG_TXUIE | IDT_CFG_TXSFI | IDT_CFG_PHYIE;
	patm_nor_write(sc, IDT_NOR_CFG, cfg);

	for (i = 0; i < sc->mmap->max_conn; i++)
		if (sc->vccs[i] != NULL)
			patm_load_vc(sc, sc->vccs[i], 1);

	ATMEV_SEND_IFSTATE_CHANGED(IFP2IFATM(sc->ifp),
	    sc->utopia.carrier == UTP_CARR_OK);
}
Exemplo n.º 11
0
/*
 * Stop the interface
 */
void
patm_stop(struct patm_softc *sc)
{
	u_int i;
	struct mbuf *m;
	struct patm_txmap *map;
	struct patm_scd *scd;

	sc->ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
	sc->utopia.flags |= UTP_FL_POLL_CARRIER;

	patm_reset(sc);

	mtx_lock(&sc->tst_lock);
	i = sc->tst_state;
	sc->tst_state = 0;
	callout_stop(&sc->tst_callout);
	mtx_unlock(&sc->tst_lock);

	if (i != 0) {
		/* this means we are just entering or leaving the timeout.
		 * wait a little bit. Doing this correctly would be more
		 * involved */
		DELAY(1000);
	}

	/*
	 * Give any waiters on closing a VCC a chance. They will stop
	 * to wait if they see that IFF_DRV_RUNNING disappeared.
	 */
	cv_broadcast(&sc->vcc_cv);

	/* free large buffers */
	patm_debug(sc, ATTACH, "freeing large buffers...");
	for (i = 0; i < sc->lbuf_max; i++)
		if (sc->lbufs[i].m != NULL)
			patm_lbuf_free(sc, &sc->lbufs[i]);

	/* free small buffers that are on the card */
	patm_debug(sc, ATTACH, "freeing small buffers...");
	mbp_card_free(sc->sbuf_pool);

	/* free aal0 buffers that are on the card */
	patm_debug(sc, ATTACH, "freeing aal0 buffers...");
	mbp_card_free(sc->vbuf_pool);

	/* freeing partial receive chains and reset vcc state */
	for (i = 0; i < sc->mmap->max_conn; i++) {
		if (sc->vccs[i] != NULL) {
			if (sc->vccs[i]->chain != NULL) {
				m_freem(sc->vccs[i]->chain);
				sc->vccs[i]->chain = NULL;
				sc->vccs[i]->last = NULL;
			}

			if (sc->vccs[i]->vflags & (PATM_VCC_RX_CLOSING |
			    PATM_VCC_TX_CLOSING)) {
				uma_zfree(sc->vcc_zone, sc->vccs[i]);
				sc->vccs[i] = NULL;
			} else {
				/* keep */
				sc->vccs[i]->vflags &= ~PATM_VCC_OPEN;
				sc->vccs[i]->cps = 0;
				sc->vccs[i]->scd = NULL;
			}
		}
	}

	/* stop all active SCDs */
	while ((scd = LIST_FIRST(&sc->scd_list)) != NULL) {
		/* free queue packets */
		for (;;) {
			_IF_DEQUEUE(&scd->q, m);
			if (m == NULL)
				break;
			m_freem(m);
		}

		/* free transmitting packets */
		for (i = 0; i < IDT_TSQE_TAG_SPACE; i++) {
			if ((m = scd->on_card[i]) != NULL) {
				scd->on_card[i] = 0;
				map = m->m_pkthdr.header;

				bus_dmamap_unload(sc->tx_tag, map->map);
				SLIST_INSERT_HEAD(&sc->tx_maps_free, map, link);
				m_freem(m);
			}
		}
		patm_scd_free(sc, scd);
	}
	sc->scd0 = NULL;

	sc->flags &= ~PATM_CLR;

	/* reset raw cell queue */
	sc->rawh = NULL;

	ATMEV_SEND_IFSTATE_CHANGED(IFP2IFATM(sc->ifp),
	    sc->utopia.carrier == UTP_CARR_OK);
}