firedtv-iso.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * FireSAT DVB driver
  3. *
  4. * Copyright (C) 2008 Henrik Kurelid <henrik@kurelid.se>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of
  9. * the License, or (at your option) any later version.
  10. */
  11. #include <linux/errno.h>
  12. #include <linux/kernel.h>
  13. #include <linux/list.h>
  14. #include <linux/spinlock.h>
  15. #include <dvb_demux.h>
  16. #include <dma.h>
  17. #include <iso.h>
  18. #include <nodemgr.h>
  19. #include "firedtv.h"
  20. static void rawiso_activity_cb(struct hpsb_iso *iso);
  21. void tear_down_iso_channel(struct firedtv *fdtv)
  22. {
  23. if (fdtv->iso_handle != NULL) {
  24. hpsb_iso_stop(fdtv->iso_handle);
  25. hpsb_iso_shutdown(fdtv->iso_handle);
  26. }
  27. fdtv->iso_handle = NULL;
  28. }
  29. int setup_iso_channel(struct firedtv *fdtv)
  30. {
  31. int result;
  32. fdtv->iso_handle =
  33. hpsb_iso_recv_init(fdtv->ud->ne->host,
  34. 256 * 200, //data_buf_size,
  35. 256, //buf_packets,
  36. fdtv->isochannel,
  37. HPSB_ISO_DMA_DEFAULT, //dma_mode,
  38. -1, //stat.config.irq_interval,
  39. rawiso_activity_cb);
  40. if (fdtv->iso_handle == NULL) {
  41. printk(KERN_ERR "Cannot initialize iso receive.\n");
  42. return -EINVAL;
  43. }
  44. result = hpsb_iso_recv_start(fdtv->iso_handle, -1, -1, 0);
  45. if (result != 0) {
  46. printk(KERN_ERR "Cannot start iso receive.\n");
  47. return -EINVAL;
  48. }
  49. return 0;
  50. }
  51. static void rawiso_activity_cb(struct hpsb_iso *iso)
  52. {
  53. unsigned int num;
  54. unsigned int i;
  55. unsigned int packet;
  56. unsigned long flags;
  57. struct firedtv *fdtv = NULL;
  58. struct firedtv *fdtv_iterator;
  59. spin_lock_irqsave(&fdtv_list_lock, flags);
  60. list_for_each_entry(fdtv_iterator, &fdtv_list, list) {
  61. if(fdtv_iterator->iso_handle == iso) {
  62. fdtv = fdtv_iterator;
  63. break;
  64. }
  65. }
  66. spin_unlock_irqrestore(&fdtv_list_lock, flags);
  67. if (fdtv) {
  68. packet = iso->first_packet;
  69. num = hpsb_iso_n_ready(iso);
  70. for (i = 0; i < num; i++,
  71. packet = (packet + 1) % iso->buf_packets) {
  72. unsigned char *buf =
  73. dma_region_i(&iso->data_buf, unsigned char,
  74. iso->infos[packet].offset +
  75. sizeof(struct CIPHeader));
  76. int count = (iso->infos[packet].len -
  77. sizeof(struct CIPHeader)) /
  78. (188 + sizeof(struct firewireheader));
  79. if (iso->infos[packet].len <= sizeof(struct CIPHeader))
  80. continue; // ignore empty packet
  81. while (count --) {
  82. if (buf[sizeof(struct firewireheader)] == 0x47)
  83. dvb_dmx_swfilter_packets(&fdtv->demux,
  84. &buf[sizeof(struct firewireheader)], 1);
  85. else
  86. printk("%s: invalid packet, skipping\n", __func__);
  87. buf += 188 + sizeof(struct firewireheader);
  88. }
  89. }
  90. hpsb_iso_recv_release_packets(iso, num);
  91. }
  92. else {
  93. printk("%s: packets for unknown iso channel, skipping\n",
  94. __func__);
  95. hpsb_iso_recv_release_packets(iso, hpsb_iso_n_ready(iso));
  96. }
  97. }