00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifdef HAVE_CONFIG_H
00022 #include "config/config.h"
00023 #endif
00024 #include <linux/module.h>
00025 #include <linux/pci.h>
00026 #include <linux/list.h>
00027 #include <linux/ioport.h>
00028 #include <linux/irq.h>
00029 #include <linux/moduleparam.h>
00030 #include <linux/seq_file.h>
00031 #include <linux/rwsem.h>
00032 #include <linux/delay.h>
00033
00034 #ifdef RT_RTDM
00035 # include <rtdm/rtdm_driver.h>
00036 # include "most-common-rt.h"
00037 #endif
00038
00039 #include "most-constants.h"
00040 #include "most-pci.h"
00041 #include "most-base.h"
00042 #include "most-measurements.h"
00043
00054 #define DRIVER_NAME "most-pci"
00055
00059 #define PR DRIVER_NAME ": "
00060
00064 #define SCTL_MAXLOOP 10000
00065
00069 static char *version = "$Rev: 639 $";
00070
00071
00072 static u32 readreg (struct most_dev *, u32);
00073 static void writereg (struct most_dev *, u32, u32);
00074 static void changereg (struct most_dev *, u32, u32, u32);
00075 static int writereg_8104 (struct most_dev *, unsigned char *, size_t, u32);
00076 static int readreg_8104 (struct most_dev *, unsigned char *, size_t, u32);
00077 static bool get_license (struct most_dev *);
00078 static void revision (struct most_dev *);
00079 static void intset (struct most_dev *, unsigned int, unsigned int,
00080 unsigned int *);
00081 static void reset (struct most_dev *);
00082 static void intclear (struct most_dev *, unsigned int);
00083 static int features (struct most_dev *);
00084 static int dma_allocate (struct most_dev *, struct dma_buffer *);
00085 static void dma_deallocate (struct most_dev *, struct dma_buffer *);
00086
00087
00088
00092 static int disable_shared_irq = false;
00093
00094 #ifndef DOXYGEN
00095 module_param(disable_shared_irq, bool, S_IRUGO);
00096 MODULE_PARM_DESC(disable_shared_irq, "Don't support IRQ sharing if set to true (default: false)");
00097 #endif
00098
00099
00100
00104 static struct most_dev* devices[MOST_DEVICE_NUMBER];
00105
00109 static struct rw_semaphore sema = __RWSEM_INITIALIZER(sema);
00110
00114 static const struct pci_device_id ids[] = {
00115 { PCI_DEVICE(PCI_VENDOR_ID_OASIS, PCI_DEVICE_ID_OASIS_MOST_PCI_INTERFACE) },
00116 { PCI_DEVICE(0, 0) },
00117 };
00118
00122 MODULE_DEVICE_TABLE(pci, ids);
00123
00124
00125
00126
00140 static inline u32 loop_until_bit_is_clear(void __iomem *addr,
00141 u32 bitmask,
00142 bool *timeout)
00143 {
00144 volatile unsigned long count = 0;
00145 u32 val;
00146 unsigned long delay_ns = 0;
00147
00148 do {
00149 val = ioread32(addr);
00150 ndelay(delay_ns);
00151 delay_ns += MOST_DELAY_INCREMENT;
00152 } while ((val & bitmask) && (count++ < MOST_MAX_POLL));
00153
00154 if (val == MOST_MAX_POLL) {
00155 if (timeout) {
00156 *timeout = true;
00157 }
00158
00159 rtnrt_err("Busy loop timed out\n");
00160 } else if (timeout) {
00161 *timeout = false;
00162 }
00163
00164 return val;
00165 }
00166
00173 static inline u32 readreg_int(struct most_dev* dev, u32 address)
00174 {
00175 u32 val = ioread32(PCI_DEV(dev)->mem + address);
00176 pr_reg_access_debug(PR "REGREAD 0x%x=0x%x\n", address, val);
00177 return val;
00178 }
00179
00187 static inline void writereg_int(struct most_dev* dev, u32 value, u32 address)
00188 {
00189 iowrite32(value, PCI_DEV(dev)->mem + address);
00190 pr_reg_access_debug(PR "REGWRITE 0x%x=0x%x\n", address, value);
00191 }
00192
00198 static inline bool keyctrl_reset(struct most_dev *dev)
00199 {
00200 u32 val;
00201 int i = SCTL_MAXLOOP;
00202
00203 val = readreg_int(dev, MOST_PCI_DSCTRL_REG);
00204 val |= DSCTL_RST;
00205 writereg_int(dev, val, MOST_PCI_DSCTRL_REG);
00206 do {
00207 if (!(readreg_int(dev, MOST_PCI_DSCTRL_REG) & DSCTL_RST)) {
00208 break;
00209 }
00210 } while (--i);
00211
00212 if (!(readreg_int(dev, MOST_PCI_DSCTRL_REG) & DSCTL_PRE)) {
00213 rtnrt_err(PR "keyctrl_reset failed\n");
00214 return false;
00215 }
00216
00217 return true;
00218 }
00219
00226 static unsigned char dsc_shift_read_byte(struct most_dev *dev)
00227 {
00228 unsigned char data = 0x00;
00229 int i, count;
00230 u32 val;
00231
00232 for (count = 0; count < 8; count++) {
00233
00234 val = readreg_int(dev, MOST_PCI_DSCTRL_REG);
00235 val |= DSCTL_RD;
00236 writereg_int(dev, val | DSCTL_RD, MOST_PCI_DSCTRL_REG);
00237
00238
00239 i = SCTL_MAXLOOP;
00240 do {
00241 val = readreg_int(dev, MOST_PCI_DSCTRL_REG);
00242 if (!(val & DSCTL_RD)) {
00243 break;
00244 }
00245 } while(--i);
00246
00247 if (val & DSCTL_RD_VAL) {
00248 data |= (1 << count);
00249 }
00250 }
00251
00252 return data;
00253 }
00254
00262 static void dsc_shift_write_byte(struct most_dev *dev, unsigned char data)
00263 {
00264 int i, count;
00265 u32 val;
00266
00267 for (count = 0; count < 8; count++) {
00268 val = readreg_int(dev, MOST_PCI_DSCTRL_REG);
00269 if (data & (1 << count)) {
00270
00271 val |= DSCTL_WR | DSCTL_WR_VAL;
00272 } else {
00273
00274 val |= DSCTL_WR;
00275 val &= ~DSCTL_WR_VAL;
00276 }
00277 writereg_int(dev, val, MOST_PCI_DSCTRL_REG);
00278
00279
00280 i = SCTL_MAXLOOP;
00281 do {
00282 if (!(readreg_int(dev, MOST_PCI_DSCTRL_REG) & DSCTL_WR)) {
00283 break;
00284 }
00285 } while(--i);
00286 }
00287 }
00288
00294 static bool get_license(struct most_dev *dev)
00295 {
00296 unsigned short license[4];
00297 int i;
00298
00299
00300 if (!keyctrl_reset(dev)) {
00301 return false;
00302 }
00303
00304
00305 dsc_shift_write_byte(dev, 0xCC);
00306
00307
00308 dsc_shift_write_byte(dev, 0xF0);
00309
00310
00311 dsc_shift_write_byte(dev, LICENSE_ADDRESS_HW + 0x00);
00312
00313 for (i = 0; i < 4; i++) {
00314 license[i] = dsc_shift_read_byte(dev);
00315 license[i] |= dsc_shift_read_byte(dev) << 8;
00316 }
00317 rtnrt_info(PR "License: %04X-%04X-%04X-%04X\n",
00318 license[3], license[2], license[1], license[0]);
00319
00320
00321 writereg_int(dev, DSCTL_CRC_RST, MOST_PCI_DSCTRL_REG);
00322 writereg_int(dev, 0x00, MOST_PCI_DSCTRL_REG);
00323
00324
00325 if (!keyctrl_reset(dev)) {
00326 return false;
00327 }
00328
00329
00330 dsc_shift_write_byte(dev, 0x33);
00331
00332
00333 writereg_int(dev, DSCTL_CRC_EN, MOST_PCI_DSCTRL_REG);
00334
00335
00336 dev->serial_number = (u64)dsc_shift_read_byte(dev);
00337
00338 dev->serial_number |= dsc_shift_read_byte(dev) << 8;
00339
00340
00341 writereg_int(dev, license[0], MOST_PCI_LICENSE_REG);
00342
00343 writereg_int(dev, 0x00000000, MOST_PCI_LICCOMP_REG);
00344
00345
00346 dev->serial_number |= dsc_shift_read_byte(dev) << 16;
00347
00348 dev->serial_number |= (u64)dsc_shift_read_byte(dev) << 24;
00349
00350
00351 writereg_int(dev, license[1], MOST_PCI_LICENSE_REG);
00352
00353 writereg_int(dev, 0x00000000, MOST_PCI_LICCOMP_REG);
00354
00355
00356 dev->serial_number |= (u64)dsc_shift_read_byte(dev) << 32;
00357
00358 dev->serial_number |= (u64)dsc_shift_read_byte(dev) << 40;
00359
00360
00361 writereg_int(dev, license[2], MOST_PCI_LICENSE_REG);
00362
00363 writereg_int(dev, 0x00000000, MOST_PCI_LICCOMP_REG);
00364
00365
00366 dev->serial_number |= (u64)dsc_shift_read_byte(dev) << 48;
00367
00368 dev->serial_number |= (u64)dsc_shift_read_byte(dev) << 56;
00369
00370
00371 writereg_int(dev, license[3], MOST_PCI_LICENSE_REG);
00372
00373 writereg_int(dev, 0x00000000, MOST_PCI_LICCOMP_REG);
00374
00375
00376 writereg_int(dev, 0x00, MOST_PCI_DSCTRL_REG);
00377
00378 return true;
00379 }
00380
00388 static void manage_usage(struct most_dev *dev, int change)
00389 {
00390 if (change == 1) {
00391 try_module_get(THIS_MODULE);
00392 } else if (change == -1) {
00393 module_put(THIS_MODULE);
00394 } else {
00395 rtnrt_err(PR "manage_usage: change(%d) invalid\n", change);
00396 }
00397 }
00398
00404 int features(struct most_dev *dev)
00405 {
00406 u32 val;
00407 int ret = 0;
00408
00409 val = readreg_int(dev, MOST_PCI_DSCTRL_REG);
00410
00411 if (val & DSCTL_EN_ASYNC) {
00412 ret |= MOST_FEATURE_ASYNC;
00413 }
00414 if (val & DSCTL_EN_MASTER) {
00415 ret |= MOST_FEATURE_MASTER;
00416 }
00417 if (val & DSCTL_EN_SYNC) {
00418 ret |= MOST_FEATURE_SYNC;
00419 }
00420 if (val & DSCTL_EN_CTRL) {
00421 ret |= MOST_FEATURE_CTRL;
00422 }
00423
00424 return ret;
00425 }
00426
00433 static void revision(struct most_dev *dev)
00434 {
00435 u32 version_reg;
00436
00437 version_reg = readreg_int(dev, MOST_PCI_VERSION_REG);
00438
00439 PCI_DEV(dev)->fpga_revision = version_reg & 0xfff;
00440 dev->product_id = (version_reg >> 24) & 0xff;
00441
00442 PCI_DEV(dev)->fpga_features = 0;
00443 if (PCI_DEV(dev)->fpga_revision > 27) {
00444 PCI_DEV(dev)->fpga_features |= MOST_PCI_FW_NEW_PACKET_LEN_POS;
00445 }
00446 if (PCI_DEV(dev)->fpga_revision > 220) {
00447 PCI_DEV(dev)->fpga_features |= MOST_PCI_FW_FOT_STATUS;
00448 }
00449 if (PCI_DEV(dev)->fpga_revision > 227) {
00450 PCI_DEV(dev)->fpga_features |= MOST_PCI_FW_SEC_ASYNC_ADDR;
00451 }
00452 if (PCI_DEV(dev)->fpga_revision > 233) {
00453 PCI_DEV(dev)->fpga_features |= MOST_PCI_FW_RX_TX_BIG_ENABLE;
00454 }
00455
00456 rtnrt_info(PR "Product ID: %d, Revision %03d, Features: 0x%X\n",
00457 dev->product_id, PCI_DEV(dev)->fpga_revision,
00458 PCI_DEV(dev)->fpga_features);
00459 }
00460
00467 void high_driver_registered(struct most_high_driver* drv)
00468 {
00469 int i;
00470
00471
00472 for (i = 0; i < MOST_DEVICE_NUMBER; i++) {
00473 down_read(&sema);
00474 if (devices[i] != NULL) {
00475 drv->probe(devices[i]);
00476 }
00477 up_read(&sema);
00478 }
00479 }
00480
00488 void high_driver_deregistered(struct most_high_driver* drv)
00489 {
00490 int i;
00491
00492
00493 for (i = 0; i < MOST_DEVICE_NUMBER; i++) {
00494 down_read(&sema);
00495 if (devices[i] != NULL) {
00496 drv->remove(devices[i]);
00497 }
00498 up_read(&sema);
00499 }
00500 }
00501
00502
00508 void proc_show(struct seq_file *s)
00509 {
00510 int i;
00511
00512 for (i = 0; i < MOST_DEVICE_NUMBER; i++) {
00513 down_read(&sema);
00514 if (devices[i] != NULL) {
00515 struct most_dev *dev = devices[i];
00516
00517 seq_printf(s, "%d : %04X-%04X-%04X-%04X\n", dev->card_number,
00518 (unsigned int)(((dev->serial_number) >> 48) & 0xffff),
00519 (unsigned int)(((dev->serial_number) >> 32) & 0xffff),
00520 (unsigned int)(((dev->serial_number) >> 16) & 0xffff),
00521 (unsigned int)(((dev->serial_number) ) & 0xffff));
00522 }
00523 up_read(&sema);
00524 }
00525 }
00526
00532 static inline rtnrt_irqreturn_t handle_interrupt(struct most_dev *dev)
00533 {
00534 struct list_head *cursor;
00535 struct most_high_driver *high_driver;
00536 u32 intstatus, intmask;
00537 u32 intstatus_new = 0;
00538
00539 measuring_int_begin();
00540
00541
00542 intstatus = readreg_int(dev, MOST_PCI_INTSTATUS_REG) & 0xff;
00543 intmask = readreg_int(dev, MOST_PCI_INTMASK_REG) & 0xff;
00544 intstatus &= intmask;
00545 if (unlikely(!intstatus)) {
00546 measuring_int_error_sharing();
00547 return RTNRT_IRQ_NONE;
00548 }
00549
00550 pr_irq_debug(PR "int_handler, status = 0x%x, mask = 0x%x\n",
00551 intstatus, intmask);
00552
00553
00554 rtnrt_lock_get(&most_base_high_drivers_spin.lock);
00555 list_for_each(cursor, &most_base_high_drivers_spin.list) {
00556 high_driver = list_entry(cursor, struct most_high_driver, spin_list);
00557
00558 if (high_driver->int_handler && high_driver->interrupt_mask & intstatus) {
00559 high_driver->int_handler(dev, intstatus);
00560
00561
00562 intstatus_new |= high_driver->interrupt_mask & intstatus;
00563 }
00564 }
00565 rtnrt_lock_put(&most_base_high_drivers_spin.lock);
00566
00567
00568 writereg_int(dev, intstatus_new, MOST_PCI_INTSTATUS_REG);
00569
00570 measuring_int_end();
00571
00572 return RTNRT_IRQ_HANDLED;
00573 }
00574
00578 DECLARE_IRQ_PROXY(int_handler, handle_interrupt, struct most_dev);
00579
00589 static int probe(struct pci_dev *lpci_dev, const struct pci_device_id *id)
00590 {
00591 int err;
00592 struct most_dev *dev;
00593 struct list_head *cursor;
00594 struct most_high_driver *high_driver;
00595
00596
00597
00598
00599
00600
00601 if ((err = pci_enable_device(lpci_dev)) != 0) {
00602 rtnrt_err(PR "Unable to enable the PCI device\n");
00603 goto out;
00604 }
00605
00606
00607
00608
00609
00610 pci_set_master(lpci_dev);
00611
00612
00613 dev = most_dev_new();
00614 if (unlikely(!dev)) {
00615 rtnrt_warn(PR "Allocation of private data structure failed\n");
00616 err = -ENOMEM;
00617 goto out_disable_dev;
00618 }
00619
00620
00621 if (MOST_DEV_CARDNUMBER(dev) >= MOST_DEVICE_NUMBER) {
00622 rtnrt_warn(PR "This would be the %dth device, but only %d "
00623 "devices are supported\n",
00624 MOST_DEV_CARDNUMBER(dev), MOST_DEVICE_NUMBER);
00625 goto out_driver_structure;
00626 }
00627
00628
00629 err = pci_request_regions(lpci_dev, dev->name);
00630 if (unlikely(err != 0)) {
00631 rtnrt_warn(PR "Could not allocate PCI regions.\n");
00632 goto out_driver_structure;
00633 }
00634
00635
00636 dev->impl = (void *)kmalloc(sizeof(struct most_pci_device), GFP_KERNEL);
00637 if (unlikely(!dev->impl)) {
00638 rtnrt_warn(PR "Allocation of most_pci_device failed\n");
00639 err = -ENOMEM;
00640 goto out_region;
00641 }
00642 memset(PCI_DEV(dev), 0, sizeof(struct most_pci_device));
00643
00644
00645 dev->manage_usage = manage_usage;
00646 dev->ops.readreg = readreg;
00647 dev->ops.writereg = writereg;
00648 dev->ops.changereg = changereg;
00649 dev->ops.readreg8104 = readreg_8104;
00650 dev->ops.writereg8104 = writereg_8104;
00651 dev->ops.intset = intset;
00652 dev->ops.reset = reset;
00653 dev->ops.intclear = intclear;
00654 dev->ops.features = features;
00655 dev->ops.dma_allocate = dma_allocate;
00656 dev->ops.dma_deallocate = dma_deallocate;
00657 #ifdef RT_RTDM
00658 dev->rt_ops.readreg = readreg;
00659 dev->rt_ops.writereg = writereg;
00660 #endif
00661
00662
00663 err = pci_read_config_byte(lpci_dev, PCI_INTERRUPT_LINE,
00664 &PCI_DEV(dev)->interrupt_line);
00665 if (unlikely((err != 0) || (PCI_DEV(dev)->interrupt_line == 0))) {
00666 rtnrt_warn(PR "Card has no interrupt line assigned\n");
00667 goto out_region;
00668 }
00669
00670
00671 err = rtnrt_register_interrupt_handler(&PCI_DEV(dev)->rt_irq_handle,
00672 PCI_DEV(dev)->interrupt_line, int_handler,
00673 (disable_shared_irq ? 0 : SA_SHIRQ), dev->name, dev);
00674
00675 if (unlikely(err != 0)) {
00676 rtnrt_warn(PR "Interrupt line %d could not be assigned "
00677 "(error code = %d)\n", PCI_DEV(dev)->interrupt_line, err);
00678 goto out_region;
00679 }
00680
00681
00682 err = rtnrt_irq_enable(&PCI_DEV(dev)->rt_irq_handle);
00683 if (unlikely(err != 0)) {
00684 rtnrt_warn(PR "Could not enable real-time PCI interrupts");
00685 goto out_irq;
00686 }
00687
00688
00689 PCI_DEV(dev)->mem = pci_iomap(lpci_dev, 0, 0);
00690 if (unlikely(! PCI_DEV(dev)->mem)) {
00691 rtnrt_warn(PR "Mapping of I/O memory to virtual address failed\n");
00692 err = -ENOMEM;
00693 goto out_irq;
00694 }
00695
00696
00697 if (!get_license(dev)) {
00698 printk(KERN_WARNING PR "get_license failed\n");
00699 err = -ENODEV;
00700 goto out_irq;
00701 }
00702 revision(dev);
00703
00704
00705 most_intset(dev, 0, 0x1ff, NULL);
00706
00707 rtnrt_info(PR "Serial Number: %04X-%04X-%04X-%04X\n",
00708 (unsigned int)(((dev->serial_number) >> 48) & 0xffff),
00709 (unsigned int)(((dev->serial_number) >> 32) & 0xffff),
00710 (unsigned int)(((dev->serial_number) >> 16) & 0xffff),
00711 (unsigned int)(((dev->serial_number) ) & 0xffff));
00712
00713
00714
00715
00716
00717
00718 down_write(&sema);
00719 devices[MOST_DEV_CARDNUMBER(dev)] = dev;
00720 up_write(&sema);
00721 pci_set_drvdata(lpci_dev, dev);
00722
00723
00724 PCI_DEV(dev)->lpci_dev = lpci_dev;
00725
00726
00727 down_read(&most_base_high_drivers_sema.lock);
00728 list_for_each(cursor, &most_base_high_drivers_sema.list) {
00729 high_driver = list_entry(cursor, struct most_high_driver, sema_list);
00730 high_driver->probe(dev);
00731 }
00732 up_read(&most_base_high_drivers_sema.lock);
00733
00734 rtnrt_info("MOST PCI (device %d) card found and enabled\n", dev->card_number);
00735
00736 return 0;
00737
00738 out_irq:
00739 rtnrt_free_interrupt_handler(&PCI_DEV(dev)->rt_irq_handle,
00740 PCI_DEV(dev)->interrupt_line, dev);
00741 out_region:
00742 pci_release_regions(lpci_dev);
00743 out_driver_structure:
00744 most_dev_free(dev);
00745 out_disable_dev:
00746 pci_disable_device(lpci_dev);
00747 out:
00748
00749 return err;
00750 }
00751
00752
00761 static void remove(struct pci_dev *lpci_dev)
00762 {
00763 struct list_head *cursor;
00764 struct most_high_driver *high_driver;
00765 struct most_dev *dev;
00766
00767
00768 dev = (struct most_dev *)pci_get_drvdata(lpci_dev);
00769 BUG_ON(!dev);
00770
00771
00772 rtnrt_free_interrupt_handler(&PCI_DEV(dev)->rt_irq_handle,
00773 PCI_DEV(dev)->interrupt_line, dev);
00774
00775
00776 down_read(&most_base_high_drivers_sema.lock);
00777 list_for_each(cursor, &most_base_high_drivers_sema.list) {
00778 high_driver = list_entry(cursor, struct most_high_driver, sema_list);
00779 high_driver->remove(dev);
00780 }
00781 up_read(&most_base_high_drivers_sema.lock);
00782
00783
00784 pci_iounmap(PCI_DEV(dev)->lpci_dev, PCI_DEV(dev)->mem);
00785
00786
00787 pci_release_regions(PCI_DEV(dev)->lpci_dev);
00788
00789
00790 pci_disable_device(PCI_DEV(dev)->lpci_dev);
00791
00792
00793 down_write(&sema);
00794 devices[MOST_DEV_CARDNUMBER(dev)] = NULL;
00795 up_write(&sema);
00796 pci_set_drvdata(lpci_dev, NULL);
00797
00798 rtnrt_info("PCI card removed (device %d)\n", dev->card_number);
00799
00800
00801 most_dev_free(dev);
00802 }
00803
00811 static u32 readreg(struct most_dev* dev, u32 address)
00812 {
00813 return readreg_int(dev, address);
00814 }
00815
00823 static void writereg(struct most_dev* dev, u32 value, u32 address)
00824 {
00825 writereg_int(dev, value, address);
00826 }
00827
00836 static void changereg(struct most_dev *dev, u32 address, u32 value, u32 mask)
00837 {
00838 unsigned long flags;
00839 u32 val;
00840
00841 spin_lock_irqsave(&dev->lock, flags);
00842
00843 val = readreg_int(dev, address);
00844 val = (val & ~mask) | value;
00845 writereg_int(dev, val, address);
00846 spin_unlock_irqrestore(&dev->lock, flags);
00847 }
00848
00856 static inline void write_map_8104(struct most_dev *dev,
00857 unsigned char map)
00858 {
00859 int val;
00860
00861
00862
00863
00864
00865
00866
00867
00868 val = loop_until_bit_is_clear(PCI_DEV(dev)->mem + MOST_PCI_CMD_REG,
00869 EXEC, NULL);
00870
00871 val = map | EXEC;
00872
00873 writereg_int(dev, val, MOST_PCI_CMD_REG);
00874
00875 pr_devfunc_debug("Write MAP 0x%x\n", map);
00876 }
00877
00885 static inline void write_data_8104(struct most_dev* dev, unsigned char data)
00886 {
00887 u32 val;
00888
00889
00890
00891
00892
00893
00894
00895
00896 val = loop_until_bit_is_clear(PCI_DEV(dev)->mem + MOST_PCI_CMD_REG,
00897 EXEC, NULL);
00898
00899 val = CPOP1 | data | EXEC;
00900
00901 writereg_int(dev, val, MOST_PCI_CMD_REG);
00902
00903 pr_devfunc_debug("Write data 0x%x\n", data);
00904 }
00905
00912 static inline unsigned char read_data_8104(struct most_dev* dev)
00913 {
00914 u32 val;
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924 val = loop_until_bit_is_clear(PCI_DEV(dev)->mem + MOST_PCI_CMD_REG,
00925 EXEC, NULL);
00926
00927 val = CPOP1 | CPOP0 | EXEC;
00928 writereg_int(dev, val, MOST_PCI_CMD_REG);
00929
00930 val = 0;
00931 val = loop_until_bit_is_clear(PCI_DEV(dev)->mem + MOST_PCI_CMD_REG,
00932 EXEC, NULL);
00933
00934 val &= VALUE_DATA;
00935
00936 pr_devfunc_debug("read data 0x%x\n", val);
00937
00938 return val;
00939 }
00940
00953 static int readreg_8104(struct most_dev *dev,
00954 unsigned char *dest,
00955 size_t len,
00956 u32 addr)
00957 {
00958 unsigned long flags;
00959 unsigned char page = (addr >> 8) & 0x03;
00960 unsigned char address = addr & 0xff;
00961 int read = 0;
00962
00963 spin_lock_irqsave(&dev->lock, flags);
00964
00965 if (page != PCI_DEV(dev)->page) {
00966 write_map_8104(dev, MOST_IF_PAGE);
00967 write_data_8104(dev, page);
00968 PCI_DEV(dev)->page = page;
00969 }
00970
00971 write_map_8104(dev, address);
00972
00973 do {
00974 *dest++ = read_data_8104(dev);
00975 read++;
00976 } while (--len > 0);
00977
00978 spin_unlock_irqrestore(&dev->lock, flags);
00979
00980 return read;
00981 }
00982
00995 static int writereg_8104(struct most_dev *dev,
00996 unsigned char *src,
00997 size_t len,
00998 u32 addr)
00999 {
01000 unsigned long flags;
01001 unsigned char page = (addr >> 8) & 0x03;
01002 unsigned char address = addr & 0xff;
01003 int written = 0;
01004
01005 spin_lock_irqsave(&dev->lock, flags);
01006
01007 if (page != PCI_DEV(dev)->page) {
01008 write_map_8104(dev, MOST_IF_PAGE);
01009 write_data_8104(dev, page);
01010 PCI_DEV(dev)->page = page;
01011 }
01012
01013 write_map_8104(dev, address);
01014
01015 do {
01016 write_data_8104(dev, *src++);
01017 written++;
01018 } while (--len > 0);
01019
01020 spin_unlock_irqrestore(&dev->lock, flags);
01021
01022 return written;
01023 }
01024
01035 static void intset(struct most_dev *dev,
01036 unsigned int interrupts,
01037 unsigned int mask,
01038 unsigned int *oldmask)
01039 {
01040 unsigned long flags;
01041 u32 val;
01042
01043 spin_lock_irqsave(&dev->lock, flags);
01044
01045
01046 val = readreg_int(dev, MOST_PCI_INTMASK_REG);
01047
01048
01049 if (oldmask) {
01050 *oldmask = val;
01051 }
01052
01053
01054 val = (val & ~mask) | interrupts;
01055 writereg_int(dev, val, MOST_PCI_INTMASK_REG);
01056
01057 pr_irq_debug(PR "intset, interrupts = 0x%x, mask = 0x%x => 0x%x\n",
01058 interrupts, mask, val);
01059
01060 spin_unlock_irqrestore(&dev->lock, flags);
01061 }
01062
01069 static void intclear(struct most_dev *dev, unsigned int interrupts)
01070 {
01071 writereg_int(dev, interrupts, MOST_PCI_INTSTATUS_REG);
01072 }
01073
01079 static void reset(struct most_dev *dev)
01080 {
01081 unsigned long flags;
01082 u32 tmp;
01083
01084 spin_lock_irqsave(&dev->lock, flags);
01085
01086
01087 tmp = loop_until_bit_is_clear(PCI_DEV(dev)->mem + MOST_PCI_CMD_REG, EXEC,
01088 NULL);
01089
01090
01091 writereg_int(dev, MRST, MOST_PCI_CMD_REG);
01092 spin_unlock_irqrestore(&dev->lock, flags);
01093 }
01094
01102 static int dma_allocate(struct most_dev *dev,
01103 struct dma_buffer *dma)
01104 {
01105 dma->addr_virt = dma_alloc_coherent(&PCI_DEV(dev)->lpci_dev->dev,
01106 dma->size, &dma->addr_bus, GFP_KERNEL);
01107 pr_reg_access_debug(PR "Allocating %d bytes of DMA memory\n",
01108 dma->size);
01109 if (!dma->addr_virt) {
01110 rtnrt_err(PR "Allocating of DMA memory failed\n");
01111 return -ENOMEM;
01112 }
01113
01114 return 0;
01115 }
01116
01117
01125 static void dma_deallocate(struct most_dev *dev,
01126 struct dma_buffer *dma)
01127 {
01128 pr_reg_access_debug(PR "Deallocating %d bytes of DMA memory\n",
01129 dma->size);
01130 dma_free_coherent(&PCI_DEV(dev)->lpci_dev->dev, dma->size, dma->addr_virt,
01131 dma->addr_bus);
01132 }
01133
01138 static struct pci_driver pci_driver = {
01139 .name = DRIVER_NAME,
01140 .id_table = ids,
01141 .probe = probe,
01142 .remove = remove
01143 };
01144
01148 static struct most_low_driver low_driver = {
01149 .name = "most-pci",
01150 .list = LIST_HEAD_INIT(low_driver.list),
01151 .high_driver_registered = high_driver_registered,
01152 .high_driver_deregistered = high_driver_deregistered,
01153 .proc_show = proc_show
01154 };
01155
01161 static int __init most_pci_init(void)
01162 {
01163 rtnrt_info("Loading module %s, version %s\n", DRIVER_NAME, version);
01164 most_register_low_driver(&low_driver);
01165
01166 return pci_register_driver(&pci_driver);
01167 }
01168
01172 static void __exit most_pci_exit(void)
01173 {
01174 rtnrt_info("Unloading module %s, version %s\n", DRIVER_NAME, version);
01175
01176 most_deregister_low_driver(&low_driver);
01177 pci_unregister_driver(&pci_driver);
01178 }
01179
01180 #ifndef DOXYGEN
01181 MODULE_LICENSE("GPL");
01182 MODULE_AUTHOR("Bernhard Walle");
01183 MODULE_VERSION("$Rev: 639 $");
01184 MODULE_DESCRIPTION("Base driver for the MOST PCI card from OASIS Silicon "
01185 "systems.");
01186 module_init(most_pci_init);
01187 module_exit(most_pci_exit);
01188 #endif
01189
01190