ipath_init_chip.c

来自「LINUX 2.6.17.4的源码」· C语言 代码 · 共 959 行 · 第 1/2 页

C
959
字号
	 */	dd->ipath_flags |= IPATH_INITTED;	/*	 * init our shadow copies of head from tail values, and write	 * head values to match.	 */	val = ipath_read_ureg32(dd, ur_rcvegrindextail, 0);	(void)ipath_write_ureg(dd, ur_rcvegrindexhead, val, 0);	dd->ipath_port0head = ipath_read_ureg32(dd, ur_rcvhdrtail, 0);	/* Initialize so we interrupt on next packet received */	(void)ipath_write_ureg(dd, ur_rcvhdrhead,			       dd->ipath_rhdrhead_intr_off |			       dd->ipath_port0head, 0);	/*	 * by now pioavail updates to memory should have occurred, so	 * copy them into our working/shadow registers; this is in	 * case something went wrong with abort, but mostly to get the	 * initial values of the generation bit correct.	 */	for (i = 0; i < dd->ipath_pioavregs; i++) {		__le64 val;		/*		 * Chip Errata bug 6641; even and odd qwords>3 are swapped.		 */		if (i > 3) {			if (i & 1)				val = dd->ipath_pioavailregs_dma[i - 1];			else				val = dd->ipath_pioavailregs_dma[i + 1];		}		else			val = dd->ipath_pioavailregs_dma[i];		dd->ipath_pioavailshadow[i] = le64_to_cpu(val);	}	/* can get counters, stats, etc. */	dd->ipath_flags |= IPATH_PRESENT;}static int init_housekeeping(struct ipath_devdata *dd,			     struct ipath_portdata **pdp, int reinit){	char boardn[32];	int ret = 0;	/*	 * have to clear shadow copies of registers at init that are	 * not otherwise set here, or all kinds of bizarre things	 * happen with driver on chip reset	 */	dd->ipath_rcvhdrsize = 0;	/*	 * Don't clear ipath_flags as 8bit mode was set before	 * entering this func. However, we do set the linkstate to	 * unknown, so we can watch for a transition.	 * PRESENT is set because we want register reads to work,	 * and the kernel infrastructure saw it in config space;	 * We clear it if we have failures.	 */	dd->ipath_flags |= IPATH_LINKUNK | IPATH_PRESENT;	dd->ipath_flags &= ~(IPATH_LINKACTIVE | IPATH_LINKARMED |			     IPATH_LINKDOWN | IPATH_LINKINIT);	ipath_cdbg(VERBOSE, "Try to read spc chip revision\n");	dd->ipath_revision =		ipath_read_kreg64(dd, dd->ipath_kregs->kr_revision);	/*	 * set up fundamental info we need to use the chip; we assume	 * if the revision reg and these regs are OK, we don't need to	 * special case the rest	 */	dd->ipath_sregbase =		ipath_read_kreg32(dd, dd->ipath_kregs->kr_sendregbase);	dd->ipath_cregbase =		ipath_read_kreg32(dd, dd->ipath_kregs->kr_counterregbase);	dd->ipath_uregbase =		ipath_read_kreg32(dd, dd->ipath_kregs->kr_userregbase);	ipath_cdbg(VERBOSE, "ipath_kregbase %p, sendbase %x usrbase %x, "		   "cntrbase %x\n", dd->ipath_kregbase, dd->ipath_sregbase,		   dd->ipath_uregbase, dd->ipath_cregbase);	if ((dd->ipath_revision & 0xffffffff) == 0xffffffff	    || (dd->ipath_sregbase & 0xffffffff) == 0xffffffff	    || (dd->ipath_cregbase & 0xffffffff) == 0xffffffff	    || (dd->ipath_uregbase & 0xffffffff) == 0xffffffff) {		ipath_dev_err(dd, "Register read failures from chip, "			      "giving up initialization\n");		dd->ipath_flags &= ~IPATH_PRESENT;		ret = -ENODEV;		goto done;	}	/* clear the initial reset flag, in case first driver load */	ipath_write_kreg(dd, dd->ipath_kregs->kr_errorclear,			 INFINIPATH_E_RESET);	if (reinit)		ret = init_chip_reset(dd, pdp);	else		ret = init_chip_first(dd, pdp);	if (ret)		goto done;	ipath_cdbg(VERBOSE, "Revision %llx (PCI %x), %u ports, %u tids, "		   "%u egrtids\n", (unsigned long long) dd->ipath_revision,		   dd->ipath_pcirev, dd->ipath_portcnt, dd->ipath_rcvtidcnt,		   dd->ipath_rcvegrcnt);	if (((dd->ipath_revision >> INFINIPATH_R_SOFTWARE_SHIFT) &	     INFINIPATH_R_SOFTWARE_MASK) != IPATH_CHIP_SWVERSION) {		ipath_dev_err(dd, "Driver only handles version %d, "			      "chip swversion is %d (%llx), failng\n",			      IPATH_CHIP_SWVERSION,			      (int)(dd->ipath_revision >>				    INFINIPATH_R_SOFTWARE_SHIFT) &			      INFINIPATH_R_SOFTWARE_MASK,			      (unsigned long long) dd->ipath_revision);		ret = -ENOSYS;		goto done;	}	dd->ipath_majrev = (u8) ((dd->ipath_revision >>				  INFINIPATH_R_CHIPREVMAJOR_SHIFT) &				 INFINIPATH_R_CHIPREVMAJOR_MASK);	dd->ipath_minrev = (u8) ((dd->ipath_revision >>				  INFINIPATH_R_CHIPREVMINOR_SHIFT) &				 INFINIPATH_R_CHIPREVMINOR_MASK);	dd->ipath_boardrev = (u8) ((dd->ipath_revision >>				    INFINIPATH_R_BOARDID_SHIFT) &				   INFINIPATH_R_BOARDID_MASK);	ret = dd->ipath_f_get_boardname(dd, boardn, sizeof boardn);	snprintf(dd->ipath_boardversion, sizeof(dd->ipath_boardversion),		 "Driver %u.%u, %s, InfiniPath%u %u.%u, PCI %u, "		 "SW Compat %u\n",		 IPATH_CHIP_VERS_MAJ, IPATH_CHIP_VERS_MIN, boardn,		 (unsigned)(dd->ipath_revision >> INFINIPATH_R_ARCH_SHIFT) &		 INFINIPATH_R_ARCH_MASK,		 dd->ipath_majrev, dd->ipath_minrev, dd->ipath_pcirev,		 (unsigned)(dd->ipath_revision >>			    INFINIPATH_R_SOFTWARE_SHIFT) &		 INFINIPATH_R_SOFTWARE_MASK);	ipath_dbg("%s", dd->ipath_boardversion);done:	return ret;}/** * ipath_init_chip - do the actual initialization sequence on the chip * @dd: the infinipath device * @reinit: reinitializing, so don't allocate new memory * * Do the actual initialization sequence on the chip.  This is done * both from the init routine called from the PCI infrastructure, and * when we reset the chip, or detect that it was reset internally, * or it's administratively re-enabled. * * Memory allocation here and in called routines is only done in * the first case (reinit == 0).  We have to be careful, because even * without memory allocation, we need to re-write all the chip registers * TIDs, etc. after the reset or enable has completed. */int ipath_init_chip(struct ipath_devdata *dd, int reinit){	int ret = 0, i;	u32 val32, kpiobufs;	u64 val, atmp;	struct ipath_portdata *pd = NULL; /* keep gcc4 happy */	ret = init_housekeeping(dd, &pd, reinit);	if (ret)		goto done;	/*	 * we ignore most issues after reporting them, but have to specially	 * handle hardware-disabled chips.	 */	if (ret == 2) {		/* unique error, known to ipath_init_one */		ret = -EPERM;		goto done;	}	/*	 * We could bump this to allow for full rcvegrcnt + rcvtidcnt,	 * but then it no longer nicely fits power of two, and since	 * we now use routines that backend onto __get_free_pages, the	 * rest would be wasted.	 */	dd->ipath_rcvhdrcnt = dd->ipath_rcvegrcnt;	ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvhdrcnt,			 dd->ipath_rcvhdrcnt);	/*	 * Set up the shadow copies of the piobufavail registers,	 * which we compare against the chip registers for now, and	 * the in memory DMA'ed copies of the registers.  This has to	 * be done early, before we calculate lastport, etc.	 */	val = dd->ipath_piobcnt2k + dd->ipath_piobcnt4k;	/*	 * calc number of pioavail registers, and save it; we have 2	 * bits per buffer.	 */	dd->ipath_pioavregs = ALIGN(val, sizeof(u64) * BITS_PER_BYTE / 2)		/ (sizeof(u64) * BITS_PER_BYTE / 2);	if (ipath_kpiobufs == 0) {		/* not set by user, or set explictly to default  */		if ((dd->ipath_piobcnt2k + dd->ipath_piobcnt4k) > 128)			kpiobufs = 32;		else			kpiobufs = 16;	}	else		kpiobufs = ipath_kpiobufs;	if (kpiobufs >	    (dd->ipath_piobcnt2k + dd->ipath_piobcnt4k -	     (dd->ipath_cfgports * IPATH_MIN_USER_PORT_BUFCNT))) {		i = dd->ipath_piobcnt2k + dd->ipath_piobcnt4k -			(dd->ipath_cfgports * IPATH_MIN_USER_PORT_BUFCNT);		if (i < 0)			i = 0;		dev_info(&dd->pcidev->dev, "Allocating %d PIO bufs for "			 "kernel leaves too few for %d user ports "			 "(%d each); using %u\n", kpiobufs,			 dd->ipath_cfgports - 1,			 IPATH_MIN_USER_PORT_BUFCNT, i);		/*		 * shouldn't change ipath_kpiobufs, because could be		 * different for different devices...		 */		kpiobufs = i;	}	dd->ipath_lastport_piobuf =		dd->ipath_piobcnt2k + dd->ipath_piobcnt4k - kpiobufs;	dd->ipath_pbufsport = dd->ipath_cfgports > 1		? dd->ipath_lastport_piobuf / (dd->ipath_cfgports - 1)		: 0;	val32 = dd->ipath_lastport_piobuf -		(dd->ipath_pbufsport * (dd->ipath_cfgports - 1));	if (val32 > 0) {		ipath_dbg("allocating %u pbufs/port leaves %u unused, "			  "add to kernel\n", dd->ipath_pbufsport, val32);		dd->ipath_lastport_piobuf -= val32;		ipath_dbg("%u pbufs/port leaves %u unused, add to kernel\n",			  dd->ipath_pbufsport, val32);	}	dd->ipath_lastpioindex = dd->ipath_lastport_piobuf;	ipath_cdbg(VERBOSE, "%d PIO bufs for kernel out of %d total %u "		   "each for %u user ports\n", kpiobufs,		   dd->ipath_piobcnt2k + dd->ipath_piobcnt4k,		   dd->ipath_pbufsport, dd->ipath_cfgports - 1);	dd->ipath_f_early_init(dd);	/* early_init sets rcvhdrentsize and rcvhdrsize, so this must be	 * done after early_init */	dd->ipath_hdrqlast =		dd->ipath_rcvhdrentsize * (dd->ipath_rcvhdrcnt - 1);	ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvhdrentsize,			 dd->ipath_rcvhdrentsize);	ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvhdrsize,			 dd->ipath_rcvhdrsize);	if (!reinit) {		ret = init_pioavailregs(dd);		init_shadow_tids(dd);		if (ret)			goto done;	}	(void)ipath_write_kreg(dd, dd->ipath_kregs->kr_sendpioavailaddr,			       dd->ipath_pioavailregs_phys);	/*	 * this is to detect s/w errors, which the h/w works around by	 * ignoring the low 6 bits of address, if it wasn't aligned.	 */	val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_sendpioavailaddr);	if (val != dd->ipath_pioavailregs_phys) {		ipath_dev_err(dd, "Catastrophic software error, "			      "SendPIOAvailAddr written as %lx, "			      "read back as %llx\n",			      (unsigned long) dd->ipath_pioavailregs_phys,			      (unsigned long long) val);		ret = -EINVAL;		goto done;	}	val = ipath_port0_rcvhdrtail_dma + dd->ipath_unit * 64;	/* verify that the alignment requirement was met */	ipath_write_kreg_port(dd, dd->ipath_kregs->kr_rcvhdrtailaddr,			      0, val);	atmp = ipath_read_kreg64_port(		dd, dd->ipath_kregs->kr_rcvhdrtailaddr, 0);	if (val != atmp) {		ipath_dev_err(dd, "Catastrophic software error, "			      "RcvHdrTailAddr0 written as %llx, "			      "read back as %llx from %x\n",			      (unsigned long long) val,			      (unsigned long long) atmp,			      dd->ipath_kregs->kr_rcvhdrtailaddr);		ret = -EINVAL;		goto done;	}	ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvbthqp, IPATH_KD_QP);	/*	 * make sure we are not in freeze, and PIO send enabled, so	 * writes to pbc happen	 */	ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask, 0ULL);	ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,			 ~0ULL&~INFINIPATH_HWE_MEMBISTFAILED);	ipath_write_kreg(dd, dd->ipath_kregs->kr_control, 0ULL);	ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,			 INFINIPATH_S_PIOENABLE);	/*	 * before error clears, since we expect serdes pll errors during	 * this, the first time after reset	 */	if (bringup_link(dd)) {		dev_info(&dd->pcidev->dev, "Failed to bringup IB link\n");		ret = -ENETDOWN;		goto done;	}	/*	 * clear any "expected" hwerrs from reset and/or initialization	 * clear any that aren't enabled (at least this once), and then	 * set the enable mask	 */	dd->ipath_f_init_hwerrors(dd);	ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,			 ~0ULL&~INFINIPATH_HWE_MEMBISTFAILED);	ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,			 dd->ipath_hwerrmask);	dd->ipath_maskederrs = dd->ipath_ignorederrs;	/* clear all */	ipath_write_kreg(dd, dd->ipath_kregs->kr_errorclear, -1LL);	/* enable errors that are masked, at least this first time. */	ipath_write_kreg(dd, dd->ipath_kregs->kr_errormask,			 ~dd->ipath_maskederrs);	/* clear any interrups up to this point (ints still not enabled) */	ipath_write_kreg(dd, dd->ipath_kregs->kr_intclear, -1LL);	ipath_stats.sps_lid[dd->ipath_unit] = dd->ipath_lid;	/*	 * Set up the port 0 (kernel) rcvhdr q and egr TIDs.  If doing	 * re-init, the simplest way to handle this is to free	 * existing, and re-allocate.	 */	if (reinit)		ipath_free_pddata(dd, 0, 0);	dd->ipath_f_tidtemplate(dd);	ret = ipath_create_rcvhdrq(dd, pd);	if (!ret)		ret = create_port0_egr(dd);	if (ret)		ipath_dev_err(dd, "failed to allocate port 0 (kernel) "			      "rcvhdrq and/or egr bufs\n");	else		enable_chip(dd, pd, reinit);	/*	 * cause retrigger of pending interrupts ignored during init,	 * even if we had errors	 */	ipath_write_kreg(dd, dd->ipath_kregs->kr_intclear, 0ULL);	if(!dd->ipath_stats_timer_active) {		/*		 * first init, or after an admin disable/enable		 * set up stats retrieval timer, even if we had errors		 * in last portion of setup		 */		init_timer(&dd->ipath_stats_timer);		dd->ipath_stats_timer.function = ipath_get_faststats;		dd->ipath_stats_timer.data = (unsigned long) dd;		/* every 5 seconds; */		dd->ipath_stats_timer.expires = jiffies + 5 * HZ;		/* takes ~16 seconds to overflow at full IB 4x bandwdith */		add_timer(&dd->ipath_stats_timer);		dd->ipath_stats_timer_active = 1;	}done:	if (!ret) {		*dd->ipath_statusp |= IPATH_STATUS_CHIP_PRESENT;		if (!dd->ipath_f_intrsetup(dd)) {			/* now we can enable all interrupts from the chip */			ipath_write_kreg(dd, dd->ipath_kregs->kr_intmask,					 -1LL);			/* force re-interrupt of any pending interrupts. */			ipath_write_kreg(dd, dd->ipath_kregs->kr_intclear,					 0ULL);			/* chip is usable; mark it as initialized */			*dd->ipath_statusp |= IPATH_STATUS_INITTED;		} else			ipath_dev_err(dd, "No interrupts enabled, couldn't "				      "setup interrupt address\n");		if (dd->ipath_cfgports > ipath_stats.sps_nports)			/*			 * sps_nports is a global, so, we set it to			 * the highest number of ports of any of the			 * chips we find; we never decrement it, at			 * least for now.  Since this might have changed			 * over disable/enable or prior to reset, always			 * do the check and potentially adjust.			 */			ipath_stats.sps_nports = dd->ipath_cfgports;	} else		ipath_dbg("Failed (%d) to initialize chip\n", ret);	/* if ret is non-zero, we probably should do some cleanup	   here... */	return ret;}static int ipath_set_kpiobufs(const char *str, struct kernel_param *kp){	struct ipath_devdata *dd;	unsigned long flags;	unsigned short val;	int ret;	ret = ipath_parse_ushort(str, &val);	spin_lock_irqsave(&ipath_devs_lock, flags);	if (ret < 0)		goto bail;	if (val == 0) {		ret = -EINVAL;		goto bail;	}	list_for_each_entry(dd, &ipath_dev_list, ipath_list) {		if (dd->ipath_kregbase)			continue;		if (val > (dd->ipath_piobcnt2k + dd->ipath_piobcnt4k -			   (dd->ipath_cfgports *			    IPATH_MIN_USER_PORT_BUFCNT)))		{			ipath_dev_err(				dd,				"Allocating %d PIO bufs for kernel leaves "				"too few for %d user ports (%d each)\n",				val, dd->ipath_cfgports - 1,				IPATH_MIN_USER_PORT_BUFCNT);			ret = -EINVAL;			goto bail;		}		dd->ipath_lastport_piobuf =			dd->ipath_piobcnt2k + dd->ipath_piobcnt4k - val;	}	ret = 0;bail:	spin_unlock_irqrestore(&ipath_devs_lock, flags);	return ret;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?