linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jimmy Assarsson <extja@kvaser.com>
To: linux-can@vger.kernel.org
Cc: Jimmy Assarsson <jimmyassarsson@gmail.com>,
	Jimmy Assarsson <extja@kvaser.com>
Subject: [PATCH 12/12] can: kvaser_pciefd: Use TX FIFO size read from CAN controller
Date: Tue, 23 May 2023 11:43:50 +0200	[thread overview]
Message-ID: <20230523094354.83792-13-extja@kvaser.com> (raw)
In-Reply-To: <20230523094354.83792-1-extja@kvaser.com>

Use the TX FIFO size read from CAN controller register, instead of using
hard coded value.

Signed-off-by: Jimmy Assarsson <extja@kvaser.com>
---
 drivers/net/can/kvaser_pciefd.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/drivers/net/can/kvaser_pciefd.c b/drivers/net/can/kvaser_pciefd.c
index 0575bb84b280..5f67414e2875 100644
--- a/drivers/net/can/kvaser_pciefd.c
+++ b/drivers/net/can/kvaser_pciefd.c
@@ -640,8 +640,7 @@ static netdev_tx_t kvaser_pciefd_start_xmit(struct sk_buff *skb,
 	/* No room for a new message, stop the queue until at least one
 	 * successful transmit
 	 */
-	if (count >= KVASER_PCIEFD_CAN_TX_MAX_COUNT ||
-	    can->can.echo_skb[can->echo_idx])
+	if (count >= can->can.echo_skb_max || can->can.echo_skb[can->echo_idx])
 		netif_stop_queue(netdev);
 	spin_unlock_irqrestore(&can->echo_lock, irq_flags);
 
@@ -760,7 +759,7 @@ static int kvaser_pciefd_setup_can_ctrls(struct kvaser_pciefd *pcie)
 	for (i = 0; i < pcie->nr_channels; i++) {
 		struct net_device *netdev;
 		struct kvaser_pciefd_can *can;
-		u32 status, tx_nr_packets;
+		u32 status, tx_nr_packets, tx_nr_packets_max;
 
 		netdev = alloc_candev(sizeof(struct kvaser_pciefd_can),
 				      KVASER_PCIEFD_CAN_TX_MAX_COUNT);
@@ -786,17 +785,11 @@ static int kvaser_pciefd_setup_can_ctrls(struct kvaser_pciefd *pcie)
 		iowrite32(0, can->reg_base + KVASER_PCIEFD_KCAN_BUS_LOAD_REG);
 
 		tx_nr_packets = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_TX_NR_PACKETS_REG);
-		if (((tx_nr_packets >> KVASER_PCIEFD_KCAN_TX_NR_PACKETS_MAX_SHIFT) &
-		      0xff) < KVASER_PCIEFD_CAN_TX_MAX_COUNT) {
-			dev_err(&pcie->pci->dev,
-				"Max Tx count is smaller than expected\n");
-
-			free_candev(netdev);
-			return -ENODEV;
-		}
+		tx_nr_packets_max =
+			(tx_nr_packets >> KVASER_PCIEFD_KCAN_TX_NR_PACKETS_MAX_SHIFT) & 0xff;
 
 		can->can.clock.freq = pcie->freq;
-		can->can.echo_skb_max = KVASER_PCIEFD_CAN_TX_MAX_COUNT;
+		can->can.echo_skb_max = min(KVASER_PCIEFD_CAN_TX_MAX_COUNT, tx_nr_packets_max - 1);
 		can->echo_idx = 0;
 		spin_lock_init(&can->echo_lock);
 		spin_lock_init(&can->lock);
@@ -1295,8 +1288,7 @@ static int kvaser_pciefd_handle_ack_packet(struct kvaser_pciefd *pcie,
 		len = can_get_echo_skb(can->can.dev, echo_idx, NULL);
 		count = ioread32(can->reg_base + KVASER_PCIEFD_KCAN_TX_NR_PACKETS_REG) & 0xff;
 
-		if (count < KVASER_PCIEFD_CAN_TX_MAX_COUNT &&
-		    netif_queue_stopped(can->can.dev))
+		if (count < can->can.echo_skb_max && netif_queue_stopped(can->can.dev))
 			netif_wake_queue(can->can.dev);
 
 		if (!one_shot_fail) {
-- 
2.40.0


  parent reply	other threads:[~2023-05-23  9:45 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-23  9:43 [PATCH 00/12] can: kvaser_pciefd: Fixes and improvments Jimmy Assarsson
2023-05-23  9:43 ` [PATCH 01/12] can: kvaser_pciefd: Remove useless write to interrupt register Jimmy Assarsson
2023-05-23  9:43 ` [PATCH 02/12] can: kvaser_pciefd: Remove handler for unused KVASER_PCIEFD_PACK_TYPE_EFRAME_ACK Jimmy Assarsson
2023-05-23  9:43 ` [PATCH 03/12] can: kvaser_pciefd: Add function to set skb hwtstamps Jimmy Assarsson
2023-05-23  9:43 ` [PATCH 04/12] can: kvaser_pciefd: Set hardware timestamp on transmitted packets Jimmy Assarsson
2023-05-23  9:43 ` [PATCH 05/12] can: kvaser_pciefd: Define unsigned constants with type suffix 'U' Jimmy Assarsson
2023-05-23  9:43 ` [PATCH 06/12] can: kvaser_pciefd: Remove SPI flash parameter read functionality Jimmy Assarsson
2023-05-23  9:43 ` [PATCH 07/12] can: kvaser_pciefd: Sort includes in alphabetic order Jimmy Assarsson
2023-05-23  9:43 ` [PATCH 08/12] can: kvaser_pciefd: Rename device ID defines Jimmy Assarsson
2023-05-23  9:43 ` [PATCH 09/12] can: kvaser_pciefd: Change return type for kvaser_pciefd_{receive,transmit,set_tx}_irq() Jimmy Assarsson
2023-05-23  9:43 ` [PATCH 10/12] can: kvaser_pciefd: Add len8_dlc support Jimmy Assarsson
2023-05-23  9:43 ` [PATCH 11/12] can: kvaser_pciefd: Refactor code Jimmy Assarsson
2023-05-23 11:27   ` Vincent MAILHOL
2023-05-24  7:40     ` Jimmy Assarsson
2023-05-23  9:43 ` Jimmy Assarsson [this message]
2023-05-23  9:43 ` [PATCH 0/3] can: kvaser_pciefd: Add support for new Kvaser PCI Express devices Jimmy Assarsson
2023-05-23  9:51   ` Jimmy Assarsson
2023-06-22 15:16   ` Jimmy Assarsson
2023-05-23  9:43 ` [PATCH 1/3] can: kvaser_pciefd: Move hardware specific constants and functions into a driver_data struct Jimmy Assarsson
2023-05-23  9:43 ` [PATCH 2/3] can: kvaser_pciefd: Add support for new Kvaser pciefd devices Jimmy Assarsson
2023-05-23  9:43 ` [PATCH 3/3] can: kvaser_pciefd: Wrap register read and writes with macros Jimmy Assarsson
2023-05-23  9:50 ` [PATCH 00/12] can: kvaser_pciefd: Fixes and improvments Jimmy Assarsson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230523094354.83792-13-extja@kvaser.com \
    --to=extja@kvaser.com \
    --cc=jimmyassarsson@gmail.com \
    --cc=linux-can@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).