2 * dvb_ca.c: generic DVB functions for EN50221 CAM interfaces
4 * Copyright (C) 2004 Andrew de Quincey
6 * Parts of this file were based on sources as follows:
8 * Copyright (C) 2003 Ralph Metzler <rjkm@metzlerbros.de>
12 * Copyright (C) 1999-2002 Ralph Metzler
13 * & Marcus Metzler for convergence integrated media GmbH
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
31 #include <linux/errno.h>
32 #include <linux/slab.h>
33 #include <linux/list.h>
34 #include <linux/module.h>
35 #include <linux/vmalloc.h>
36 #include <linux/delay.h>
37 #include <asm/semaphore.h>
38 #include <asm/atomic.h>
40 #include "dvb_ca_en50221.h"
41 #include "dvb_functions.h"
42 #include "dvb_ringbuffer.h"
44 static int dvb_ca_en50221_debug = 0;
45 #define dprintk if (dvb_ca_en50221_debug) printk
47 #define INIT_TIMEOUT_SECS 5
49 #define HOST_LINK_BUF_SIZE 0x200
51 #define RX_BUFFER_SIZE 65535
53 #define MAX_RX_PACKETS_PER_ITERATION 10
56 #define CTRLIF_COMMAND 1
57 #define CTRLIF_STATUS 1
58 #define CTRLIF_SIZE_LOW 2
59 #define CTRLIF_SIZE_HIGH 3
61 #define CMDREG_HC 1 /* Host control */
62 #define CMDREG_SW 2 /* Size write */
63 #define CMDREG_SR 4 /* Size read */
64 #define CMDREG_RS 8 /* Reset interface */
65 #define CMDREG_FRIE 0x40 /* Enable FR interrupt */
66 #define CMDREG_DAIE 0x80 /* Enable DA interrupt */
67 #define IRQEN (CMDREG_DAIE)
69 #define STATUSREG_RE 1 /* read error */
70 #define STATUSREG_WE 2 /* write error */
71 #define STATUSREG_FR 0x40 /* module free */
72 #define STATUSREG_DA 0x80 /* data available */
73 #define STATUSREG_TXERR (STATUSREG_RE|STATUSREG_WE) /* general transfer error */
76 #define DVB_CA_SLOTSTATE_NONE 0
77 #define DVB_CA_SLOTSTATE_UNINITIALISED 1
78 #define DVB_CA_SLOTSTATE_RUNNING 2
79 #define DVB_CA_SLOTSTATE_INVALID 3
80 #define DVB_CA_SLOTSTATE_WAITREADY 4
81 #define DVB_CA_SLOTSTATE_VALIDATE 5
82 #define DVB_CA_SLOTSTATE_WAITFR 6
83 #define DVB_CA_SLOTSTATE_LINKINIT 7
86 /* Information on a CA slot */
89 /* current state of the CAM */
92 /* Number of CAMCHANGES that have occurred since last processing */
93 atomic_t camchange_count;
95 /* Type of last CAMCHANGE */
98 /* base address of CAM config */
101 /* value to write into Config Control register */
104 /* if 1, the CAM supports DA IRQs */
105 u8 da_irq_supported:1;
107 /* size of the buffer to use when talking to the CAM */
110 /* semaphore for syncing access to slot structure */
111 struct semaphore sem;
113 /* buffer for incoming packets */
114 struct dvb_ringbuffer rx_buffer;
116 /* timer used during various states of the slot */
117 unsigned long timeout;
120 /* Private CA-interface information */
121 struct dvb_ca_private {
123 /* pointer back to the public data structure */
124 struct dvb_ca_en50221* pub;
127 struct dvb_device *dvbdev;
129 /* Flags describing the interface (DVB_CA_FLAG_*) */
132 /* number of slots supported by this CA interface */
133 unsigned int slot_count;
135 /* information on each slot */
136 struct dvb_ca_slot* slot_info;
138 /* wait queues for read() and write() operations */
139 wait_queue_head_t wait_queue;
141 /* PID of the monitoring thread */
144 /* Wait queue used when shutting thread down */
145 wait_queue_head_t thread_queue;
147 /* Flag indicating when thread should exit */
150 /* Flag indicating if the CA device is open */
153 /* Flag indicating the thread should wake up now */
156 /* Delay the main thread should use */
159 /* Slot to start looking for data to read from in the next user-space read operation */
163 static void dvb_ca_en50221_thread_wakeup(struct dvb_ca_private* ca);
164 static int dvb_ca_en50221_read_data(struct dvb_ca_private* ca, int slot, u8* ebuf, int ecount);
165 static int dvb_ca_en50221_write_data(struct dvb_ca_private* ca, int slot, u8* ebuf, int ecount);
169 * Safely find needle in haystack.
171 * @param haystack Buffer to look in.
172 * @param hlen Number of bytes in haystack.
173 * @param needle Buffer to find.
174 * @param nlen Number of bytes in needle.
175 * @return Pointer into haystack needle was found at, or NULL if not found.
177 static u8* findstr(u8* haystack, int hlen, u8* needle, int nlen)
181 if (hlen < nlen) return NULL;
183 for(i=0; i<= hlen - nlen; i++) {
184 if (!strncmp(haystack+i, needle, nlen)) return haystack+i;
192 /* ******************************************************************************** */
193 /* EN50221 physical interface functions */
199 static int dvb_ca_en50221_check_camstatus(struct dvb_ca_private* ca, int slot)
207 if (ca->flags & DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE) {
208 return (atomic_read(&ca->slot_info[slot].camchange_count) != 0);
212 if ((status = down_interruptible(&ca->slot_info[slot].sem)) != 0) return status;
213 slot_status = ca->pub->poll_slot_status(ca->pub, slot);
214 up(&ca->slot_info[slot].sem);
216 cam_present_now = (slot_status & DVB_CA_EN50221_POLL_CAM_PRESENT) ? 1: 0;
217 cam_changed = (slot_status & DVB_CA_EN50221_POLL_CAM_CHANGED) ? 1: 0;
219 int cam_present_old = (ca->slot_info[slot].slot_state != DVB_CA_SLOTSTATE_NONE);
220 cam_changed = (cam_present_now != cam_present_old);
224 if (!cam_present_now) {
225 ca->slot_info[slot].camchange_type = DVB_CA_EN50221_CAMCHANGE_REMOVED;
227 ca->slot_info[slot].camchange_type = DVB_CA_EN50221_CAMCHANGE_INSERTED;
229 atomic_set(&ca->slot_info[slot].camchange_count, 1);
231 if ((ca->slot_info[slot].slot_state == DVB_CA_SLOTSTATE_WAITREADY) &&
232 (slot_status & DVB_CA_EN50221_POLL_CAM_READY)) {
233 // move to validate state if reset is completed
234 ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_VALIDATE;
243 * Wait for flags to become set on the STATUS register on a CAM interface,
244 * checking for errors and timeout.
246 * @param ca CA instance.
247 * @param slot Slot on interface.
248 * @param waitfor Flags to wait for.
249 * @param timeout_ms Timeout in milliseconds.
251 * @return 0 on success, nonzero on error.
253 static int dvb_ca_en50221_wait_if_status(struct dvb_ca_private* ca, int slot, u8 waitfor, int timeout_hz)
255 unsigned long timeout;
258 dprintk ("%s\n", __FUNCTION__);
260 /* loop until timeout elapsed */
262 timeout = jiffies + timeout_hz;
264 /* read the status and check for error */
265 int res = ca->pub->read_cam_control(ca->pub, slot, CTRLIF_STATUS);
266 if (res < 0) return -EIO;
268 /* if we got the flags, it was successful! */
270 dprintk("%s succeeded timeout:%lu\n", __FUNCTION__, jiffies - start);
274 /* check for timeout */
275 if (time_after(jiffies, timeout)) {
283 dprintk("%s failed timeout:%lu\n", __FUNCTION__, jiffies - start);
285 /* if we get here, we've timed out */
291 * Initialise the link layer connection to a CAM.
293 * @param ca CA instance.
294 * @param slot Slot id.
296 * @return 0 on success, nonzero on failure.
298 static int dvb_ca_en50221_link_init(struct dvb_ca_private* ca, int slot)
304 dprintk ("%s\n", __FUNCTION__);
306 /* we'll be determining these during this function */
307 ca->slot_info[slot].da_irq_supported = 0;
309 /* reset the link interface. Note CAM IRQs are disabled */
310 if ((ret = ca->pub->write_cam_control(ca->pub, slot, CTRLIF_COMMAND, CMDREG_RS)) != 0) return ret;
311 if ((ret = dvb_ca_en50221_wait_if_status(ca, slot, STATUSREG_FR, HZ/10)) != 0) return ret;
313 /* set the host link buffer size temporarily. it will be overwritten with the
314 * real negotiated size later. */
315 ca->slot_info[slot].link_buf_size = 2;
317 /* read the buffer size from the CAM */
318 if ((ret = ca->pub->write_cam_control(ca->pub, slot, CTRLIF_COMMAND, IRQEN | CMDREG_SR)) != 0) return ret;
319 if ((ret = dvb_ca_en50221_wait_if_status(ca, slot, STATUSREG_DA, HZ/10)) != 0) return ret;
320 if ((ret = dvb_ca_en50221_read_data(ca, slot, buf, 2)) != 2) return -EIO;
321 if ((ret = ca->pub->write_cam_control(ca->pub, slot, CTRLIF_COMMAND, IRQEN)) != 0) return ret;
323 /* store it, and choose the minimum of our buffer and the CAM's buffer size */
324 buf_size = (buf[0] << 8) | buf[1];
325 if (buf_size > HOST_LINK_BUF_SIZE) buf_size = HOST_LINK_BUF_SIZE;
326 ca->slot_info[slot].link_buf_size = buf_size;
327 buf[0] = buf_size >> 8;
328 buf[1] = buf_size & 0xff;
329 dprintk("Chosen link buffer size of %i\n", buf_size);
331 /* write the buffer size to the CAM */
332 if ((ret = ca->pub->write_cam_control(ca->pub, slot, CTRLIF_COMMAND, IRQEN | CMDREG_SW)) != 0) return ret;
333 if ((ret = dvb_ca_en50221_wait_if_status(ca, slot, STATUSREG_FR, HZ/10)) != 0) return ret;
334 if ((ret = dvb_ca_en50221_write_data(ca, slot, buf, 2)) != 2) return -EIO;
335 if ((ret = ca->pub->write_cam_control(ca->pub, slot, CTRLIF_COMMAND, IRQEN)) != 0) return ret;
342 * Read a tuple from attribute memory.
344 * @param ca CA instance.
345 * @param slot Slot id.
346 * @param address Address to read from. Updated.
347 * @param tupleType Tuple id byte. Updated.
348 * @param tupleLength Tuple length. Updated.
349 * @param tuple Dest buffer for tuple (must be 256 bytes). Updated.
351 * @return 0 on success, nonzero on error.
353 static int dvb_ca_en50221_read_tuple(struct dvb_ca_private* ca, int slot,
354 int* address, int* tupleType, int* tupleLength, u8* tuple)
359 int _address = *address;
361 /* grab the next tuple length and type */
362 if ((_tupleType = ca->pub->read_attribute_mem(ca->pub, slot, _address)) < 0) return _tupleType;
363 if ((_tupleLength = ca->pub->read_attribute_mem(ca->pub, slot, _address+2)) < 0) return _tupleLength;
366 dprintk("TUPLE type:0x%x length:%i\n", _tupleType, _tupleLength);
368 /* read in the whole tuple */
369 for(i=0; i< _tupleLength; i++) {
370 tuple[i] = ca->pub->read_attribute_mem(ca->pub, slot, _address + (i*2));
371 dprintk(" 0x%02x: 0x%02x %c\n", i, tuple[i] & 0xff, ((tuple[i] > 31) && (tuple[i] < 127)) ? tuple[i] : '.');
373 _address += (_tupleLength*2);
376 *tupleType = _tupleType;
377 *tupleLength = _tupleLength;
384 * Parse attribute memory of a CAM module, extracting Config register, and checking
385 * it is a DVB CAM module.
387 * @param ca CA instance.
388 * @param slot Slot id.
390 * @return 0 on success, <0 on failure.
392 static int dvb_ca_en50221_parse_attributes(struct dvb_ca_private* ca, int slot)
401 int got_cftableentry = 0;
409 if ((status = dvb_ca_en50221_read_tuple(ca, slot, &address, &tupleType, &tupleLength, tuple)) < 0) return status;
410 if (tupleType != 0x1D) return -EINVAL;
415 if ((status = dvb_ca_en50221_read_tuple(ca, slot, &address, &tupleType, &tupleLength, tuple)) < 0) return status;
416 if (tupleType != 0x1C) return -EINVAL;
421 if ((status = dvb_ca_en50221_read_tuple(ca, slot, &address, &tupleType, &tupleLength, tuple)) < 0) return status;
422 if (tupleType != 0x15) return -EINVAL;
427 if ((status = dvb_ca_en50221_read_tuple(ca, slot, &address, &tupleType, &tupleLength, tuple)) < 0) return status;
428 if (tupleType != 0x20) return -EINVAL;
429 if (tupleLength != 4) return -EINVAL;
430 manfid = (tuple[1] << 8) | tuple[0];
431 devid = (tuple[3] << 8) | tuple[2];
436 if ((status = dvb_ca_en50221_read_tuple(ca, slot, &address, &tupleType, &tupleLength, tuple)) < 0) return status;
437 if (tupleType != 0x1A) return -EINVAL;
438 if (tupleLength < 3) return -EINVAL;
440 /* extract the configbase */
442 if (tupleLength < (3 + rasz + 14)) return -EINVAL;
443 ca->slot_info[slot].config_base = 0;
444 for(i=0; i< rasz+1; i++) {
445 ca->slot_info[slot].config_base |= (tuple[2+i] << (8*i));
448 /* check it contains the correct DVB string */
449 dvb_str = findstr(tuple, tupleLength, "DVB_CI_V", 8);
450 if (dvb_str == NULL) return -EINVAL;
451 if (tupleLength < ((dvb_str - (char*) tuple) + 12)) return -EINVAL;
453 /* is it a version we support? */
454 if (strncmp(dvb_str + 8, "1.00", 4)) {
455 printk("dvb_ca: Unsupported DVB CAM module version %c%c%c%c\n",
456 dvb_str[8], dvb_str[9], dvb_str[10], dvb_str[11]);
460 /* process the CFTABLE_ENTRY tuples, and any after those */
461 while((!end_chain) && (address < 0x1000)) {
462 if ((status = dvb_ca_en50221_read_tuple(ca, slot, &address, &tupleType, &tupleLength, tuple)) < 0) return status;
464 case 0x1B: // CISTPL_CFTABLE_ENTRY
465 if (tupleLength < (2+11+17)) break;
467 /* if we've already parsed one, just use it */
468 if (got_cftableentry) break;
470 /* get the config option */
471 ca->slot_info[slot].config_option = tuple[0] & 0x3f;
473 /* OK, check it contains the correct strings */
474 if ((findstr(tuple, tupleLength, "DVB_HOST", 8) == NULL) ||
475 (findstr(tuple, tupleLength, "DVB_CI_MODULE", 13) == NULL)) break;
477 got_cftableentry = 1;
480 case 0x14: // CISTPL_NO_LINK
483 case 0xFF: // CISTPL_END
487 default: /* Unknown tuple type - just skip this tuple and move to the next one */
488 dprintk("dvb_ca: Skipping unknown tuple type:0x%x length:0x%x\n", tupleType, tupleLength);
493 if ((address > 0x1000) || (!got_cftableentry)) return -EINVAL;
495 dprintk("Valid DVB CAM detected MANID:%x DEVID:%x CONFIGBASE:0x%x CONFIGOPTION:0x%x\n",
497 ca->slot_info[slot].config_base,
498 ca->slot_info[slot].config_option);
506 * Set CAM's configoption correctly.
508 * @param ca CA instance.
509 * @param slot Slot containing the CAM.
511 static int dvb_ca_en50221_set_configoption(struct dvb_ca_private* ca, int slot)
515 dprintk ("%s\n", __FUNCTION__);
517 /* set the config option */
518 ca->pub->write_attribute_mem(ca->pub, slot, ca->slot_info[slot].config_base, ca->slot_info[slot].config_option);
521 configoption = ca->pub->read_attribute_mem(ca->pub, slot, ca->slot_info[slot].config_base);
522 dprintk("Set configoption 0x%x, read configoption 0x%x\n",
523 ca->slot_info[slot].config_option, configoption & 0x3f);
532 * This function talks to an EN50221 CAM control interface. It reads a buffer of
533 * data from the CAM. The data can either be stored in a supplied buffer, or
534 * automatically be added to the slot's rx_buffer.
536 * @param ca CA instance.
537 * @param slot Slot to read from.
538 * @param ebuf If non-NULL, the data will be written to this buffer. If NULL,
539 * the data will be added into the buffering system as a normal fragment.
540 * @param ecount Size of ebuf. Ignored if ebuf is NULL.
542 * @return Number of bytes read, or < 0 on error
544 static int dvb_ca_en50221_read_data(struct dvb_ca_private* ca, int slot, u8* ebuf, int ecount)
548 u8 buf[HOST_LINK_BUF_SIZE];
551 dprintk ("%s\n", __FUNCTION__);
553 /* acquire the slot */
554 if ((status = down_interruptible(&ca->slot_info[slot].sem)) != 0) return status;
556 /* check if we have space for a link buf in the rx_buffer */
558 if (dvb_ringbuffer_free(&ca->slot_info[slot].rx_buffer) <
559 (ca->slot_info[slot].link_buf_size + DVB_RINGBUFFER_PKTHDRSIZE)) {
565 /* reset the interface if there's been a tx error */
566 if ((status = ca->pub->read_cam_control(ca->pub, slot, CTRLIF_STATUS)) < 0) goto exit;
567 if (status & STATUSREG_TXERR) {
568 ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_LINKINIT;
572 if (!(status & STATUSREG_DA)) {
578 /* read the amount of data */
579 if ((status = ca->pub->read_cam_control(ca->pub, slot, CTRLIF_SIZE_HIGH)) < 0) goto exit;
580 bytes_read = status << 8;
581 if ((status = ca->pub->read_cam_control(ca->pub, slot, CTRLIF_SIZE_LOW)) < 0) goto exit;
582 bytes_read |= status;
584 /* check it will fit */
586 if (bytes_read > ca->slot_info[slot].link_buf_size) {
587 printk("dvb_ca: CAM tried to send a buffer larger than the link buffer size!\n");
588 ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_LINKINIT;
592 if (bytes_read < 2) {
593 printk("dvb_ca: CAM sent a buffer that was less than 2 bytes!\n");
594 ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_LINKINIT;
599 if (bytes_read > ecount) {
600 printk("dvb_ca: CAM tried to send a buffer larger than the ecount size!\n");
606 /* fill the buffer */
607 for(i=0; i < bytes_read; i++) {
608 /* read byte and check */
609 if ((status = ca->pub->read_cam_control(ca->pub, slot, CTRLIF_DATA)) < 0) goto exit;
611 /* OK, store it in the buffer */
615 /* check for read error (RE should now go to 0) */
616 if ((status = ca->pub->read_cam_control(ca->pub, slot, CTRLIF_STATUS)) < 0) goto exit;
617 if (status & STATUSREG_RE) {
622 /* OK, add it to the receive buffer, or copy into external buffer if supplied */
624 dvb_ringbuffer_pkt_write(&ca->slot_info[slot].rx_buffer, buf, bytes_read);
626 memcpy(ebuf, buf, bytes_read);
629 /* wake up readers when a last_fragment is received */
630 if ((buf[1] & 0x80) == 0x00) {
631 wake_up_interruptible(&ca->wait_queue);
637 up(&ca->slot_info[slot].sem);
643 * This function talks to an EN50221 CAM control interface. It writes a buffer of data
646 * @param ca CA instance.
647 * @param slot Slot to write to.
648 * @param ebuf The data in this buffer is treated as a complete link-level packet to
650 * @param count Size of ebuf.
652 * @return Number of bytes written, or < 0 on error.
654 static int dvb_ca_en50221_write_data(struct dvb_ca_private* ca, int slot, u8* buf, int bytes_write)
659 dprintk ("%s\n", __FUNCTION__);
663 if (bytes_write > ca->slot_info[slot].link_buf_size) return -EINVAL;
665 /* acquire the slot */
666 if ((status = down_interruptible(&ca->slot_info[slot].sem)) != 0) return status;
668 /* reset the interface if there's been a tx error */
669 if ((status = ca->pub->read_cam_control(ca->pub, slot, CTRLIF_STATUS)) < 0) goto exitnowrite;
670 if (status & STATUSREG_TXERR) {
671 ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_LINKINIT;
676 /* check if interface is actually waiting for us to read from it */
677 if (status & STATUSREG_DA) {
683 if ((status = ca->pub->write_cam_control(ca->pub, slot, CTRLIF_COMMAND, IRQEN | CMDREG_HC)) != 0) goto exit;
685 /* check if interface is still free */
686 if ((status = ca->pub->read_cam_control(ca->pub, slot, CTRLIF_STATUS)) < 0) goto exit;
687 if (!(status & STATUSREG_FR)) {
688 /* it wasn't free => try again later */
693 /* send the amount of data */
694 if ((status = ca->pub->write_cam_control(ca->pub, slot, CTRLIF_SIZE_HIGH, bytes_write >> 8)) != 0) goto exit;
695 if ((status = ca->pub->write_cam_control(ca->pub, slot, CTRLIF_SIZE_LOW, bytes_write & 0xff)) != 0) goto exit;
697 /* send the buffer */
698 for(i=0; i < bytes_write; i++) {
699 if ((status = ca->pub->write_cam_control(ca->pub, slot, CTRLIF_DATA, buf[i])) != 0) goto exit;
702 /* check for write error (WE should now be 0) */
703 if ((status = ca->pub->read_cam_control(ca->pub, slot, CTRLIF_STATUS)) < 0) goto exit;
704 if (status & STATUSREG_WE) {
708 status = bytes_write;
711 ca->pub->write_cam_control(ca->pub, slot, CTRLIF_COMMAND, IRQEN);
714 up(&ca->slot_info[slot].sem);
720 /* ******************************************************************************** */
721 /* EN50221 higher level functions */
725 * A CAM has been removed => shut it down.
727 * @param ca CA instance.
728 * @param slot Slot to shut down.
730 static int dvb_ca_en50221_slot_shutdown(struct dvb_ca_private* ca, int slot)
734 dprintk ("%s\n", __FUNCTION__);
736 if ((status = down_interruptible(&ca->slot_info[slot].sem)) != 0) return status;
737 ca->pub->slot_shutdown(ca->pub, slot);
738 ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_NONE;
739 if (ca->slot_info[slot].rx_buffer.data) vfree(ca->slot_info[slot].rx_buffer.data);
740 ca->slot_info[slot].rx_buffer.data = NULL;
741 up(&ca->slot_info[slot].sem);
743 /* need to wake up all processes to check if they're now
744 trying to write to a defunct CAM */
745 wake_up_interruptible(&ca->wait_queue);
747 dprintk("Slot %i shutdown\n", slot);
755 * A CAMCHANGE IRQ has occurred.
757 * @param ca CA instance.
758 * @param slot Slot concerned.
759 * @param change_type One of the DVB_CA_CAMCHANGE_* values.
761 void dvb_ca_en50221_camchange_irq(struct dvb_ca_en50221* pubca, int slot, int change_type)
763 struct dvb_ca_private* ca = (struct dvb_ca_private*) pubca->private;
765 dprintk("CAMCHANGE IRQ slot:%i change_type:%i\n", slot, change_type);
767 switch(change_type) {
768 case DVB_CA_EN50221_CAMCHANGE_REMOVED:
769 case DVB_CA_EN50221_CAMCHANGE_INSERTED:
776 ca->slot_info[slot].camchange_type = change_type;
777 atomic_inc(&ca->slot_info[slot].camchange_count);
778 dvb_ca_en50221_thread_wakeup(ca);
783 * A CAMREADY IRQ has occurred.
785 * @param ca CA instance.
786 * @param slot Slot concerned.
788 void dvb_ca_en50221_camready_irq(struct dvb_ca_en50221* pubca, int slot)
790 struct dvb_ca_private* ca = (struct dvb_ca_private*) pubca->private;
792 dprintk("CAMREADY IRQ slot:%i\n", slot);
794 if (ca->slot_info[slot].slot_state == DVB_CA_SLOTSTATE_WAITREADY) {
795 ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_VALIDATE;
796 dvb_ca_en50221_thread_wakeup(ca);
802 * An FR or DA IRQ has occurred.
804 * @param ca CA instance.
805 * @param slot Slot concerned.
807 void dvb_ca_en50221_frda_irq(struct dvb_ca_en50221* pubca, int slot)
809 struct dvb_ca_private* ca = (struct dvb_ca_private*) pubca->private;
812 dprintk("FR/DA IRQ slot:%i\n", slot);
814 switch(ca->slot_info[slot].slot_state) {
815 case DVB_CA_SLOTSTATE_LINKINIT:
816 flags = ca->pub->read_cam_control(pubca, slot, CTRLIF_STATUS);
817 if (flags & STATUSREG_DA) {
818 dprintk("CAM supports DA IRQ\n");
819 ca->slot_info[slot].da_irq_supported = 1;
823 case DVB_CA_SLOTSTATE_RUNNING:
824 flags = ca->pub->read_cam_control(pubca, slot, CTRLIF_STATUS);
825 if (flags & STATUSREG_DA) {
826 dvb_ca_en50221_thread_wakeup(ca);
834 /* ******************************************************************************** */
835 /* EN50221 thread functions */
838 * Wake up the DVB CA thread
840 * @param ca CA instance.
842 static void dvb_ca_en50221_thread_wakeup(struct dvb_ca_private* ca)
845 dprintk ("%s\n", __FUNCTION__);
849 wake_up_interruptible(&ca->thread_queue);
853 * Used by the CA thread to determine if an early wakeup is necessary
855 * @param ca CA instance.
857 static int dvb_ca_en50221_thread_should_wakeup(struct dvb_ca_private* ca)
863 if (ca->exit) return 1;
870 * Update the delay used by the thread.
872 * @param ca CA instance.
874 static void dvb_ca_en50221_thread_update_delay(struct dvb_ca_private* ca)
877 int curdelay = 100000000;
880 for(slot=0; slot < ca->slot_count; slot++) {
881 switch(ca->slot_info[slot].slot_state) {
883 case DVB_CA_SLOTSTATE_NONE:
884 case DVB_CA_SLOTSTATE_INVALID:
886 if (!(ca->flags & DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE)) {
891 case DVB_CA_SLOTSTATE_UNINITIALISED:
892 case DVB_CA_SLOTSTATE_WAITREADY:
893 case DVB_CA_SLOTSTATE_VALIDATE:
894 case DVB_CA_SLOTSTATE_WAITFR:
895 case DVB_CA_SLOTSTATE_LINKINIT:
899 case DVB_CA_SLOTSTATE_RUNNING:
901 if (!(ca->flags & DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE)) {
905 if ((!ca->slot_info[slot].da_irq_supported) ||
906 (!(ca->flags & DVB_CA_EN50221_FLAG_IRQ_DA))) {
913 if (delay < curdelay) curdelay = delay;
916 ca->delay = curdelay;
922 * Kernel thread which monitors CA slots for CAM changes, and performs data transfers.
924 static int dvb_ca_en50221_thread(void* data)
926 struct dvb_ca_private *ca = (struct dvb_ca_private*) data;
933 dprintk ("%s\n", __FUNCTION__);
935 /* setup kernel thread */
936 snprintf(name, sizeof(name), "kdvb-ca-%i:%i", ca->dvbdev->adapter->num, ca->dvbdev->id);
937 dvb_kernel_thread_setup(name);
939 /* choose the correct initial delay */
940 dvb_ca_en50221_thread_update_delay(ca);
944 /* sleep for a bit */
946 flags = wait_event_interruptible_timeout(ca->thread_queue, dvb_ca_en50221_thread_should_wakeup(ca), ca->delay);
947 if ((flags == -ERESTARTSYS) || ca->exit) {
948 /* got signal or quitting */
954 /* go through all the slots processing them */
955 for(slot=0; slot < ca->slot_count; slot++) {
957 // check the cam status + deal with CAMCHANGEs
958 while(dvb_ca_en50221_check_camstatus(ca, slot)) {
959 /* clear down an old CI slot if necessary */
960 if (ca->slot_info[slot].slot_state != DVB_CA_SLOTSTATE_NONE) dvb_ca_en50221_slot_shutdown(ca, slot);
962 /* if a CAM is NOW present, initialise it */
963 if (ca->slot_info[slot].camchange_type == DVB_CA_EN50221_CAMCHANGE_INSERTED) {
964 ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_UNINITIALISED;
967 /* we've handled one CAMCHANGE */
968 dvb_ca_en50221_thread_update_delay(ca);
969 atomic_dec(&ca->slot_info[slot].camchange_count);
973 switch(ca->slot_info[slot].slot_state) {
974 case DVB_CA_SLOTSTATE_NONE:
975 case DVB_CA_SLOTSTATE_INVALID:
979 case DVB_CA_SLOTSTATE_UNINITIALISED:
980 ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_WAITREADY;
981 ca->pub->slot_reset(ca->pub, slot);
982 ca->slot_info[slot].timeout = jiffies + (INIT_TIMEOUT_SECS * HZ);
985 case DVB_CA_SLOTSTATE_WAITREADY:
986 if (time_after(jiffies, ca->slot_info[slot].timeout)) {
987 printk("dvb_ca: PC card did not respond :(\n");
988 ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_INVALID;
989 dvb_ca_en50221_thread_update_delay(ca);
992 // no other action needed; will automatically change state when ready
995 case DVB_CA_SLOTSTATE_VALIDATE:
996 if (dvb_ca_en50221_parse_attributes(ca, slot) != 0) {
997 printk("dvb_ca: Invalid PC card inserted :(\n");
998 ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_INVALID;
999 dvb_ca_en50221_thread_update_delay(ca);
1002 if (dvb_ca_en50221_set_configoption(ca, slot) != 0) {
1003 printk("dvb_ca: Unable to initialise CAM :(\n");
1004 ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_INVALID;
1005 dvb_ca_en50221_thread_update_delay(ca);
1009 dprintk("DVB CAM validated successfully\n");
1011 ca->slot_info[slot].timeout = jiffies + (INIT_TIMEOUT_SECS * HZ);
1012 ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_WAITFR;
1016 case DVB_CA_SLOTSTATE_WAITFR:
1017 if (time_after(jiffies, ca->slot_info[slot].timeout)) {
1018 printk("dvb_ca: DVB CAM did not respond :(\n");
1019 ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_INVALID;
1020 dvb_ca_en50221_thread_update_delay(ca);
1024 flags = ca->pub->read_cam_control(ca->pub, slot, CTRLIF_STATUS);
1025 if (flags & STATUSREG_FR) {
1026 ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_LINKINIT;
1031 case DVB_CA_SLOTSTATE_LINKINIT:
1032 if (dvb_ca_en50221_link_init(ca, slot) != 0) {
1033 printk("dvb_ca: DVB CAM link initialisation failed :(\n");
1034 ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_INVALID;
1035 dvb_ca_en50221_thread_update_delay(ca);
1039 rxbuf = vmalloc(RX_BUFFER_SIZE);
1040 if (rxbuf == NULL) {
1041 printk("dvb_ca: Unable to allocate CAM rx buffer :(\n");
1042 ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_INVALID;
1043 dvb_ca_en50221_thread_update_delay(ca);
1046 dvb_ringbuffer_init(&ca->slot_info[slot].rx_buffer, rxbuf, RX_BUFFER_SIZE);
1048 ca->pub->slot_ts_enable(ca->pub, slot);
1049 ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_RUNNING;
1050 dvb_ca_en50221_thread_update_delay(ca);
1051 printk("dvb_ca: DVB CAM detected and initialised successfully\n");
1054 case DVB_CA_SLOTSTATE_RUNNING:
1055 if (!ca->open) break;
1058 while(dvb_ca_en50221_read_data(ca, slot, NULL, 0) > 0) {
1059 if (!ca->open) break;
1061 /* if a CAMCHANGE occurred at some point, do not do any more processing of this slot */
1062 if (dvb_ca_en50221_check_camstatus(ca, slot)) {
1063 // we dont want to sleep on the next iteration so we can handle the cam change
1068 /* check if we've hit our limit this time */
1069 if (++pktcount >= MAX_RX_PACKETS_PER_ITERATION) {
1070 // dont sleep; there is likely to be more data to read
1083 wake_up_interruptible (&ca->thread_queue);
1089 /* ******************************************************************************** */
1090 /* EN50221 IO interface functions */
1093 * Real ioctl implementation.
1094 * NOTE: CA_SEND_MSG/CA_GET_MSG ioctls have userspace buffers passed to them.
1096 * @param inode Inode concerned.
1097 * @param file File concerned.
1098 * @param cmd IOCTL command.
1099 * @param arg Associated argument.
1101 * @return 0 on success, <0 on error.
1103 static int dvb_ca_en50221_io_do_ioctl(struct inode *inode, struct file *file, unsigned int cmd, void *parg)
1105 struct dvb_device* dvbdev=(struct dvb_device*) file->private_data;
1106 struct dvb_ca_private* ca = (struct dvb_ca_private*) dvbdev->priv;
1110 dprintk ("%s\n", __FUNCTION__);
1114 for(slot = 0; slot < ca->slot_count; slot++) {
1115 if (ca->slot_info[slot].slot_state != DVB_CA_SLOTSTATE_NONE) {
1116 dvb_ca_en50221_slot_shutdown(ca, slot);
1117 if (ca->flags & DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE)
1118 dvb_ca_en50221_camchange_irq(ca->pub, slot, DVB_CA_EN50221_CAMCHANGE_INSERTED);
1121 ca->next_read_slot = 0;
1122 dvb_ca_en50221_thread_wakeup(ca);
1127 struct ca_caps *caps = (struct ca_caps*) parg;
1129 caps->slot_num=ca->slot_count;
1130 caps->slot_type=CA_CI_LINK;
1137 case CA_GET_SLOT_INFO:
1139 struct ca_slot_info *info=(struct ca_slot_info *)parg;
1141 if ((info->num > ca->slot_count) || (info->num < 0))
1144 info->type = CA_CI_LINK;
1146 if ((ca->slot_info[info->num].slot_state != DVB_CA_SLOTSTATE_NONE) &&
1147 (ca->slot_info[info->num].slot_state != DVB_CA_SLOTSTATE_INVALID)) {
1148 info->flags = CA_CI_MODULE_PRESENT;
1150 if (ca->slot_info[info->num].slot_state == DVB_CA_SLOTSTATE_RUNNING) {
1151 info->flags |= CA_CI_MODULE_READY;
1166 * Wrapper for ioctl implementation.
1168 * @param inode Inode concerned.
1169 * @param file File concerned.
1170 * @param cmd IOCTL command.
1171 * @param arg Associated argument.
1173 * @return 0 on success, <0 on error.
1175 static int dvb_ca_en50221_io_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
1177 return dvb_usercopy(inode, file, cmd, arg, dvb_ca_en50221_io_do_ioctl);
1182 * Implementation of write() syscall.
1184 * @param file File structure.
1185 * @param buf Source buffer.
1186 * @param count Size of source buffer.
1187 * @param ppos Position in file (ignored).
1189 * @return Number of bytes read, or <0 on error.
1191 static ssize_t dvb_ca_en50221_io_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
1193 struct dvb_device *dvbdev=(struct dvb_device *) file->private_data;
1194 struct dvb_ca_private *ca=(struct dvb_ca_private*) dvbdev->priv;
1195 u8 slot, connection_id;
1197 char fragbuf[HOST_LINK_BUF_SIZE];
1200 unsigned long timeout;
1203 dprintk ("%s\n", __FUNCTION__);
1205 /* Incoming packet has a 2 byte header. hdr[0] = slot_id, hdr[1] = connection_id */
1206 if (count < 2) return -EINVAL;
1208 /* extract slot & connection id */
1209 if (copy_from_user(&slot, buf, 1)) return -EFAULT;
1210 if (copy_from_user(&connection_id, buf+1, 1)) return -EFAULT;
1214 /* check if the slot is actually running */
1215 if (ca->slot_info[slot].slot_state != DVB_CA_SLOTSTATE_RUNNING) return -EINVAL;
1217 /* fragment the packets & store in the buffer */
1218 while(fragpos < count) {
1219 fraglen = ca->slot_info[slot].link_buf_size - 2;
1220 if ((count - fragpos) < fraglen) fraglen = count - fragpos;
1222 fragbuf[0] = connection_id;
1223 fragbuf[1] = ((fragpos + fraglen) < count) ? 0x80 : 0x00;
1224 if ((status = copy_from_user(fragbuf+2, buf+fragpos, fraglen)) != 0) goto exit;
1226 timeout = jiffies + HZ/2;
1228 while(!time_after(jiffies, timeout)) {
1229 status = dvb_ca_en50221_write_data(ca, slot, fragbuf, fraglen+2);
1230 if (status == (fraglen+2)) {
1234 if (status != -EAGAIN) goto exit;
1253 * Condition for waking up in dvb_ca_en50221_io_read_condition
1255 static int dvb_ca_en50221_io_read_condition(struct dvb_ca_private* ca, int* result, int* _slot)
1261 int connection_id = -1;
1265 slot = ca->next_read_slot;
1266 while((slot_count < ca->slot_count) && (!found)) {
1267 if (ca->slot_info[slot].slot_state != DVB_CA_SLOTSTATE_RUNNING) goto nextslot;
1269 if ((*result = down_interruptible(&ca->slot_info[slot].sem)) != 0) return 1;
1271 idx = dvb_ringbuffer_pkt_next(&ca->slot_info[slot].rx_buffer, -1, &fraglen);
1273 dvb_ringbuffer_pkt_read(&ca->slot_info[slot].rx_buffer, idx, 0, hdr, 2, 0);
1274 if (connection_id == -1) connection_id = hdr[0];
1275 if ((hdr[0] == connection_id) && ((hdr[1] & 0x80) == 0)) {
1281 idx = dvb_ringbuffer_pkt_next(&ca->slot_info[slot].rx_buffer, idx, &fraglen);
1284 if (!found) up(&ca->slot_info[slot].sem);
1287 slot = (slot + 1) % ca->slot_count;
1291 ca->next_read_slot = slot;
1297 * Implementation of read() syscall.
1299 * @param file File structure.
1300 * @param buf Destination buffer.
1301 * @param count Size of destination buffer.
1302 * @param ppos Position in file (ignored).
1304 * @return Number of bytes read, or <0 on error.
1306 static ssize_t dvb_ca_en50221_io_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
1308 struct dvb_device *dvbdev=(struct dvb_device *) file->private_data;
1309 struct dvb_ca_private *ca=(struct dvb_ca_private*) dvbdev->priv;
1314 int connection_id = -1;
1316 int last_fragment = 0;
1321 dprintk ("%s\n", __FUNCTION__);
1323 /* Outgoing packet has a 2 byte header. hdr[0] = slot_id, hdr[1] = connection_id */
1324 if (count < 2) return -EINVAL;
1326 /* wait for some data */
1327 if ((status = dvb_ca_en50221_io_read_condition(ca, &result, &slot)) == 0) {
1329 /* if we're in nonblocking mode, exit immediately */
1330 if (file->f_flags & O_NONBLOCK) return -EWOULDBLOCK;
1332 /* wait for some data */
1333 status = wait_event_interruptible(ca->wait_queue, dvb_ca_en50221_io_read_condition(ca, &result, &slot));
1335 if ((status < 0) || (result < 0)) {
1336 if (result) return result;
1340 idx = dvb_ringbuffer_pkt_next(&ca->slot_info[slot].rx_buffer, -1, &fraglen);
1344 printk("dvb_ca: BUG: read packet ended before last_fragment encountered\n");
1349 dvb_ringbuffer_pkt_read(&ca->slot_info[slot].rx_buffer, idx, 0, hdr, 2, 0);
1350 if (connection_id == -1) connection_id = hdr[0];
1351 if (hdr[0] == connection_id) {
1352 if (pktlen < count) {
1353 if ((pktlen + fraglen - 2) > count) {
1354 fraglen = count - pktlen;
1359 if ((status = dvb_ringbuffer_pkt_read(&ca->slot_info[slot].rx_buffer, idx, 2, buf + pktlen, fraglen, 1)) < 0) {
1365 if ((hdr[1] & 0x80) == 0) last_fragment = 1;
1369 idx2 = dvb_ringbuffer_pkt_next(&ca->slot_info[slot].rx_buffer, idx, &fraglen);
1370 if (dispose) dvb_ringbuffer_pkt_dispose(&ca->slot_info[slot].rx_buffer, idx);
1373 } while (!last_fragment);
1376 hdr[1] = connection_id;
1377 if ((status = copy_to_user(buf, hdr, 2)) != 0) goto exit;
1381 up(&ca->slot_info[slot].sem);
1387 * Implementation of file open syscall.
1389 * @param inode Inode concerned.
1390 * @param file File concerned.
1392 * @return 0 on success, <0 on failure.
1394 static int dvb_ca_en50221_io_open(struct inode *inode, struct file *file)
1396 struct dvb_device *dvbdev = (struct dvb_device *) file->private_data;
1397 struct dvb_ca_private *ca = (struct dvb_ca_private*) dvbdev->priv;
1401 dprintk ("%s\n", __FUNCTION__);
1403 err=dvb_generic_open(inode, file);
1407 for(i=0; i< ca->slot_count; i++) {
1408 if (ca->slot_info[i].slot_state == DVB_CA_SLOTSTATE_RUNNING) {
1409 dvb_ringbuffer_flush(&ca->slot_info[i].rx_buffer);
1414 dvb_ca_en50221_thread_update_delay(ca);
1415 dvb_ca_en50221_thread_wakeup(ca);
1422 * Implementation of file close syscall.
1424 * @param inode Inode concerned.
1425 * @param file File concerned.
1427 * @return 0 on success, <0 on failure.
1429 static int dvb_ca_en50221_io_release(struct inode *inode, struct file *file)
1431 struct dvb_device *dvbdev=(struct dvb_device *) file->private_data;
1432 struct dvb_ca_private *ca=(struct dvb_ca_private*) dvbdev->priv;
1435 dprintk ("%s\n", __FUNCTION__);
1437 /* mark the CA device as closed */
1439 dvb_ca_en50221_thread_update_delay(ca);
1441 err=dvb_generic_release(inode, file);
1449 * Implementation of poll() syscall.
1451 * @param file File concerned.
1452 * @param wait poll wait table.
1454 * @return Standard poll mask.
1456 static unsigned int dvb_ca_en50221_io_poll(struct file *file, poll_table *wait)
1458 struct dvb_device* dvbdev = (struct dvb_device*) file->private_data;
1459 struct dvb_ca_private* ca = (struct dvb_ca_private*) dvbdev->priv;
1460 unsigned int mask=0;
1464 dprintk ("%s\n", __FUNCTION__);
1466 if (dvb_ca_en50221_io_read_condition(ca, &result, &slot) == 1) {
1467 up(&ca->slot_info[slot].sem);
1471 /* if there is something, return now */
1472 if (mask) return mask;
1474 /* wait for something to happen */
1475 poll_wait(file, &ca->wait_queue, wait);
1477 if (dvb_ca_en50221_io_read_condition(ca, &result, &slot) == 1) {
1478 up(&ca->slot_info[slot].sem);
1486 static struct file_operations dvb_ca_fops = {
1488 read: dvb_ca_en50221_io_read,
1489 write: dvb_ca_en50221_io_write,
1490 ioctl: dvb_ca_en50221_io_ioctl,
1491 open: dvb_ca_en50221_io_open,
1492 release: dvb_ca_en50221_io_release,
1493 poll: dvb_ca_en50221_io_poll,
1496 static struct dvb_device dvbdev_ca = {
1505 /* ******************************************************************************** */
1506 /* Initialisation/shutdown functions */
1510 * Initialise a new DVB CA EN50221 interface device.
1512 * @param dvb_adapter DVB adapter to attach the new CA device to.
1513 * @param ca The dvb_ca instance.
1514 * @param flags Flags describing the CA device (DVB_CA_FLAG_*).
1515 * @param slot_count Number of slots supported.
1517 * @return 0 on success, nonzero on failure
1519 int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter, struct dvb_ca_en50221* pubca, int flags, int slot_count)
1522 struct dvb_ca_private* ca = NULL;
1525 dprintk ("%s\n", __FUNCTION__);
1527 if (slot_count < 1) return -EINVAL;
1529 /* initialise the system data */
1530 if ((ca = (struct dvb_ca_private*) kmalloc(sizeof(struct dvb_ca_private), GFP_KERNEL)) == NULL) {
1534 memset(ca, 0, sizeof(struct dvb_ca_private));
1537 ca->slot_count = slot_count;
1538 if ((ca->slot_info = kmalloc(sizeof(struct dvb_ca_slot) * slot_count, GFP_KERNEL)) == NULL) {
1542 memset(ca->slot_info, 0, sizeof(struct dvb_ca_slot) * slot_count);
1543 init_waitqueue_head(&ca->wait_queue);
1545 init_waitqueue_head(&ca->thread_queue);
1549 ca->next_read_slot = 0;
1550 pubca->private = ca;
1552 /* register the DVB device */
1553 ret = dvb_register_device(dvb_adapter, &ca->dvbdev, &dvbdev_ca, ca, DVB_DEVICE_CA);
1554 if (ret) goto error;
1556 /* now initialise each slot */
1557 for(i=0; i< slot_count; i++) {
1558 memset(&ca->slot_info[i], 0, sizeof(struct dvb_ca_slot));
1559 ca->slot_info[i].slot_state = DVB_CA_SLOTSTATE_NONE;
1560 atomic_set(&ca->slot_info[i].camchange_count, 0);
1561 ca->slot_info[i].camchange_type = DVB_CA_EN50221_CAMCHANGE_REMOVED;
1562 init_MUTEX(&ca->slot_info[i].sem);
1565 if (signal_pending(current)) {
1571 /* create a kthread for monitoring this CA device */
1572 ret = kernel_thread (dvb_ca_en50221_thread, ca, 0);
1574 printk("dvb_ca_init: failed to start kernel_thread (%d)\n", ret);
1577 ca->thread_pid = ret;
1582 if (ca->dvbdev != NULL) dvb_unregister_device(ca->dvbdev);
1583 if (ca->slot_info != NULL) kfree(ca->slot_info);
1586 pubca->private = NULL;
1593 * Release a DVB CA EN50221 interface device.
1595 * @param ca_dev The dvb_device_t instance for the CA device.
1596 * @param ca The associated dvb_ca instance.
1598 void dvb_ca_en50221_release(struct dvb_ca_en50221* pubca)
1600 struct dvb_ca_private* ca = (struct dvb_ca_private*) pubca->private;
1603 dprintk ("%s\n", __FUNCTION__);
1605 /* shutdown the thread if there was one */
1606 if (ca->thread_pid) {
1607 if (kill_proc(ca->thread_pid, 0, 1) == -ESRCH) {
1608 printk("dvb_ca_release: thread PID %d already died\n", ca->thread_pid);
1612 dvb_ca_en50221_thread_wakeup(ca);
1613 wait_event_interruptible(ca->thread_queue, ca->thread_pid == 0);
1617 for(i=0; i< ca->slot_count; i++) {
1618 dvb_ca_en50221_slot_shutdown(ca, i);
1620 kfree(ca->slot_info);
1621 dvb_unregister_device(ca->dvbdev);
1623 pubca->private = NULL;
1626 MODULE_PARM(dvb_ca_en50221_debug,"i");
1628 MODULE_PARM_DESC(dvb_ca_en50221_debug, "enable verbose debug messages");