Various nits, fixes and hacks for mantis CA support on SMP
PATCH 1/1 Various nits, fixes and hacks for mantis CA support on SMP
Hi,
This patch, against 3.3-rc4, is basically a conglomerate of patches that together seem to make CA support on mantis working and stable, even on SMP systems. (I'm using a Terratec Cinergy DVB-S2 card with a Conax CAM, with mumudvb as userspace.) There are a few fixes from this mailing list and some of my own; the end result is too ugly to include, and there are still things I don't understand at all, but I hope it can be useful for some.
Below is the list of what the patch does:
- I've followed the instructions from some post on this mailing list to enable CAM support in the first place (mantis_set_direction move to mantis_pci.c, uncomment mantis_ca_init).
- The MANTIS_GPIF_STATUS fix from http://patchwork.linuxtv.org/patch/8776/.
Not that it seems to change a lot for me, but it makes sense.
- I've fixed a ton of SMP-related bugs. Basically a lot of the members of mantis_ca were accessed from several threads without a mutex, which is a big no-no; I've mostly changed to using atomic operations here, although I also added some locks were it made sense (e.g. when resetting the CAM). The ca_lock is replaced by a more general int_stat_lock, which ideally is held when banging on MANTIS_INT_STAT. (I have no hardware documentation, so I'm afraid I don't really know the specifics here.)
- mantis_hif_write_wait() would never clear MANTIS_SBUF_OPDONE_BIT, leading to a lot of operations never actually waiting for the callback. I've added many such fixes, as well as debugging output when the bit is in a surprising state (e.g., MANTIS_SBUF_OPDONE_BIT set before the beginning of an operation, where it really should be cleared).
- Some operations check for timeout by testing if wait_event_timeout() return -ERESTARTSYS. However, wait_event_timeout() can can never do this; the return value for timeout is zero. I've fixed this (well, I seemingly forgot one; have to do that in the next version :-) ). Unfortunately, this make the problems in the next point a _lot_ worse, since timeouts are now actually percolated up the stack.
- As others have noticed, sometimes, especially during DMA transfers, the IRQ0 flag is never properly set and thus reads never return. (The typical case for this is when we've just done a write and the en50221 thread is waiting for the CAM status word to signal STATUSREG_DA; if this doesn't happen in a reasonable amount of time, the upstream libdvben50221.so will report errors back to mumudvb.) I have no idea why this happens more often on SMP systems than on UMP systems, but they really seem to do. I haven't found any reasonable workaround for reliable polling either, so I'm making a hack -- if there's nothing returned in two milliseconds, the read is simply assumed to have completed. This is an unfortunate hack, but in practice it's identical to the previous behavior except with a shorter timeout.
- A hack to fix a mutex issue in the DVB layer; dvb_usercopy(), which is called on all ioctls, not only copies data to and from userspace, but also takes a lock on the file descriptor, which means that only one ioctl can run at a time. This means that if one thread of mumudvb is busy trying to get, say, the SNR from the frontend (which can hang due to the issue above), the CAM thread's ioctl(fd, CA_GET_SLOT_INFO, ...) will hang, even though it doesn't need to communicate with the hardware at all. This obviously requires a better fix, but I don't know the generic DVB layer well enough to say what it is. Maybe it's some sort of remnant of from when all ioctl()s took the BKL. Note that on UMP kernels without preemption, mutex_lock is to the best of my knowledge a no-op, so these delay issues would not show up on non-SMP.
- Tiny cleanups: Removed some unused mmread()s and structure members. Some debugging messages have been made more specific or clearer (e.g. reads say what address they're from, the I2C subsystem reports if there were any timeouts, the interrupt handler properly clears the RISC status word so it isn't shown as <Unknown>).
I'm still not happy with the bit-banging on the I2C interface (as opposed to dealing with it in the interrupt handler); I long suspected it for causing the IRQ0 problems, especially as they seem to have a sort-of similar issue with I2CDONE/I2CRACk never being set, but it seem the DMA transfers is really what causes it somehow, so I've left it alone.
Anyway, if there are specific pieces people want me to split out for mainline, I'd be happy to do that and add the required Signed-Off-By lines etc. Let me know.
/* Steinar */
Signature · 1 line
Homepage: http://www.sesse.net/
drivers/media/dvb/dvb-core/dvbdev.c renamed from linux-3.3-rc4/drivers/media/dvb/dvb-core/dvbdev.c +2 -2
@@ -417,10 +417,10 @@ }/* call driver */ -mutex_lock (&dvbdev_mutex); +// mutex_lock(&dvbdev_mutex); if ((err =func (file, cmd, parg)) == -ENOIOCTLCMD ) err = -EINVAL ; -mutex_unlock (&dvbdev_mutex); +// mutex_unlock(&dvbdev_mutex); if (err <0 ) goto out;
drivers/media/dvb/mantis/mantis_ca.c renamed from linux-3.3-rc4/drivers/media/dvb/mantis/mantis_ca.c +17 -3
@@ -34,6 +34,7 @@#include "mantis_link.h" #include "mantis_hif.h" #include "mantis_reg.h" +#include "mantis_pci.h" #include "mantis_ca.h"
@@ -95,11 +96,25 @@struct mantis_pci *mantis = ca->ca_priv;dprintk (MANTIS_DEBUG ,1 ,"Slot(%d): Slot RESET" , slot); +mutex_lock (&mantis->int_stat_lock); +if (test_and_clear_bit (MANTIS_SBUF_OPDONE_BIT , &ca->hif_event)) { +dprintk (MANTIS_NOTICE ,1 ,"Slot(%d): Reset operation done before it started!" , slot); + }udelay (500 );/* Wait.. */ mmwrite (0xda ,MANTIS_PCMCIA_RESET );/* Leading edge assert */ udelay (500 );mmwrite (0x00 ,MANTIS_PCMCIA_RESET );/* Trailing edge deassert */ msleep (1000 ); + +if (wait_event_timeout (ca->hif_opdone_wq, +test_and_clear_bit (MANTIS_SBUF_OPDONE_BIT , &ca->hif_event), +msecs_to_jiffies (500 )) == -ERESTARTSYS ) { + +dprintk (MANTIS_ERROR ,1 ,"Slot(%d): Reset timeout!" , slot); + }else { +dprintk (MANTIS_DEBUG ,1 ,"Slot(%d): Reset complete" , slot); + } +mutex_unlock (&mantis->int_stat_lock);dvb_ca_en50221_camready_irq (&ca->en50221,0 );return 0 ;
@@ -111,6 +126,7 @@struct mantis_pci *mantis = ca->ca_priv;dprintk (MANTIS_DEBUG ,1 ,"Slot(%d): Slot shutdown" , slot); +mantis_set_direction (mantis,0 );/* Disable TS through CAM */ return 0 ; }
@@ -121,7 +137,7 @@struct mantis_pci *mantis = ca->ca_priv;dprintk (MANTIS_DEBUG ,1 ,"Slot(%d): TS control" , slot); -/* mantis_set_direction(mantis, 1); */ /* Enable TS through CAM */ +mantis_set_direction (mantis,1 );/* Enable TS through CAM */ return 0 ; }
@@ -172,8 +188,6 @@ ca->en50221.poll_slot_status = mantis_slot_status; ca->en50221.data = ca; -mutex_init (&ca->ca_lock); -init_waitqueue_head (&ca->hif_data_wq);init_waitqueue_head (&ca->hif_opdone_wq);init_waitqueue_head (&ca->hif_write_wq);
drivers/media/dvb/mantis/mantis_cards.c renamed from linux-3.3-rc4/drivers/media/dvb/mantis/mantis_cards.c +13 -12
@@ -73,7 +73,7 @@static irqreturn_t mantis_irq_handler (int irq,void *dev_id) { -u32 stat =0 , mask =0 , lstat =0 ; +u32 stat =0 , mask =0 ;u32 rst_stat =0 , rst_mask =0 ;struct mantis_pci *mantis;
@@ -88,19 +88,9 @@ stat =mmread (MANTIS_INT_STAT ); mask =mmread (MANTIS_INT_MASK ); - lstat = stat & ~MANTIS_INT_RISCSTAT ;if (!(stat & mask))return IRQ_NONE ; - rst_mask =MANTIS_GPIF_WRACK | -MANTIS_GPIF_OTHERR | -MANTIS_SBUF_WSTO | -MANTIS_GPIF_EXTIRQ ; - - rst_stat =mmread (MANTIS_GPIF_STATUS ); - rst_stat &= rst_mask; -mmwrite (rst_stat,MANTIS_GPIF_STATUS ); - mantis->mantis_int_stat = stat; mantis->mantis_int_mask = mask;dprintk (MANTIS_DEBUG ,0 ,"\n-- Stat=<%02x> Mask=<%02x> --" , stat, mask);
@@ -109,6 +99,15 @@ }if (stat &MANTIS_INT_IRQ0 ) {dprintk (MANTIS_DEBUG ,0 ,"<%s>" , label[1 ]); + + rst_mask =MANTIS_GPIF_WRACK | +MANTIS_GPIF_OTHERR | +MANTIS_SBUF_WSTO | +MANTIS_GPIF_EXTIRQ ; + + rst_stat =mmread (MANTIS_GPIF_STATUS ); +mmwrite (rst_stat & rst_mask,MANTIS_GPIF_STATUS ); + mantis->gpif_status = rst_stat;wake_up (&ca->hif_write_wq);schedule_work (&ca->hif_evm_work);
@@ -142,7 +141,8 @@wake_up (&mantis->i2c_wq); }mmwrite (stat,MANTIS_INT_STAT ); - stat &= ~(MANTIS_INT_RISCEN | MANTIS_INT_I2CDONE | + stat &= ~(MANTIS_INT_RISCSTAT | + MANTIS_INT_RISCEN | MANTIS_INT_I2CDONE | MANTIS_INT_I2CRACK | MANTIS_INT_PCMCIA7 | MANTIS_INT_PCMCIA6 | MANTIS_INT_PCMCIA5 | MANTIS_INT_PCMCIA4 | MANTIS_INT_PCMCIA3 |
@@ -179,6 +179,7 @@ config = (struct mantis_hwconfig *) pci_id->driver_data; config->irq_handler = &mantis_irq_handler; mantis->hwconfig = config; +mutex_init (&mantis->int_stat_lock); err =mantis_pci_init (mantis);if (err) {
drivers/media/dvb/mantis/mantis_common.h renamed from linux-3.3-rc4/drivers/media/dvb/mantis/mantis_common.h +2 -1
@@ -161,9 +161,10 @@/* A12 A13 A14 */ u32 gpio_status; -u32 gpif_status; +volatile unsigned long gpif_status;struct mantis_ca *mantis_ca; +struct mutex int_stat_lock;wait_queue_head_t uart_wq;struct work_struct uart_work;
drivers/media/dvb/mantis/mantis_core.c renamed from linux-3.3-rc4/drivers/media/dvb/mantis/mantis_core.c +0 -20
@@ -213,23 +213,3 @@udelay (100 ); } -/* direction = 0 , no CI passthrough ; 1 , CI passthrough */ -void mantis_set_direction (struct mantis_pci *mantis,int direction) -{ -u32 reg; - - reg =mmread (0x28 ); -dprintk (verbose,MANTIS_DEBUG ,1 ,"TS direction setup" ); -if (direction ==0x01 ) { -/* to CI */ - reg |=0x04 ; -mmwrite (reg,0x28 ); - reg &=0xff -0x04 ; -mmwrite (reg,0x28 ); - }else { - reg &=0xff -0x04 ; -mmwrite (reg,0x28 ); - reg |=0x04 ; -mmwrite (reg,0x28 ); - } -}
drivers/media/dvb/mantis/mantis_dvb.c renamed from linux-3.3-rc4/drivers/media/dvb/mantis/mantis_dvb.c +3 -1
@@ -239,6 +239,8 @@ mantis->fe =NULL ; goto err5; } + +mantis_ca_init (mantis); } }
@@ -274,7 +276,6 @@int err;if (mantis->fe) { -/* mantis_ca_exit(mantis); */ err =mantis_frontend_shutdown (mantis);if (err !=0 )dprintk (MANTIS_ERROR ,1 ,"Frontend exit while POWER ON! <%d>" , err);
@@ -282,6 +283,7 @@dvb_frontend_detach (mantis->fe); } +mantis_ca_exit (mantis);tasklet_kill (&mantis->tasklet);dvb_net_release (&mantis->dvbnet);
drivers/media/dvb/mantis/mantis_evm.c renamed from linux-3.3-rc4/drivers/media/dvb/mantis/mantis_evm.c +11 -10
@@ -20,6 +20,7 @@#include <linux/kernel.h> +#include <linux/atomic.h> #include <linux/signal.h> #include <linux/sched.h> #include <linux/interrupt.h>
@@ -41,10 +42,7 @@ struct mantis_ca *ca = container_of(work, struct mantis_ca, hif_evm_work);struct mantis_pci *mantis = ca->ca_priv; -u32 gpif_stat, gpif_mask; - - gpif_stat =mmread (MANTIS_GPIF_STATUS ); - gpif_mask =mmread (MANTIS_GPIF_IRQCFG ); +u32 gpif_stat =mmread (MANTIS_GPIF_STATUS );if (gpif_stat &MANTIS_GPIF_DETSTAT ) {if (gpif_stat &MANTIS_CARD_PLUGIN ) {
@@ -66,13 +64,13 @@ } } -if (mantis->gpif_status &MANTIS_GPIF_EXTIRQ ) +if (gpif_stat &MANTIS_GPIF_EXTIRQ )dprintk (MANTIS_DEBUG ,1 ,"Event Mgr: Adapter(%d) Slot(0): Ext IRQ" , mantis->num); -if (mantis->gpif_status &MANTIS_SBUF_WSTO ) +if (gpif_stat &MANTIS_SBUF_WSTO )dprintk (MANTIS_DEBUG ,1 ,"Event Mgr: Adapter(%d) Slot(0): Smart Buffer Timeout" , mantis->num); -if (mantis->gpif_status &MANTIS_GPIF_OTHERR ) +if (gpif_stat &MANTIS_GPIF_OTHERR )dprintk (MANTIS_DEBUG ,1 ,"Event Mgr: Adapter(%d) Slot(0): Alignment Error" , mantis->num);if (gpif_stat &MANTIS_SBUF_OVFLW )
@@ -87,10 +85,13 @@if (gpif_stat &MANTIS_SBUF_EMPTY )dprintk (MANTIS_DEBUG ,1 ,"Event Mgr: Adapter(%d) Slot(0): Smart Buffer Empty" , mantis->num); -if (gpif_stat &MANTIS_SBUF_OPDONE ) { +if (gpif_stat &MANTIS_SBUF_OPDONE )dprintk (MANTIS_DEBUG ,1 ,"Event Mgr: Adapter(%d) Slot(0): Smart Buffer operation complete" , mantis->num); - ca->sbuf_status =MANTIS_SBUF_DATA_AVAIL ; - ca->hif_event =MANTIS_SBUF_OPDONE ; + +if (gpif_stat &MANTIS_SBUF_OPDONE ) { +if (test_and_set_bit (MANTIS_SBUF_OPDONE_BIT , &ca->hif_event)) { +dprintk (MANTIS_NOTICE ,1 ,"Operation done, but SBUF_OPDONE bit was already set!" ); + }wake_up (&ca->hif_opdone_wq); } }
drivers/media/dvb/mantis/mantis_hif.c renamed from linux-3.3-rc4/drivers/media/dvb/mantis/mantis_hif.c +59 -38
214 lines not on this page · raw message
drivers/media/dvb/mantis/mantis_i2c.c renamed from linux-3.3-rc4/drivers/media/dvb/mantis/mantis_i2c.c +40 -2
132 lines not on this page · raw message
drivers/media/dvb/mantis/mantis_link.h renamed from linux-3.3-rc4/drivers/media/dvb/mantis/mantis_link.h +1 -10
@@ -25,12 +25,6 @@#include <linux/workqueue.h> #include "dvb_ca_en50221.h" -enum mantis_sbuf_status { -MANTIS_SBUF_DATA_AVAIL =1 , -MANTIS_SBUF_DATA_EMPTY =2 , -MANTIS_SBUF_DATA_OVFLW =3 -}; -struct mantis_slot {u32 timeout;u32 slave_cfg;
@@ -48,20 +42,17 @@struct work_struct hif_evm_work; -u32 hif_event; +volatile unsigned long hif_event;wait_queue_head_t hif_opdone_wq;wait_queue_head_t hif_brrdyw_wq;wait_queue_head_t hif_data_wq;wait_queue_head_t hif_write_wq;/* HIF Write op */ -enum mantis_sbuf_status sbuf_status; -enum mantis_slot_state slot_state;void *ca_priv;struct dvb_ca_en50221 en50221; -struct mutex ca_lock; };/* CA */
drivers/media/dvb/mantis/mantis_pci.c renamed from linux-3.3-rc4/drivers/media/dvb/mantis/mantis_pci.c +23 -0
@@ -97,6 +97,7 @@pci_read_config_byte (pdev,PCI_LATENCY_TIMER , &latency); mantis->latency = latency; mantis->revision = pdev->revision; +mantis_set_direction (mantis,0 ); dprintk(MANTIS_ERROR, 0, " Mantis Rev %d [%04x:%04x], ", mantis->revision,
@@ -110,6 +111,7 @@ mantis->mantis_addr, mantis->mmio); +mmwrite (0x00 ,MANTIS_INT_MASK ); err = request_irq(pdev->irq, config->irq_handler, IRQF_SHARED,
@@ -165,6 +167,27 @@ }EXPORT_SYMBOL_GPL (mantis_pci_exit); +/* direction = 0 , no CI passthrough ; 1 , CI passthrough */ +void mantis_set_direction (struct mantis_pci *mantis,int direction) +{ +u32 reg; + + reg =mmread (0x28 ); +dprintk (MANTIS_DEBUG ,1 ,"TS direction setup" ); +if (direction ==0x01 ) { +/* to CI */ + reg |=0x04 ; +mmwrite (reg,0x28 ); + reg &=0xff -0x04 ; +mmwrite (reg,0x28 ); + }else { + reg &=0xff -0x04 ; +mmwrite (reg,0x28 ); + reg |=0x04 ; +mmwrite (reg,0x28 ); + } +} +MODULE_DESCRIPTION ("Mantis PCI DTV bridge driver" );MODULE_AUTHOR ("Manu Abraham" );MODULE_LICENSE ("GPL" );
drivers/media/dvb/mantis/mantis_pci.h renamed from linux-3.3-rc4/drivers/media/dvb/mantis/mantis_pci.h +2 -0
@@ -24,4 +24,6 @@extern int mantis_pci_init (struct mantis_pci *mantis);extern void mantis_pci_exit (struct mantis_pci *mantis); +void mantis_set_direction (struct mantis_pci *mantis,int direction); +#endif /* __MANTIS_PCI_H */
drivers/media/dvb/mantis/mantis_reg.h renamed from linux-3.3-rc4/drivers/media/dvb/mantis/mantis_reg.h +4 -2
@@ -152,11 +152,13 @@#define MANTIS_GPIF_STATUS 0x9c#define MANTIS_SBUF_KILLOP (0x01 << 15) -#define MANTIS_SBUF_OPDONE (0x01 << 14) +#define MANTIS_SBUF_OPDONE_BIT 14 +#define MANTIS_SBUF_OPDONE (0x01 << MANTIS_SBUF_OPDONE_BIT)#define MANTIS_SBUF_EMPTY (0x01 << 13)#define MANTIS_GPIF_DETSTAT (0x01 << 9)#define MANTIS_GPIF_INTSTAT (0x01 << 8) -#define MANTIS_GPIF_WRACK (0x01 << 7) +#define MANTIS_GPIF_WRACK_BIT 7 +#define MANTIS_GPIF_WRACK (0x01 << MANTIS_GPIF_WRACK_BIT)#define MANTIS_GPIF_BRRDY (0x01 << 6)#define MANTIS_SBUF_OVFLW (0x01 << 5)#define MANTIS_GPIF_OTHERR (0x01 << 4)
Quoted 5 lines · Steinar H. Gunderson
I'm still not happy with the bit-banging on the I2C interface (as opposed to dealing with it in the interrupt handler); I long suspected it for causing the IRQ0 problems, especially as they seem to have a sort-of similar issue with I2CDONE/I2CRACk never being set, but it seem the DMA transfers is really what causes it somehow, so I've left it alone.
There's one more thing I forgot to mention; deinitialization does not seem to work correctly. If I remove the mantis driver and reload it, the CAM is no longer detected correctly (when the 50211 driver tries to read the identification bits from the CAM memory space, they simply don't match anymore). This is annoying, as it means a reboot is required whenever one wants to test a new fix, but I haven't been able to figure out why it happens. Just wanted to mention so that nobody bangs their head in the wall too much due to hitting that problem :-)
/* Steinar */
Signature · 1 line
Homepage: http://www.sesse.net/
Hi
Nice work. I looked your code very shortly.
I'm not happy with I2CDONE busy looping either.
I've tried twice lately to swith into I2C IRQ, but those patches have caused I2CDONE timeouts.
Do my following I2C logic thoughts make any sense?
I2C bus might have some underlying requirements:
1. When driver wants to talk to a DVB frontend, it first opens up an I2C gate, then talks, and finally closes the I2C gate. This is ok.
2. After setting up DVB frontend frequency etc. I2C bus should be quiet 10ms (radio silence, to fasten taking DVB TS lock). This is ok.
There might be race conditions, that the driver possibly manages:
1. If two threads talk into DVB frontend, one could turn off the I2C gate, while the other is talking to DVB frontend.
This would case lack of I2CRACK: only way to recover would be to turn the I2C gate on, and then redo the I2C transfer.
2. Thread 1 turns I2C gate into DVB frontend and sets up frequency. It waits 10ms. Thread 2 will talk to some I2C device, thus breaking the silence. This case would not be so bad, because it would just delay taking the wanted DVB TS lock.
Regards,
Marko Ristola
28.02.2012 03:03, Steinar H. Gunderson kirjoitti:
Quoted 82 lines
Hi,
This patch, against 3.3-rc4, is basically a conglomerate of patches that together seem to make CA support on mantis working and stable, even on SMP systems. (I'm using a Terratec Cinergy DVB-S2 card with a Conax CAM, with mumudvb as userspace.) There are a few fixes from this mailing list and some of my own; the end result is too ugly to include, and there are still things I don't understand at all, but I hope it can be useful for some.
Below is the list of what the patch does:
- I've followed the instructions from some post on this mailing list to enable CAM support in the first place (
mantis_set_directionmove tomantis_pci.c, uncommentmantis_ca_init).- The
MANTIS_GPIF_STATUSfix from http://patchwork.linuxtv.org/patch/8776/.
Not that it seems to change a lot for me, but it makes sense.- I've fixed a ton of SMP-related bugs. Basically a lot of the members of
mantis_cawere accessed from several threads without a mutex, which is a big no-no; I've mostly changed to using atomic operations here, although I also added some locks were it made sense (e.g. when resetting the CAM). Theca_lockis replaced by a more generalint_stat_lock, which ideally is held when banging onMANTIS_INT_STAT. (I have no hardware documentation, so I'm afraid I don't really know the specifics here.)-
mantis_hif_write_wait()would never clearMANTIS_SBUF_OPDONE_BIT, leading to a lot of operations never actually waiting for the callback. I've added many such fixes, as well as debugging output when the bit is in a surprising state (e.g.,MANTIS_SBUF_OPDONE_BITset before the beginning of an operation, where it really should be cleared).- Some operations check for timeout by testing if
wait_event_timeout()return-ERESTARTSYS. However,wait_event_timeout()can can never do this; the return value for timeout is zero. I've fixed this (well, I seemingly forgot one; have to do that in the next version :-) ). Unfortunately, this make the problems in the next point a _lot_ worse, since timeouts are now actually percolated up the stack.- As others have noticed, sometimes, especially during DMA transfers, the IRQ0 flag is never properly set and thus reads never return. (The typical case for this is when we've just done a write and the en50221 thread is waiting for the CAM status word to signal
STATUSREG_DA; if this doesn't happen in a reasonable amount of time, the upstream libdvben50221.so will report errors back to mumudvb.) I have no idea why this happens more often on SMP systems than on UMP systems, but they really seem to do. I haven't found any reasonable workaround for reliable polling either, so I'm making a hack -- if there's nothing returned in two milliseconds, the read is simply assumed to have completed. This is an unfortunate hack, but in practice it's identical to the previous behavior except with a shorter timeout.- A hack to fix a mutex issue in the DVB layer;
dvb_usercopy(), which is called on all ioctls, not only copies data to and from userspace, but also takes a lock on the file descriptor, which means that only one ioctl can run at a time. This means that if one thread of mumudvb is busy trying to get, say, the SNR from the frontend (which can hang due to the issue above), the CAM thread'sioctl(fd, CA_GET_SLOT_INFO, ...)will hang, even though it doesn't need to communicate with the hardware at all. This obviously requires a better fix, but I don't know the generic DVB layer well enough to say what it is. Maybe it's some sort of remnant of from when all ioctl()s took the BKL. Note that on UMP kernels without preemption,mutex_lockis to the best of my knowledge a no-op, so these delay issues would not show up on non-SMP.- Tiny cleanups: Removed some unused mmread()s and structure members. Some debugging messages have been made more specific or clearer (e.g. reads say what address they're from, the I2C subsystem reports if there were any timeouts, the interrupt handler properly clears the RISC status word so it isn't shown as <Unknown>).
I'm still not happy with the bit-banging on the I2C interface (as opposed to dealing with it in the interrupt handler); I long suspected it for causing the IRQ0 problems, especially as they seem to have a sort-of similar issue with I2CDONE/I2CRACk never being set, but it seem the DMA transfers is really what causes it somehow, so I've left it alone.
Anyway, if there are specific pieces people want me to split out for mainline, I'd be happy to do that and add the required Signed-Off-By lines etc. Let me know.
/* Steinar */
Quoted 2 lines · Marko Ristola
I'm not happy with I2CDONE busy looping either.
I've tried twice lately to swith into I2C IRQ, but those patches have caused I2CDONE timeouts.
Note that there are already timeouts with the current polling code, but they are ignored (my patch makes them at least be printed with verbose=5). I can't immediately recall if it's on RACK, DONE or both.
Quoted 1 line
Do my following I2C logic thoughts make any sense?
Well, note first of all that I know next to nothing about I2C, and I've never seen any hardware documentation on the Mantis card (is there any?). But generally it makes sense to me, except that I've never heard of the demand of radio silence for 10 ms before.
Quoted 4 lines
There might be race conditions, that the driver possibly manages:
1. If two threads talk into DVB frontend, one could turn off the I2C gate, while the other is talking to DVB frontend. This would case lack of I2CRACK: only way to recover would be to turn
the I2C gate on, and then redo the I2C transfer.
Note that I've tried putting mutexes around the I2C functions, and it didn't help on the I2C timeouts; however, that was largely on a single-character level, so it might not be enough. (You can see these mutexes being commented out in my patch.)
/* Steinar */
Signature · 1 line
Homepage: http://www.sesse.net/
03.03.2012 01:21, Steinar H. Gunderson kirjoitti:
Quoted 7 lines · Marko Ristola
Quoted 2 lines
I'm not happy with I2CDONE busy looping either.
I've tried twice lately to swith into I2C IRQ, but those patches have caused I2CDONE timeouts.Note that there are already timeouts with the current polling code, but they are ignored (my patch makes them at least be printed with verbose=5). I can't immediately recall if it's on RACK, DONE or both.
I think that occasional timeouts belong to the picture (RACK missing means: packet lost). If I2CDONE comes immediately when I2C command has been emitted,
it is a driver software bug (some earlier I2C command).
Quoted 7 lines
Quoted 2 lines
Do my following I2C logic thoughts make any sense?
Well, note first of all that I know next to nothing about I2C, and I've never seen any hardware documentation on the Mantis card (is there any?). But generally it makes sense to me, except that I've never heard of the demand of radio silence for 10 ms before.
Ok. Radio silence for 10 ms isn't your problem: when you have a FE_LOCK, 10 ms requirement is no more relevant.
Quoted 10 lines
Quoted 5 lines
There might be race conditions, that the driver possibly manages:
1. If two threads talk into DVB frontend, one could turn off the I2C gate, while the other is talking to DVB frontend. This would case lack of I2CRACK: only way to recover would be to turn
the I2C gate on, and then redo the I2C transfer.Note that I've tried putting mutexes around the I2C functions, and it didn't help on the I2C timeouts; however, that was largely on a single-character level, so it might not be enough. (You can see these mutexes being commented out in my patch.)
I have now a new idea for what to try with I2C interrupts. It all depends, whether I understand the driver coding well enough.
Quoted 2 lines
/* Steinar */
I have also a low interest for Mantis coding:
Ideas come fast, and if the new code doesn't work right away, I back up the code somewhere and drop it.
Some years ago during Summer Holiday time I could get something done and even patches got applied into Linux kernel.
Marko Ristola
Em 27-02-2012 22:03, Steinar H. Gunderson escreveu:
Quoted 5 lines
Hi,
This patch, against 3.3-rc4, is basically a conglomerate of patches that together seem to make CA support on mantis working and stable, even on SMP systems.
A "conglomerate of patches" can't be applied upstream. Instead, you should be sending us a patch series, preserving the original author/signed-off-by for each one, if the patches were nod written by you, and add your Signed-off-by: at the end of each patch.
Regards,
Mauro
(I'm using a Terratec Cinergy DVB-S2 card with a Conax CAM, with
Quoted 77 lines
mumudvb as userspace.) There are a few fixes from this mailing list and some of my own; the end result is too ugly to include, and there are still things I don't understand at all, but I hope it can be useful for some.
Below is the list of what the patch does:
- I've followed the instructions from some post on this mailing list to enable CAM support in the first place (
mantis_set_directionmove tomantis_pci.c, uncommentmantis_ca_init).- The
MANTIS_GPIF_STATUSfix from http://patchwork.linuxtv.org/patch/8776/.
Not that it seems to change a lot for me, but it makes sense.- I've fixed a ton of SMP-related bugs. Basically a lot of the members of
mantis_cawere accessed from several threads without a mutex, which is a big no-no; I've mostly changed to using atomic operations here, although I also added some locks were it made sense (e.g. when resetting the CAM). Theca_lockis replaced by a more generalint_stat_lock, which ideally is held when banging onMANTIS_INT_STAT. (I have no hardware documentation, so I'm afraid I don't really know the specifics here.)-
mantis_hif_write_wait()would never clearMANTIS_SBUF_OPDONE_BIT, leading to a lot of operations never actually waiting for the callback. I've added many such fixes, as well as debugging output when the bit is in a surprising state (e.g.,MANTIS_SBUF_OPDONE_BITset before the beginning of an operation, where it really should be cleared).- Some operations check for timeout by testing if
wait_event_timeout()return-ERESTARTSYS. However,wait_event_timeout()can can never do this; the return value for timeout is zero. I've fixed this (well, I seemingly forgot one; have to do that in the next version :-) ). Unfortunately, this make the problems in the next point a _lot_ worse, since timeouts are now actually percolated up the stack.- As others have noticed, sometimes, especially during DMA transfers, the IRQ0 flag is never properly set and thus reads never return. (The typical case for this is when we've just done a write and the en50221 thread is waiting for the CAM status word to signal
STATUSREG_DA; if this doesn't happen in a reasonable amount of time, the upstream libdvben50221.so will report errors back to mumudvb.) I have no idea why this happens more often on SMP systems than on UMP systems, but they really seem to do. I haven't found any reasonable workaround for reliable polling either, so I'm making a hack -- if there's nothing returned in two milliseconds, the read is simply assumed to have completed. This is an unfortunate hack, but in practice it's identical to the previous behavior except with a shorter timeout.- A hack to fix a mutex issue in the DVB layer;
dvb_usercopy(), which is called on all ioctls, not only copies data to and from userspace, but also takes a lock on the file descriptor, which means that only one ioctl can run at a time. This means that if one thread of mumudvb is busy trying to get, say, the SNR from the frontend (which can hang due to the issue above), the CAM thread'sioctl(fd, CA_GET_SLOT_INFO, ...)will hang, even though it doesn't need to communicate with the hardware at all. This obviously requires a better fix, but I don't know the generic DVB layer well enough to say what it is. Maybe it's some sort of remnant of from when all ioctl()s took the BKL. Note that on UMP kernels without preemption,mutex_lockis to the best of my knowledge a no-op, so these delay issues would not show up on non-SMP.- Tiny cleanups: Removed some unused mmread()s and structure members. Some debugging messages have been made more specific or clearer (e.g. reads say what address they're from, the I2C subsystem reports if there were any timeouts, the interrupt handler properly clears the RISC status word so it isn't shown as <Unknown>).
I'm still not happy with the bit-banging on the I2C interface (as opposed to dealing with it in the interrupt handler); I long suspected it for causing the IRQ0 problems, especially as they seem to have a sort-of similar issue with I2CDONE/I2CRACk never being set, but it seem the DMA transfers is really what causes it somehow, so I've left it alone.
Anyway, if there are specific pieces people want me to split out for mainline, I'd be happy to do that and add the required Signed-Off-By lines etc. Let me know.
/* Steinar */
Quoted 4 lines · Mauro Carvalho Chehab
A "conglomerate of patches" can't be applied upstream. Instead, you should be sending us a patch series, preserving the original author/signed-off-by for each one, if the patches were nod written by you, and add your
Signed-off-by: at the end of each patch.
This is true. I was, however, mainly looking for feedback -- it seems there is very little interest, though.
/* Steinar */
Signature · 1 line
Homepage: http://www.sesse.net/
Quoted 8 lines · Steinar H. Gunderson
Quoted 4 lines · Mauro Carvalho Chehab
A "conglomerate of patches" can't be applied upstream. Instead, you should be sending us a patch series, preserving the original author/signed-off-by for each one, if the patches were nod written by you, and add your
Signed-off-by: at the end of each patch.This is true. I was, however, mainly looking for feedback -- it seems there is very little interest, though.
The user base is too small to get any feedback without getting the patches into mainline. I suggest you submit the parts you'd like to use yourself. That's the only way to get them tested.
I do have two mantis cards, but I don't have any CAM and I don't have access to any DVB-C signal anymore. So that's why I didn't provide any feedback despite being historically interested in this driver.
Bjørn
Quoted 3 lines · Bjørn Mork
The user base is too small to get any feedback without getting the patches into mainline. I suggest you submit the parts you'd like to use yourself. That's the only way to get them tested.
Well, it's still pretty much blind coding... is there any hardware documentation for these boards available? (If not, how were the first free drivers coded?)
/* Steinar */
Signature · 1 line
Homepage: http://www.sesse.net/