Home | History | Annotate | Line # | Download | only in pci
nvme_pci.c revision 1.19
      1 /*	$NetBSD: nvme_pci.c,v 1.19 2017/06/01 02:45:11 chs Exp $	*/
      2 /*	$OpenBSD: nvme_pci.c,v 1.3 2016/04/14 11:18:32 dlg Exp $ */
      3 
      4 /*
      5  * Copyright (c) 2014 David Gwynne <dlg (at) openbsd.org>
      6  *
      7  * Permission to use, copy, modify, and distribute this software for any
      8  * purpose with or without fee is hereby granted, provided that the above
      9  * copyright notice and this permission notice appear in all copies.
     10  *
     11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     18  */
     19 
     20 /*-
     21  * Copyright (C) 2016 NONAKA Kimihiro <nonaka (at) netbsd.org>
     22  * All rights reserved.
     23  *
     24  * Redistribution and use in source and binary forms, with or without
     25  * modification, are permitted provided that the following conditions
     26  * are met:
     27  * 1. Redistributions of source code must retain the above copyright
     28  *    notice, this list of conditions and the following disclaimer.
     29  * 2. Redistributions in binary form must reproduce the above copyright
     30  *    notice, this list of conditions and the following disclaimer in the
     31  *    documentation and/or other materials provided with the distribution.
     32  *
     33  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     34  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     35  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     36  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     37  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     38  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     39  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     40  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     41  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     42  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     43  */
     44 
     45 #include <sys/cdefs.h>
     46 __KERNEL_RCSID(0, "$NetBSD: nvme_pci.c,v 1.19 2017/06/01 02:45:11 chs Exp $");
     47 
     48 #include <sys/param.h>
     49 #include <sys/systm.h>
     50 #include <sys/kernel.h>
     51 #include <sys/device.h>
     52 #include <sys/bitops.h>
     53 #include <sys/bus.h>
     54 #include <sys/cpu.h>
     55 #include <sys/interrupt.h>
     56 #include <sys/kmem.h>
     57 #include <sys/pmf.h>
     58 #include <sys/module.h>
     59 
     60 #include <dev/pci/pcireg.h>
     61 #include <dev/pci/pcivar.h>
     62 
     63 #include <dev/ic/nvmereg.h>
     64 #include <dev/ic/nvmevar.h>
     65 
     66 int nvme_pci_force_intx = 0;
     67 int nvme_pci_mpsafe = 1;
     68 int nvme_pci_mq = 1;		/* INTx: ioq=1, MSI/MSI-X: ioq=ncpu */
     69 
     70 #define NVME_PCI_BAR		0x10
     71 
     72 struct nvme_pci_softc {
     73 	struct nvme_softc	psc_nvme;
     74 
     75 	pci_chipset_tag_t	psc_pc;
     76 	pci_intr_handle_t	*psc_intrs;
     77 	int			psc_nintrs;
     78 };
     79 
     80 static int	nvme_pci_match(device_t, cfdata_t, void *);
     81 static void	nvme_pci_attach(device_t, device_t, void *);
     82 static int	nvme_pci_detach(device_t, int);
     83 static int	nvme_pci_rescan(device_t, const char *, const int *);
     84 
     85 CFATTACH_DECL3_NEW(nvme_pci, sizeof(struct nvme_pci_softc),
     86     nvme_pci_match, nvme_pci_attach, nvme_pci_detach, NULL, nvme_pci_rescan,
     87     nvme_childdet, DVF_DETACH_SHUTDOWN);
     88 
     89 static int	nvme_pci_intr_establish(struct nvme_softc *,
     90 		    uint16_t, struct nvme_queue *);
     91 static int	nvme_pci_intr_disestablish(struct nvme_softc *, uint16_t);
     92 static int	nvme_pci_setup_intr(struct pci_attach_args *,
     93 		    struct nvme_pci_softc *);
     94 
     95 static int
     96 nvme_pci_match(device_t parent, cfdata_t match, void *aux)
     97 {
     98 	struct pci_attach_args *pa = aux;
     99 
    100 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_MASS_STORAGE &&
    101 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_MASS_STORAGE_NVM &&
    102 	    PCI_INTERFACE(pa->pa_class) == PCI_INTERFACE_NVM_NVME)
    103 		return 1;
    104 
    105 	return 0;
    106 }
    107 
    108 static void
    109 nvme_pci_attach(device_t parent, device_t self, void *aux)
    110 {
    111 	struct nvme_pci_softc *psc = device_private(self);
    112 	struct nvme_softc *sc = &psc->psc_nvme;
    113 	struct pci_attach_args *pa = aux;
    114 	pcireg_t memtype, reg;
    115 	bus_addr_t memaddr;
    116 	int flags, error;
    117 	int msixoff;
    118 
    119 	sc->sc_dev = self;
    120 	psc->psc_pc = pa->pa_pc;
    121 	if (pci_dma64_available(pa))
    122 		sc->sc_dmat = pa->pa_dmat64;
    123 	else
    124 		sc->sc_dmat = pa->pa_dmat;
    125 
    126 	pci_aprint_devinfo(pa, NULL);
    127 
    128 	reg = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
    129 	if ((reg & PCI_COMMAND_MASTER_ENABLE) == 0) {
    130 		reg |= PCI_COMMAND_MASTER_ENABLE;
    131         	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, reg);
    132 	}
    133 
    134 	/* Map registers */
    135 	memtype = pci_mapreg_type(pa->pa_pc, pa->pa_tag, NVME_PCI_BAR);
    136 	if (PCI_MAPREG_TYPE(memtype) != PCI_MAPREG_TYPE_MEM) {
    137 		aprint_error_dev(self, "invalid type (type=0x%x)\n", memtype);
    138 		return;
    139 	}
    140 	sc->sc_iot = pa->pa_memt;
    141 	error = pci_mapreg_info(pa->pa_pc, pa->pa_tag, PCI_MAPREG_START,
    142 	    memtype, &memaddr, &sc->sc_ios, &flags);
    143 	if (error) {
    144 		aprint_error_dev(self, "can't get map info\n");
    145 		return;
    146 	}
    147 
    148 	if (pci_get_capability(pa->pa_pc, pa->pa_tag, PCI_CAP_MSIX, &msixoff,
    149 	    NULL)) {
    150 		pcireg_t msixtbl;
    151 		uint32_t table_offset;
    152 		int bir;
    153 
    154 		msixtbl = pci_conf_read(pa->pa_pc, pa->pa_tag,
    155 		    msixoff + PCI_MSIX_TBLOFFSET);
    156 		table_offset = msixtbl & PCI_MSIX_TBLOFFSET_MASK;
    157 		bir = msixtbl & PCI_MSIX_PBABIR_MASK;
    158 		if (bir == 0) {
    159 			sc->sc_ios = table_offset;
    160 		}
    161 	}
    162 
    163 	error = bus_space_map(sc->sc_iot, memaddr, sc->sc_ios, flags,
    164 	    &sc->sc_ioh);
    165 	if (error != 0) {
    166 		aprint_error_dev(self, "can't map mem space (error=%d)\n",
    167 		    error);
    168 		return;
    169 	}
    170 
    171 	/* Establish interrupts */
    172 	if (nvme_pci_setup_intr(pa, psc) != 0) {
    173 		aprint_error_dev(self, "unable to allocate interrupt\n");
    174 		goto unmap;
    175 	}
    176 	sc->sc_intr_establish = nvme_pci_intr_establish;
    177 	sc->sc_intr_disestablish = nvme_pci_intr_disestablish;
    178 
    179 	sc->sc_ih = kmem_zalloc(sizeof(*sc->sc_ih) * psc->psc_nintrs, KM_SLEEP);
    180 	sc->sc_softih = kmem_zalloc(
    181 	    sizeof(*sc->sc_softih) * psc->psc_nintrs, KM_SLEEP);
    182 	if (nvme_attach(sc) != 0) {
    183 		/* error printed by nvme_attach() */
    184 		goto softintr_free;
    185 	}
    186 
    187 	if (!pmf_device_register(self, NULL, NULL))
    188 		aprint_error_dev(self, "couldn't establish power handler\n");
    189 
    190 	SET(sc->sc_flags, NVME_F_ATTACHED);
    191 	return;
    192 
    193 softintr_free:
    194 	kmem_free(sc->sc_softih, sizeof(*sc->sc_softih) * psc->psc_nintrs);
    195 	kmem_free(sc->sc_ih, sizeof(*sc->sc_ih) * psc->psc_nintrs);
    196 	sc->sc_nq = 0;
    197 	pci_intr_release(pa->pa_pc, psc->psc_intrs, psc->psc_nintrs);
    198 	psc->psc_nintrs = 0;
    199 unmap:
    200 	bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_ios);
    201 	sc->sc_ios = 0;
    202 }
    203 
    204 static int
    205 nvme_pci_rescan(device_t self, const char *attr, const int *flags)
    206 {
    207 
    208 	return nvme_rescan(self, attr, flags);
    209 }
    210 
    211 static int
    212 nvme_pci_detach(device_t self, int flags)
    213 {
    214 	struct nvme_pci_softc *psc = device_private(self);
    215 	struct nvme_softc *sc = &psc->psc_nvme;
    216 	int error;
    217 
    218 	if (!ISSET(sc->sc_flags, NVME_F_ATTACHED))
    219 		return 0;
    220 
    221 	error = nvme_detach(sc, flags);
    222 	if (error)
    223 		return error;
    224 
    225 	kmem_free(sc->sc_softih, sizeof(*sc->sc_softih) * psc->psc_nintrs);
    226 	sc->sc_softih = NULL;
    227 
    228 	kmem_free(sc->sc_ih, sizeof(*sc->sc_ih) * psc->psc_nintrs);
    229 	pci_intr_release(psc->psc_pc, psc->psc_intrs, psc->psc_nintrs);
    230 	bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_ios);
    231 	return 0;
    232 }
    233 
    234 static int
    235 nvme_pci_intr_establish(struct nvme_softc *sc, uint16_t qid,
    236     struct nvme_queue *q)
    237 {
    238 	struct nvme_pci_softc *psc = (struct nvme_pci_softc *)sc;
    239 	char intr_xname[INTRDEVNAMEBUF];
    240 	char intrbuf[PCI_INTRSTR_LEN];
    241 	const char *intrstr = NULL;
    242 	int (*ih_func)(void *);
    243 	void (*ih_func_soft)(void *);
    244 	void *ih_arg;
    245 	int error;
    246 
    247 	KASSERT(sc->sc_use_mq || qid == NVME_ADMIN_Q);
    248 	KASSERT(sc->sc_ih[qid] == NULL);
    249 
    250 	if (nvme_pci_mpsafe) {
    251 		pci_intr_setattr(psc->psc_pc, &psc->psc_intrs[qid],
    252 		    PCI_INTR_MPSAFE, true);
    253 	}
    254 
    255 	if (!sc->sc_use_mq) {
    256 		snprintf(intr_xname, sizeof(intr_xname), "%s",
    257 		    device_xname(sc->sc_dev));
    258 		ih_arg = sc;
    259 		ih_func = nvme_intr;
    260 		ih_func_soft = nvme_softintr_intx;
    261 	} else {
    262 		if (qid == NVME_ADMIN_Q) {
    263 			snprintf(intr_xname, sizeof(intr_xname), "%s adminq",
    264 			    device_xname(sc->sc_dev));
    265 		} else {
    266 			snprintf(intr_xname, sizeof(intr_xname), "%s ioq%d",
    267 			    device_xname(sc->sc_dev), qid);
    268 		}
    269 		ih_arg = q;
    270 		ih_func = nvme_intr_msi;
    271 		ih_func_soft = nvme_softintr_msi;
    272 	}
    273 
    274 	/* establish hardware interrupt */
    275 	sc->sc_ih[qid] = pci_intr_establish_xname(psc->psc_pc,
    276 	    psc->psc_intrs[qid], IPL_BIO, ih_func, ih_arg, intr_xname);
    277 	if (sc->sc_ih[qid] == NULL) {
    278 		aprint_error_dev(sc->sc_dev,
    279 		    "unable to establish %s interrupt\n", intr_xname);
    280 		return 1;
    281 	}
    282 
    283 	/* establish also the software interrupt */
    284 	sc->sc_softih[qid] = softint_establish(
    285 	    SOFTINT_BIO|(nvme_pci_mpsafe ? SOFTINT_MPSAFE : 0),
    286 	    ih_func_soft, q);
    287 	if (sc->sc_softih[qid] == NULL) {
    288 		pci_intr_disestablish(psc->psc_pc, sc->sc_ih[qid]);
    289 		sc->sc_ih[qid] = NULL;
    290 
    291 		aprint_error_dev(sc->sc_dev,
    292 		    "unable to establish %s soft interrupt\n",
    293 		    intr_xname);
    294 		return 1;
    295 	}
    296 
    297 	intrstr = pci_intr_string(psc->psc_pc, psc->psc_intrs[qid], intrbuf,
    298 	    sizeof(intrbuf));
    299 	if (!sc->sc_use_mq) {
    300 		aprint_normal_dev(sc->sc_dev, "interrupting at %s\n", intrstr);
    301 	} else if (qid == NVME_ADMIN_Q) {
    302 		aprint_normal_dev(sc->sc_dev,
    303 		    "for admin queue interrupting at %s\n", intrstr);
    304 	} else if (!nvme_pci_mpsafe) {
    305 		aprint_normal_dev(sc->sc_dev,
    306 		    "for io queue %d interrupting at %s\n", qid, intrstr);
    307 	} else {
    308 		kcpuset_t *affinity;
    309 		cpuid_t affinity_to;
    310 
    311 		kcpuset_create(&affinity, true);
    312 		affinity_to = (qid - 1) % ncpu;
    313 		kcpuset_set(affinity, affinity_to);
    314 		error = interrupt_distribute(sc->sc_ih[qid], affinity, NULL);
    315 		kcpuset_destroy(affinity);
    316 		aprint_normal_dev(sc->sc_dev,
    317 		    "for io queue %d interrupting at %s", qid, intrstr);
    318 		if (error == 0)
    319 			aprint_normal(" affinity to cpu%lu", affinity_to);
    320 		aprint_normal("\n");
    321 	}
    322 	return 0;
    323 }
    324 
    325 static int
    326 nvme_pci_intr_disestablish(struct nvme_softc *sc, uint16_t qid)
    327 {
    328 	struct nvme_pci_softc *psc = (struct nvme_pci_softc *)sc;
    329 
    330 	KASSERT(sc->sc_use_mq || qid == NVME_ADMIN_Q);
    331 	KASSERT(sc->sc_ih[qid] != NULL);
    332 
    333 	if (sc->sc_softih) {
    334 		softint_disestablish(sc->sc_softih[qid]);
    335 		sc->sc_softih[qid] = NULL;
    336 	}
    337 
    338 	pci_intr_disestablish(psc->psc_pc, sc->sc_ih[qid]);
    339 	sc->sc_ih[qid] = NULL;
    340 
    341 	return 0;
    342 }
    343 
    344 static int
    345 nvme_pci_setup_intr(struct pci_attach_args *pa, struct nvme_pci_softc *psc)
    346 {
    347 	struct nvme_softc *sc = &psc->psc_nvme;
    348 	int error;
    349 	int counts[PCI_INTR_TYPE_SIZE], alloced_counts[PCI_INTR_TYPE_SIZE];
    350 	pci_intr_handle_t *ihps;
    351 	int max_type, intr_type;
    352 
    353 	if (nvme_pci_force_intx) {
    354 		max_type = PCI_INTR_TYPE_INTX;
    355 		goto force_intx;
    356 	}
    357 
    358 	/* MSI-X */
    359 	max_type = PCI_INTR_TYPE_MSIX;
    360 	counts[PCI_INTR_TYPE_MSIX] = min(pci_msix_count(pa->pa_pc, pa->pa_tag),
    361 	    ncpu + 1);
    362 	if (counts[PCI_INTR_TYPE_MSIX] > 0) {
    363 		memset(alloced_counts, 0, sizeof(alloced_counts));
    364 		alloced_counts[PCI_INTR_TYPE_MSIX] = counts[PCI_INTR_TYPE_MSIX];
    365 		if (pci_intr_alloc(pa, &ihps, alloced_counts,
    366 		    PCI_INTR_TYPE_MSIX)) {
    367 			counts[PCI_INTR_TYPE_MSIX] = 0;
    368 		} else {
    369 			counts[PCI_INTR_TYPE_MSIX] =
    370 			    alloced_counts[PCI_INTR_TYPE_MSIX];
    371 			pci_intr_release(pa->pa_pc, ihps,
    372 			    alloced_counts[PCI_INTR_TYPE_MSIX]);
    373 		}
    374 	}
    375 	if (counts[PCI_INTR_TYPE_MSIX] < 2) {
    376 		counts[PCI_INTR_TYPE_MSIX] = 0;
    377 		max_type = PCI_INTR_TYPE_MSI;
    378 	} else if (!nvme_pci_mq || !nvme_pci_mpsafe) {
    379 		counts[PCI_INTR_TYPE_MSIX] = 2;	/* adminq + 1 ioq */
    380 	}
    381 
    382 retry_msi:
    383 	/* MSI */
    384 	counts[PCI_INTR_TYPE_MSI] = pci_msi_count(pa->pa_pc, pa->pa_tag);
    385 	if (counts[PCI_INTR_TYPE_MSI] > 0) {
    386 		while (counts[PCI_INTR_TYPE_MSI] > ncpu + 1) {
    387 			if (counts[PCI_INTR_TYPE_MSI] / 2 <= ncpu + 1)
    388 				break;
    389 			counts[PCI_INTR_TYPE_MSI] /= 2;
    390 		}
    391 		memset(alloced_counts, 0, sizeof(alloced_counts));
    392 		alloced_counts[PCI_INTR_TYPE_MSI] = counts[PCI_INTR_TYPE_MSI];
    393 		if (pci_intr_alloc(pa, &ihps, alloced_counts,
    394 		    PCI_INTR_TYPE_MSI)) {
    395 			counts[PCI_INTR_TYPE_MSI] = 0;
    396 		} else {
    397 			counts[PCI_INTR_TYPE_MSI] =
    398 			    alloced_counts[PCI_INTR_TYPE_MSI];
    399 			pci_intr_release(pa->pa_pc, ihps,
    400 			    alloced_counts[PCI_INTR_TYPE_MSI]);
    401 		}
    402 	}
    403 	if (counts[PCI_INTR_TYPE_MSI] < 1) {
    404 		counts[PCI_INTR_TYPE_MSI] = 0;
    405 		if (max_type == PCI_INTR_TYPE_MSI)
    406 			max_type = PCI_INTR_TYPE_INTX;
    407 	} else if (!nvme_pci_mq || !nvme_pci_mpsafe) {
    408 		if (counts[PCI_INTR_TYPE_MSI] > 2)
    409 			counts[PCI_INTR_TYPE_MSI] = 2;	/* adminq + 1 ioq */
    410 	}
    411 
    412 force_intx:
    413 	/* INTx */
    414 	counts[PCI_INTR_TYPE_INTX] = 1;
    415 
    416 	memcpy(alloced_counts, counts, sizeof(counts));
    417 	error = pci_intr_alloc(pa, &ihps, alloced_counts, max_type);
    418 	if (error) {
    419 		if (max_type != PCI_INTR_TYPE_INTX) {
    420 retry:
    421 			memset(counts, 0, sizeof(counts));
    422 			if (max_type == PCI_INTR_TYPE_MSIX) {
    423 				max_type = PCI_INTR_TYPE_MSI;
    424 				goto retry_msi;
    425 			} else {
    426 				max_type = PCI_INTR_TYPE_INTX;
    427 				goto force_intx;
    428 			}
    429 		}
    430 		return error;
    431 	}
    432 
    433 	intr_type = pci_intr_type(pa->pa_pc, ihps[0]);
    434 	if (alloced_counts[intr_type] < counts[intr_type]) {
    435 		if (intr_type != PCI_INTR_TYPE_INTX) {
    436 			pci_intr_release(pa->pa_pc, ihps,
    437 			    alloced_counts[intr_type]);
    438 			max_type = intr_type;
    439 			goto retry;
    440 		}
    441 		return EBUSY;
    442 	}
    443 
    444 	psc->psc_intrs = ihps;
    445 	psc->psc_nintrs = alloced_counts[intr_type];
    446 	if (intr_type == PCI_INTR_TYPE_MSI) {
    447 		if (alloced_counts[intr_type] > ncpu + 1)
    448 			alloced_counts[intr_type] = ncpu + 1;
    449 	}
    450 	sc->sc_use_mq = alloced_counts[intr_type] > 1;
    451 	sc->sc_nq = sc->sc_use_mq ? alloced_counts[intr_type] - 1 : 1;
    452 
    453 	return 0;
    454 }
    455 
    456 MODULE(MODULE_CLASS_DRIVER, nvme, "pci,dk_subr");
    457 
    458 #ifdef _MODULE
    459 #include "ioconf.c"
    460 #endif
    461 
    462 static int
    463 nvme_modcmd(modcmd_t cmd, void *opaque)
    464 {
    465 #ifdef _MODULE
    466 	devmajor_t cmajor, bmajor;
    467 	extern const struct cdevsw nvme_cdevsw;
    468 #endif
    469 	int error = 0;
    470 
    471 #ifdef _MODULE
    472 	switch (cmd) {
    473 	case MODULE_CMD_INIT:
    474 		error = config_init_component(cfdriver_ioconf_nvme_pci,
    475 		    cfattach_ioconf_nvme_pci, cfdata_ioconf_nvme_pci);
    476 		if (error)
    477 			break;
    478 
    479 		bmajor = cmajor = NODEVMAJOR;
    480 		error = devsw_attach(nvme_cd.cd_name, NULL, &bmajor,
    481 		    &nvme_cdevsw, &cmajor);
    482 		if (error) {
    483 			aprint_error("%s: unable to register devsw\n",
    484 			    nvme_cd.cd_name);
    485 			/* do not abort, just /dev/nvme* will not work */
    486 		}
    487 		break;
    488 	case MODULE_CMD_FINI:
    489 		devsw_detach(NULL, &nvme_cdevsw);
    490 
    491 		error = config_fini_component(cfdriver_ioconf_nvme_pci,
    492 		    cfattach_ioconf_nvme_pci, cfdata_ioconf_nvme_pci);
    493 		break;
    494 	default:
    495 		break;
    496 	}
    497 #endif
    498 	return error;
    499 }
    500