: new Blackfin on-chip SIR IrDA driver
PATCH 1/1 : new Blackfin on-chip SIR IrDA driver
From: Graf Yang <[email protected]>
--- drivers/net/irda/Kconfig | 45 +++ drivers/net/irda/Makefile | 1 + drivers/net/irda/bfin_sir.c | 796 +++++++++++++++++++++++++++++++++++++++++++ drivers/net/irda/bfin_sir.h | 147 ++++++++ 4 files changed, 989 insertions(+), 0 deletions(-) create mode 100644 drivers/net/irda/bfin_sir.c create mode 100644 drivers/net/irda/bfin_sir.h
drivers/net/irda/Kconfig +45 -0
@@ -17,6 +17,51 @@ config IRTTY_SIR If unsure, say Y. +config BFIN_SIR + tristate "Blackfin SIR on UART" + depends on BLACKFIN && IRDA + default n + help + Say Y here if your want to enable SIR function on Blackfin UART + devices. + + To activate this driver you can start irattach like: + "irattach irda0 -s" + + Saying M, it will be built as a module named bfin_sir. + + Note that you need to turn off one of the serial drivers for SIR + to use that UART. + +config BFIN_SIR3 + bool "Blackfin SIR on UART3" + depends on BFIN_SIR && !SERIAL_BFIN_UART3 && (BF54x) + +config BFIN_SIR1 + bool "Blackfin SIR on UART1" + depends on BFIN_SIR && !SERIAL_BFIN_UART1 && (!BF531 && !BF532 && !BF533 && !BF561) + +config BFIN_SIR0 + bool "Blackfin SIR on UART0" + depends on BFIN_SIR && !SERIAL_BFIN_UART0 + +config BFIN_SIR2 + bool "Blackfin SIR on UART2" + depends on BFIN_SIR && !SERIAL_BFIN_UART2 && (BF54x || BF538 || BF539) + +choice + prompt "SIR Mode" + depends on BFIN_SIR + default SIR_BFIN_DMA + +config SIR_BFIN_DMA + bool "DMA mode" + depends on !DMA_UNCACHED_NONE + +config SIR_BFIN_PIO + bool "PIO mode" +endchoice + comment "Dongle support" config DONGLE
drivers/net/irda/Makefile +1 -0
@@ -21,6 +21,7 @@ obj-$(CONFIG_MCS_FIR) += mcs7780.o obj-$(CONFIG_AU1000_FIR) += au1k_ir.o # SIR drivers obj-$(CONFIG_IRTTY_SIR) += irtty-sir.o sir-dev.o +obj-$(CONFIG_BFIN_SIR) += bfin_sir.o # dongle drivers for SIR drivers obj-$(CONFIG_ESI_DONGLE) += esi-sir.o obj-$(CONFIG_TEKRAM_DONGLE) += tekram-sir.o
drivers/net/irda/bfin_sir.c new file +796 -0
796 lines not on this page · raw message
drivers/net/irda/bfin_sir.h new file +147 -0
147 lines not on this page · raw message
Signature · 1 line
1.5.6.3
Quoted 4 lines · On Fri, 6 Mar 2009 14:44:45 +0800 Bryan Wu <[email protected]> wrote:
From: Graf Yang <[email protected]>
Signed-off-by Graf Yang <[email protected]>Signed-off-by Bryan Wu <[email protected]>
Mutter. Nothing to be said at all?
Quoted 47 lines
drivers/net/irda/bfin_sir.h | 147 ++++++++ 4 files changed, 989 insertions(+), 0 deletions(-) create mode 100644 drivers/net/irda/bfin_sir.c create mode 100644 drivers/net/irda/bfin_sir.hdrivers/net/irda/Kconfig +34
-0@@ -17,6 +17,51 @@ config IRTTY_SIR If unsure, say Y. +config BFIN_SIR + tristate "Blackfin SIR on UART" + depends on BLACKFIN && IRDA + default n + help + Say Y here if your want to enable SIR function on Blackfin UART + devices. + + To activate this driver you can start irattach like: + "irattach irda0 -s" + + Saying M, it will be built as a module named bfin_sir. + + Note that you need to turn off one of the serial drivers for SIR + to use that UART. + +config BFIN_SIR3 + bool "Blackfin SIR on UART3" + depends on BFIN_SIR && !SERIAL_BFIN_UART3 && (BF54x) + +config BFIN_SIR1 + bool "Blackfin SIR on UART1" + depends on BFIN_SIR && !SERIAL_BFIN_UART1 && (!BF531 && !BF532 && !BF533 && !BF561) + +config BFIN_SIR0 + bool "Blackfin SIR on UART0" + depends on BFIN_SIR && !SERIAL_BFIN_UART0 + +config BFIN_SIR2 + bool "Blackfin SIR on UART2" + depends on BFIN_SIR && !SERIAL_BFIN_UART2 && (BF54x || BF538 || BF539) + +choice + prompt "SIR Mode"
drivers/net/irda/Kconfig config IRTTY_SIR · line 63
Quoted 10 lines
drivers/net/irda/Kconfig +10
-0+ depends on BFIN_SIR + default SIR_BFIN_DMA + +config SIR_BFIN_DMA + bool "DMA mode" + depends on !DMA_UNCACHED_NONE + +config SIR_BFIN_PIO + bool "PIO mode" +endchoice
This arrangement is pretty user-hostile. It requires that people reconfigure and rebuild their kernel any time they want to change the driver options.
It would be much better to be able to do this via a kernel boot option.
It would be better still to be able to do this via a module parameter.
It would be better still to be able to do this via a runtime knob:
ioctl, sysfs file, whatever.
it would be better still to do all this automatically at probe time.
What you've chosen here is the worst possible solution, sorry.
drivers/net/irda/Kconfig config IRTTY_SIR
Quoted 12 lines
drivers/net/irda/Kconfig +8
-0comment "Dongle support" +static void turnaround_delay(unsigned long last_jif, int mtt) +{ + long ticks; + + mtt = mtt < 10000 ? 10000 : mtt; + ticks = 1 + mtt / (USEC_PER_SEC / HZ); + schedule_timeout_interruptible(ticks); +}
If the calling task has signal_pending() then the schedule_timeout_interruptible() will return immediately. I bet this breaks the driver.
Fixable by using schedule_timeout_uninterruptible().
drivers/net/irda/Kconfig
Quoted 11 lines
...
drivers/net/irda/Kconfig +8
-0+static void bfin_sir_stop_tx(struct bfin_sir_port *port) +{ +#ifdef CONFIG_SIR_BFIN_DMA + disable_dma(port->tx_dma_channel); +#endif + + while (!(SIR_UART_GET_LSR(port) & THRE)) + continue;
cpu_relax().
Quoted 8 lines
drivers/net/irda/Kconfig +5
-0+ SIR_UART_STOP_TX(port); +} + +#ifdef CONFIG_SIR_BFIN_PIO +static void bfin_sir_tx_chars(struct net_device *dev)
drivers/net/irda/Kconfig
Quoted 10 lines
drivers/net/irda/Kconfig +10
-0+{ + unsigned int chr; + struct bfin_sir_self *self = netdev_priv(dev); + struct bfin_sir_port *port = self->sir_port; + + if (self->tx_buff.len != 0) { + chr = *(self->tx_buff.data); + SIR_UART_PUT_CHAR(port, chr); + self->tx_buff.data++; + self->tx_buff.len--;
I don't see any locking which protects the tx_buff.
Quoted 22 lines
drivers/net/irda/Kconfig +22
-0+ } else { + self->stats.tx_packets++; + self->stats.tx_bytes += self->tx_buff.data - self->tx_buff.head; + if (self->newspeed) { + bfin_sir_set_speed(port, self->newspeed); + self->speed = self->newspeed; + self->newspeed = 0; + } + bfin_sir_stop_tx(port); + bfin_sir_enable_rx(port); + /* I'm hungry! */ + netif_wake_queue(dev); + } +} + +static void bfin_sir_rx_chars(struct net_device *dev) +{ + struct bfin_sir_self *self = netdev_priv(dev); + struct bfin_sir_port *port = self->sir_port; + unsigned char ch; + + SIR_UART_CLEAR_LSR(port);
drivers/net/irda/Kconfig
Quoted 10 lines
drivers/net/irda/Kconfig +10
-0+ ch = SIR_UART_GET_CHAR(port); + async_unwrap_char(dev, &self->stats, &self->rx_buff, ch); + dev->last_rx = jiffies; +} + +static irqreturn_t bfin_sir_rx_int(int irq, void *dev_id) +{ + struct net_device *dev = dev_id; + struct bfin_sir_self *self = netdev_priv(dev); + struct bfin_sir_port *port = self->sir_port;
blank line here.
Quoted 5 lines
drivers/net/irda/Kconfig +5
-0+ while ((SIR_UART_GET_LSR(port) & DR)) + bfin_sir_rx_chars(dev); + + return IRQ_HANDLED; +}
drivers/net/irda/Kconfig
Quoted 10 lines
drivers/net/irda/Kconfig +7
-0+ +static irqreturn_t bfin_sir_dma_tx_int(int irq, void *dev_id) +{ + struct net_device *dev = dev_id; + struct bfin_sir_self *self = netdev_priv(dev); + struct bfin_sir_port *port = self->sir_port; + spin_lock(&self->lock);
please prefer to put a blank line after end-of-locals and before start-of-code,
Quoted 18 lines
drivers/net/irda/Kconfig +18
-0+ if (!(get_dma_curr_irqstat(port->tx_dma_channel)&DMA_RUN)) { + clear_dma_irqstat(port->tx_dma_channel); + bfin_sir_stop_tx(port); + + self->stats.tx_packets++; + self->stats.tx_bytes += self->tx_buff.len; + self->tx_buff.len = 0; + if (self->newspeed) { + bfin_sir_set_speed(port, self->newspeed); + self->speed = self->newspeed; + self->newspeed = 0; + } + bfin_sir_enable_rx(port); + /* I'm hungry! */ + netif_wake_queue(dev); + port->tx_done = 1; + } + spin_unlock(&self->lock);
drivers/net/irda/Kconfig
Quoted 10 lines
drivers/net/irda/Kconfig +10
-0+ + return IRQ_HANDLED; +} + +static void bfin_sir_dma_rx_chars(struct net_device *dev) +{ + struct bfin_sir_self *self = netdev_priv(dev); + struct bfin_sir_port *port = self->sir_port; + int i; +
like that.
Quoted 4 lines
drivers/net/irda/Kconfig +4
-0+ SIR_UART_CLEAR_LSR(port); + + for (i = port->rx_dma_buf.head; i < port->rx_dma_buf.tail; i++) + async_unwrap_char(dev, &self->stats, &self->rx_buff, port->rx_dma_buf.buf[i]);
drivers/net/irda/Kconfig
Quoted 10 lines
drivers/net/irda/Kconfig +7
-0+} + +static int bfin_sir_stop(struct net_device *dev) +{ + struct bfin_sir_self *self = netdev_priv(dev); + + flush_scheduled_work();
flush_scheduled_work() flushes all work items. It is preferable to use flush_work() to flush a single item.
Quoted 12 lines
drivers/net/irda/Kconfig +12
-0+ bfin_sir_shutdown(self->sir_port, dev); + + if (self->rxskb) { + dev_kfree_skb(self->rxskb); + self->rxskb = NULL; + } + + /* Stop IrLAP */ + if (self->irlap) { + irlap_close(self->irlap); + self->irlap = NULL; + }
drivers/net/irda/Kconfig
Quoted 10 lines
drivers/net/irda/Kconfig +10
-0+ + netif_stop_queue(dev); + self->open = 0; + + return 0; +} + +static int bfin_sir_init_iobuf(iobuff_t *io, int size) +{ + io->head = kmalloc(size, GFP_KERNEL | GFP_DMA);
Does it actually _need_ the GFP_DMA?
It is wrong (or at least, contradictory) to combine GFP_KERNEL and GFP_DMA together in this manner. Use one or the other.
Quoted 12 lines
drivers/net/irda/Kconfig +9
-0+ if (!io->head) + return -ENOMEM; + io->truesize = size; + io->in_frame = FALSE; + io->state = OUTSIDE_FRAME; + io->data = io->head; + return 0; +} +
Quoted 74 lines · Andrew Morton
Quoted 4 lines · On Fri, 6 Mar 2009 14:44:45 +0800 Bryan Wu <[email protected]> wrote:
From: Graf Yang <[email protected]>
Signed-off-by Graf Yang <[email protected]>Signed-off-by Bryan Wu <[email protected]>Mutter. Nothing to be said at all?
Quoted 47 lines
drivers/net/irda/bfin_sir.h | 147 ++++++++ 4 files changed, 989 insertions(+), 0 deletions(-) create mode 100644 drivers/net/irda/bfin_sir.c create mode 100644 drivers/net/irda/bfin_sir.hdrivers/net/irda/Kconfig +34
-0@@ -17,6 +17,51 @@ config IRTTY_SIR If unsure, say Y. +config BFIN_SIR + tristate "Blackfin SIR on UART" + depends on BLACKFIN && IRDA + default n + help + Say Y here if your want to enable SIR function on Blackfin UART + devices. + + To activate this driver you can start irattach like: + "irattach irda0 -s" + + Saying M, it will be built as a module named bfin_sir. + + Note that you need to turn off one of the serial drivers for SIR + to use that UART. + +config BFIN_SIR3 + bool "Blackfin SIR on UART3" + depends on BFIN_SIR && !SERIAL_BFIN_UART3 && (BF54x) + +config BFIN_SIR1 + bool "Blackfin SIR on UART1" + depends on BFIN_SIR && !SERIAL_BFIN_UART1 && (!BF531 && !BF532 && !BF533 && !BF561) + +config BFIN_SIR0 + bool "Blackfin SIR on UART0" + depends on BFIN_SIR && !SERIAL_BFIN_UART0 + +config BFIN_SIR2 + bool "Blackfin SIR on UART2" + depends on BFIN_SIR && !SERIAL_BFIN_UART2 && (BF54x || BF538 || BF539) + +choice + prompt "SIR Mode"drivers/net/irda/Kconfig config IRTTY_SIR · line 63
Quoted 10 lines
drivers/net/irda/Kconfig +10
-0+ depends on BFIN_SIR + default SIR_BFIN_DMA + +config SIR_BFIN_DMA + bool "DMA mode" + depends on !DMA_UNCACHED_NONE + +config SIR_BFIN_PIO + bool "PIO mode" +endchoiceThis arrangement is pretty user-hostile. It requires that people reconfigure and rebuild their kernel any time they want to change the driver options.
It would be much better to be able to do this via a kernel boot option.
Quoted 8 lines
It would be better still to be able to do this via a module parameter.
It would be better still to be able to do this via a runtime knob:
ioctl, sysfs file, whatever.it would be better still to do all this automatically at probe time.
What you've chosen here is the worst possible solution, sorry.
Because most of our end-users are using it in embedded devices, they want the binary be smaller and faster. The compile time overhead is not a problem.
Quoted 18 lines
drivers/net/irda/Kconfig config IRTTY_SIR
Quoted 13 lines
drivers/net/irda/Kconfig +8
-0comment "Dongle support" +static void turnaround_delay(unsigned long last_jif, int mtt) +{ + long ticks; + + mtt = mtt < 10000 ? 10000 : mtt; + ticks = 1 + mtt / (USEC_PER_SEC / HZ); + schedule_timeout_interruptible(ticks); +}If the calling task has
signal_pending()then theschedule_timeout_interruptible()will return immediately. I bet this breaks the driver.
Quoted 1 line
Fixable by using
schedule_timeout_uninterruptible().
OK, Thanks.
Quoted 21 lines
drivers/net/irda/Kconfig
Quoted 12 lines
...
drivers/net/irda/Kconfig +8
-0+static void bfin_sir_stop_tx(struct bfin_sir_port *port) +{ +#ifdef CONFIG_SIR_BFIN_DMA + disable_dma(port->tx_dma_channel); +#endif + + while (!(SIR_UART_GET_LSR(port) & THRE)) + continue;
cpu_relax().Quoted 6 lines
drivers/net/irda/Kconfig +3
-0+ SIR_UART_STOP_TX(port); +} +
Quoted 14 lines
drivers/net/irda/Kconfig
Quoted 12 lines
drivers/net/irda/Kconfig +12
-0+#ifdef CONFIG_SIR_BFIN_PIO +static void bfin_sir_tx_chars(struct net_device *dev) +{ + unsigned int chr; + struct bfin_sir_self *self = netdev_priv(dev); + struct bfin_sir_port *port = self->sir_port; + + if (self->tx_buff.len != 0) { + chr = *(self->tx_buff.data); + SIR_UART_PUT_CHAR(port, chr); + self->tx_buff.data++; + self->tx_buff.len--;I don't see any locking which protects the
tx_buff.
I will add lock for both tx/rx.
Quoted 95 lines
Quoted 23 lines
drivers/net/irda/Kconfig +22
-0+ } else { + self->stats.tx_packets++; + self->stats.tx_bytes += self->tx_buff.data - self->tx_buff.head; + if (self->newspeed) { + bfin_sir_set_speed(port, self->newspeed); + self->speed = self->newspeed; + self->newspeed = 0; + } + bfin_sir_stop_tx(port); + bfin_sir_enable_rx(port); + /* I'm hungry! */ + netif_wake_queue(dev); + } +} + +static void bfin_sir_rx_chars(struct net_device *dev) +{ + struct bfin_sir_self *self = netdev_priv(dev); + struct bfin_sir_port *port = self->sir_port; + unsigned char ch; + + SIR_UART_CLEAR_LSR(port);drivers/net/irda/Kconfig
Quoted 10 lines
drivers/net/irda/Kconfig +10
-0+ ch = SIR_UART_GET_CHAR(port); + async_unwrap_char(dev, &self->stats, &self->rx_buff, ch); + dev->last_rx = jiffies; +} + +static irqreturn_t bfin_sir_rx_int(int irq, void *dev_id) +{ + struct net_device *dev = dev_id; + struct bfin_sir_self *self = netdev_priv(dev); + struct bfin_sir_port *port = self->sir_port;blank line here.
Quoted 5 lines
drivers/net/irda/Kconfig +5
-0+ while ((SIR_UART_GET_LSR(port) & DR)) + bfin_sir_rx_chars(dev); + + return IRQ_HANDLED; +}drivers/net/irda/Kconfig
Quoted 10 lines
drivers/net/irda/Kconfig +7
-0+ +static irqreturn_t bfin_sir_dma_tx_int(int irq, void *dev_id) +{ + struct net_device *dev = dev_id; + struct bfin_sir_self *self = netdev_priv(dev); + struct bfin_sir_port *port = self->sir_port; + spin_lock(&self->lock);please prefer to put a blank line after end-of-locals and before start-of-code,
Quoted 18 lines
drivers/net/irda/Kconfig +18
-0+ if (!(get_dma_curr_irqstat(port->tx_dma_channel)&DMA_RUN)) { + clear_dma_irqstat(port->tx_dma_channel); + bfin_sir_stop_tx(port); + + self->stats.tx_packets++; + self->stats.tx_bytes += self->tx_buff.len; + self->tx_buff.len = 0; + if (self->newspeed) { + bfin_sir_set_speed(port, self->newspeed); + self->speed = self->newspeed; + self->newspeed = 0; + } + bfin_sir_enable_rx(port); + /* I'm hungry! */ + netif_wake_queue(dev); + port->tx_done = 1; + } + spin_unlock(&self->lock);drivers/net/irda/Kconfig
Quoted 10 lines
drivers/net/irda/Kconfig +10
-0+ + return IRQ_HANDLED; +} + +static void bfin_sir_dma_rx_chars(struct net_device *dev) +{ + struct bfin_sir_self *self = netdev_priv(dev); + struct bfin_sir_port *port = self->sir_port; + int i; +like that.
Quoted 9 lines
drivers/net/irda/Kconfig +6
-0+ SIR_UART_CLEAR_LSR(port); + + for (i = port->rx_dma_buf.head; i < port->rx_dma_buf.tail; i++) + async_unwrap_char(dev, &self->stats, &self->rx_buff, port->rx_dma_buf.buf[i]); +} +
Quoted 8 lines
drivers/net/irda/Kconfig
Quoted 5 lines
drivers/net/irda/Kconfig +5
-0+static int bfin_sir_stop(struct net_device *dev) +{ + struct bfin_sir_self *self = netdev_priv(dev); + + flush_scheduled_work();
flush_scheduled_work()flushes all work items. It is preferable to useflush_work()to flush a single item.
OK, thanks.
Quoted 27 lines
Quoted 14 lines
drivers/net/irda/Kconfig +12
-0+ bfin_sir_shutdown(self->sir_port, dev); + + if (self->rxskb) { + dev_kfree_skb(self->rxskb); + self->rxskb = NULL; + } + + /* Stop IrLAP */ + if (self->irlap) { + irlap_close(self->irlap); + self->irlap = NULL; + }drivers/net/irda/Kconfig
Quoted 10 lines
drivers/net/irda/Kconfig +10
-0+ + netif_stop_queue(dev); + self->open = 0; + + return 0; +} + +static int bfin_sir_init_iobuf(iobuff_t *io, int size) +{ + io->head = kmalloc(size, GFP_KERNEL | GFP_DMA);Does it actually _need_ the
GFP_DMA?
Quoted 2 lines
It is wrong (or at least, contradictory) to combine
GFP_KERNELandGFP_DMAtogether in this manner. Use one or the other.
OK. Thanks.
Quoted 13 lines
Quoted 13 lines
drivers/net/irda/Kconfig +9
-0+ if (!io->head) + return -ENOMEM; + io->truesize = size; + io->in_frame = FALSE; + io->state = OUTSIDE_FRAME; + io->data = io->head; + return 0; +} +