From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C6605A79B; Tue, 14 May 2024 12:55:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715691334; cv=none; b=ZVGgFFP70v07VQmhzkFIeXcfxzGyJy/AaubjpnnV0Gv734i3gQj5ogi0xAOUyt8LsOY0zkaKYbV0/j0kSx5+E7nphvBsTWzqHQT90X2dMnx7I5VjrjdJLJfQ8alBRf82EIIBU4mq4TlF5fM0uuHi1KR0NEAhGxfPl2GyHIYNZKE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715691334; c=relaxed/simple; bh=ogLSvab9s/uaYk8nU1V6GvKZYCgdD8Qs2Pc34NIY5X0=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=REk401ZHEAYvgdh8g52Z1C6NddsmO9qCrrMJ2qGJfTKPMX4lQfBgBVorSikqnMco0AEEwRu8kN/ZZSXPf9NRKEBgwlYNZ6uewoNuys+L9m4J7LtUQDNvOfKQMmj6d/7pbv5fS3Wkp52lMuoTO2K72q0oP7r3bQovx944Na8TGA0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=SqHcSbng; arc=none smtp.client-ip=217.70.183.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="SqHcSbng" Received: by mail.gandi.net (Postfix) with ESMTPSA id 103CD20007; Tue, 14 May 2024 12:55:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1715691323; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1U1lSHyn+UBGYjOWsepzisKyKSuUqvB3hMNBkgKOiVw=; b=SqHcSbngLJlpXZ3Qfg4KbR4KsZwO0iwvwjzI88o8+Tf2e/Q0DD67RsrnIP/SgrGMEJZ3hQ Op8bxR6zbPwZWcXBE35qbKg9Z3diV2VFHHT+H3fyKu2MHKiNGs2FNi+dsvqmB9Id1OI8L0 Zcrk4xCQCpNsWLtad7RjLVLwn70oLnGzp+xvl+4UIL1PutKDvt9wCLEPbs0sRSkiIcTmXk x8OVkso3DFNW+I0RFrCfQa9Y5hfPaxWMG0z9OJYQmMRGmNsXb167RC3WrZi0FrHHdbi+5H hL27DJm0xrFQ4QSjQosQYjpgMA0WqCpPxwAYZRB1OAK1XvcexRfN+zuhnoMJTA== Date: Tue, 14 May 2024 14:55:18 +0200 From: Herve Codina To: Cc: , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: Re: [PATCH 16/17] mfd: Add support for LAN966x PCI device Message-ID: <20240514145518.3e989b83@bootlin.com> In-Reply-To: References: <20240430083730.134918-1-herve.codina@bootlin.com> <20240430083730.134918-17-herve.codina@bootlin.com> Organization: Bootlin X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-redhat-linux-gnu) Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-GND-Sasl: herve.codina@bootlin.com Hi Steen, On Wed, 8 May 2024 08:20:04 +0000 wrote: ... > > + > > +static irqreturn_t pci_dev_irq_handler(int irq, void *data) > > +{ > > + struct pci_dev_intr_ctrl *intr_ctrl = data; > > + int ret; > > + > > + ret = generic_handle_domain_irq(intr_ctrl->irq_domain, 0); > > + return ret ? IRQ_NONE : IRQ_HANDLED; > > +} > > + > > +static struct pci_dev_intr_ctrl *pci_dev_create_intr_ctrl(struct pci_dev *pdev) > > +{ > > + struct pci_dev_intr_ctrl *intr_ctrl; > > + struct fwnode_handle *fwnode; > > + int ret; > > + > > + if (!pdev->irq) > > + return ERR_PTR(-EOPNOTSUPP); > > + > > + fwnode = dev_fwnode(&pdev->dev); > > + if (!fwnode) > > + return ERR_PTR(-ENODEV); > > + > > + intr_ctrl = kmalloc(sizeof(*intr_ctrl), GFP_KERNEL); > > + if (!intr_ctrl) > > + return ERR_PTR(-ENOMEM); > > + > > + intr_ctrl->pci_dev = pdev; > > + > > + intr_ctrl->irq_domain = irq_domain_create_linear(fwnode, 1, &pci_dev_irq_domain_ops, > > + intr_ctrl); > > + if (!intr_ctrl->irq_domain) { > > + pci_err(pdev, "Failed to create irqdomain\n"); > > + ret = -ENOMEM; > > + goto err_free_intr_ctrl; > > + } > > + > > + ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_LEGACY); > > + if (ret < 0) { > > + pci_err(pdev, "Unable alloc irq vector (%d)\n", ret); > > + goto err_remove_domain; > > + } > > + intr_ctrl->irq = pci_irq_vector(pdev, 0); > > + ret = request_irq(intr_ctrl->irq, pci_dev_irq_handler, IRQF_SHARED, > > + dev_name(&pdev->dev), intr_ctrl); > > + if (ret) { > > + pci_err(pdev, "Unable to request irq %d (%d)\n", intr_ctrl->irq, ret); > > + goto err_free_irq_vector; > > + } > > + > > + return intr_ctrl; > > + > > +err_free_irq_vector: > > + pci_free_irq_vectors(pdev); > > +err_remove_domain: > > + irq_domain_remove(intr_ctrl->irq_domain); > > +err_free_intr_ctrl: > > + kfree(intr_ctrl); > > + return ERR_PTR(ret); > > +} > > + > > +static void pci_dev_remove_intr_ctrl(struct pci_dev_intr_ctrl *intr_ctrl) > > +{ > > + free_irq(intr_ctrl->irq, intr_ctrl); > > + pci_free_irq_vectors(intr_ctrl->pci_dev); > > + irq_dispose_mapping(irq_find_mapping(intr_ctrl->irq_domain, 0)); > > + irq_domain_remove(intr_ctrl->irq_domain); > > + kfree(intr_ctrl); > > +} > > + > > It looks like the two functions below (and their helper functions) are so > generic that they could be part of the pci driver core support. > Any plans for that? Indeed, I tried to write them in a generic way. Right now, at least for the next iteration of this series, I don't plan to move them as part of the PCI code. This piece of code did not get any feedback and I would prefer to keep them here for the moment. Of course, they could be move out of the LAN966x PCI driver later. > > > +static void devm_pci_dev_remove_intr_ctrl(void *data) > > +{ > > + struct pci_dev_intr_ctrl *intr_ctrl = data; > > + > > + pci_dev_remove_intr_ctrl(intr_ctrl); > > +} > > + > > +static int devm_pci_dev_create_intr_ctrl(struct pci_dev *pdev) > > +{ > > + struct pci_dev_intr_ctrl *intr_ctrl; > > + > > + intr_ctrl = pci_dev_create_intr_ctrl(pdev); > > + > > + if (IS_ERR(intr_ctrl)) > > + return PTR_ERR(intr_ctrl); > > + > > + return devm_add_action_or_reset(&pdev->dev, devm_pci_dev_remove_intr_ctrl, intr_ctrl); > > +} > > + > Best regards, Hervé