/* * We have a good packet, get it out of the adapter. */ static void de600_rx_intr(struct net_device *dev) { struct sk_buff *skb; int i; int read_from; int size; unsigned char *buffer; /* Get size of received packet */ size = de600_read_byte(RX_LEN, dev); /* low byte */ size += (de600_read_byte(RX_LEN, dev) << 8); /* high byte */ size -= 4; /* Ignore trailing 4 CRC-bytes */ /* Tell adapter where to store next incoming packet, enable receiver */ read_from = rx_page_adr(); next_rx_page(); de600_put_command(RX_ENABLE); if ((size < 32) || (size > 1535)) { printk(KERN_WARNING "%s: Bogus packet size %d.\n", dev->name, size); if (size > 10000) adapter_init(dev); return; } skb = dev_alloc_skb(size+2); if (skb == NULL) { printk("%s: Couldn't allocate a sk_buff of size %d.\n", dev->name, size); return; } /* else */ skb_reserve(skb,2); /* Align */ /* 'skb->data' points to the start of sk_buff data area. */ buffer = skb_put(skb,size); /* copy the packet into the buffer */ de600_setup_address(read_from, RW_ADDR); for (i = size; i > 0; --i, ++buffer) *buffer = de600_read_byte(READ_DATA, dev); skb->protocol=eth_type_trans(skb,dev); netif_rx(skb); /* update stats */ dev->last_rx = jiffies; dev->stats.rx_packets++; /* count all receives */ dev->stats.rx_bytes += size; /* count all received bytes */ /* * If any worth-while packets have been received, netif_rx() * will work on them when we get to the tasklets. */ }
/* * We have a good packet, get it out of the adapter. */ static void de600_rx_intr(struct device *dev) { struct sk_buff *skb; int i; int read_from; int size; register unsigned char *buffer; cli(); /* Get size of received packet */ size = de600_read_byte(RX_LEN, dev); /* low byte */ size += (de600_read_byte(RX_LEN, dev) << 8); /* high byte */ size -= 4; /* Ignore trailing 4 CRC-bytes */ /* Tell adapter where to store next incoming packet, enable receiver */ read_from = rx_page_adr(); next_rx_page(); de600_put_command(RX_ENABLE); sti(); if ((size < 32) || (size > 1535)) { printk("%s: Bogus packet size %d.\n", dev->name, size); if (size > 10000) adapter_init(dev); return; } skb = alloc_skb(size, GFP_ATOMIC); sti(); if (skb == NULL) { printk("%s: Couldn't allocate a sk_buff of size %d.\n", dev->name, size); return; } /* else */ skb->lock = 0; /* 'skb->data' points to the start of sk_buff data area. */ buffer = skb->data; /* copy the packet into the buffer */ de600_setup_address(read_from, RW_ADDR); for (i = size; i > 0; --i, ++buffer) *buffer = de600_read_byte(READ_DATA, dev); ((struct netstats *)(dev->priv))->rx_packets++; /* count all receives */ if (dev_rint((unsigned char *)skb, size, IN_SKBUFF, dev)) printk("%s: receive buffers full.\n", dev->name); /* * If any worth-while packets have been received, dev_rint() * has done a mark_bh(INET_BH) for us and will work on them * when we get to the bottom-half routine. */ }
static void de600_rx_intr(struct net_device *dev) { struct sk_buff *skb; int i; int read_from; int size; unsigned char *buffer; /* */ size = de600_read_byte(RX_LEN, dev); /* */ size += (de600_read_byte(RX_LEN, dev) << 8); /* */ size -= 4; /* */ /* */ read_from = rx_page_adr(); next_rx_page(); de600_put_command(RX_ENABLE); if ((size < 32) || (size > 1535)) { printk(KERN_WARNING "%s: Bogus packet size %d.\n", dev->name, size); if (size > 10000) adapter_init(dev); return; } skb = netdev_alloc_skb(dev, size + 2); if (skb == NULL) { printk("%s: Couldn't allocate a sk_buff of size %d.\n", dev->name, size); return; } /* */ skb_reserve(skb,2); /* */ /* */ buffer = skb_put(skb,size); /* */ de600_setup_address(read_from, RW_ADDR); for (i = size; i > 0; --i, ++buffer) *buffer = de600_read_byte(READ_DATA, dev); skb->protocol=eth_type_trans(skb,dev); netif_rx(skb); /* */ dev->stats.rx_packets++; /* */ dev->stats.rx_bytes += size; /* */ /* */ }
static int de600_open(struct net_device *dev) { unsigned long flags; int ret = request_irq(DE600_IRQ, de600_interrupt, 0, dev->name, dev); if (ret) { printk(KERN_ERR "%s: unable to get IRQ %d\n", dev->name, DE600_IRQ); return ret; } spin_lock_irqsave(&de600_lock, flags); ret = adapter_init(dev); spin_unlock_irqrestore(&de600_lock, flags); return ret; }
/* * Open/initialize the board. This is called (in the current kernel) * after booting when 'ifconfig <dev->name> $IP_ADDR' is run (in rc.inet1). * * This routine should set everything up anew at each open, even * registers that "should" only need to be set once at boot, so that * there is a non-reboot way to recover if something goes wrong. */ static int de600_open(struct net_device *dev) { int ret = request_irq(DE600_IRQ, de600_interrupt, 0, dev->name, dev); if (ret) { printk ("%s: unable to get IRQ %d\n", dev->name, DE600_IRQ); return ret; } if (adapter_init(dev)) return -EIO; return 0; }
struct btd_adapter *btd_manager_register_adapter(int id, gboolean up) { struct btd_adapter *adapter; const char *path; adapter = manager_find_adapter_by_id(id); if (adapter) { error("Unable to register adapter: hci%d already exist", id); return NULL; } adapter = adapter_create(connection, id); if (!adapter) return NULL; adapters = g_slist_append(adapters, adapter); if (!adapter_init(adapter, up)) { adapters = g_slist_remove(adapters, adapter); btd_adapter_unref(adapter); return NULL; } path = adapter_get_path(adapter); g_dbus_emit_signal(connection, "/", MANAGER_INTERFACE, "AdapterAdded", DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID); manager_update_adapters(); btd_stop_exit_timer(); if (default_adapter_id < 0) manager_set_default_adapter(id); if (main_opts.did_source) btd_adapter_set_did(adapter, main_opts.did_vendor, main_opts.did_product, main_opts.did_version, main_opts.did_source); DBG("Adapter %s registered", path); return btd_adapter_ref(adapter); }
/* * Open/initialize the board. This is called (in the current kernel) * after booting when 'ifconfig <dev->name> $IP_ADDR' is run (in rc.inet1). * * This routine should set everything up anew at each open, even * registers that "should" only need to be set once at boot, so that * there is a non-reboot way to recover if something goes wrong. */ static int de600_open(struct device *dev) { if (request_irq(DE600_IRQ, de600_interrupt, 0, "de600")) { printk ("%s: unable to get IRQ %d\n", dev->name, DE600_IRQ); return 1; } irq2dev_map[DE600_IRQ] = dev; #ifdef MODULE MOD_INC_USE_COUNT; #endif dev->start = 1; if (adapter_init(dev)) { return 1; } return 0; }
static int de600_start_xmit(struct sk_buff *skb, struct net_device *dev) { unsigned long flags; int transmit_from; int len; int tickssofar; u8 *buffer = skb->data; int i; if (free_tx_pages <= 0) { /* Do timeouts, to avoid hangs. */ tickssofar = jiffies - dev->trans_start; if (tickssofar < 5) return 1; /* else */ printk(KERN_WARNING "%s: transmit timed out (%d), %s?\n", dev->name, tickssofar, "network cable problem"); /* Restart the adapter. */ spin_lock_irqsave(&de600_lock, flags); if (adapter_init(dev)) { spin_unlock_irqrestore(&de600_lock, flags); return 1; } spin_unlock_irqrestore(&de600_lock, flags); } /* Start real output */ PRINTK(("de600_start_xmit:len=%d, page %d/%d\n", skb->len, tx_fifo_in, free_tx_pages)); if ((len = skb->len) < RUNT) len = RUNT; spin_lock_irqsave(&de600_lock, flags); select_nic(); tx_fifo[tx_fifo_in] = transmit_from = tx_page_adr(tx_fifo_in) - len; tx_fifo_in = (tx_fifo_in + 1) % TX_PAGES; /* Next free tx page */ if(check_lost) { /* This costs about 40 instructions per packet... */ de600_setup_address(NODE_ADDRESS, RW_ADDR); de600_read_byte(READ_DATA, dev); if (was_down || (de600_read_byte(READ_DATA, dev) != 0xde)) { if (adapter_init(dev)) { spin_unlock_irqrestore(&de600_lock, flags); return 1; } } } de600_setup_address(transmit_from, RW_ADDR); for (i = 0; i < skb->len ; ++i, ++buffer) de600_put_byte(*buffer); for (; i < len; ++i) de600_put_byte(0); if (free_tx_pages-- == TX_PAGES) { /* No transmission going on */ dev->trans_start = jiffies; netif_start_queue(dev); /* allow more packets into adapter */ /* Send page and generate a faked interrupt */ de600_setup_address(transmit_from, TX_ADDR); de600_put_command(TX_ENABLE); } else { if (free_tx_pages) netif_start_queue(dev); else netif_stop_queue(dev); select_prn(); } spin_unlock_irqrestore(&de600_lock, flags); dev_kfree_skb(skb); return 0; }
/* * Copy a buffer to the adapter transmit page memory. * Start sending. */ static int de600_start_xmit(struct sk_buff *skb, struct net_device *dev) { unsigned long flags; int transmit_from; int len; int tickssofar; byte *buffer = skb->data; if (free_tx_pages <= 0) { /* Do timeouts, to avoid hangs. */ tickssofar = jiffies - dev->trans_start; if (tickssofar < 5) return 1; /* else */ printk("%s: transmit timed out (%d), %s?\n", dev->name, tickssofar, "network cable problem" ); /* Restart the adapter. */ if (adapter_init(dev)) { return 1; } } /* Start real output */ PRINTK(("de600_start_xmit:len=%d, page %d/%d\n", skb->len, tx_fifo_in, free_tx_pages)); if ((len = skb->len) < RUNT) len = RUNT; save_flags(flags); cli(); select_nic(); tx_fifo[tx_fifo_in] = transmit_from = tx_page_adr(tx_fifo_in) - len; tx_fifo_in = (tx_fifo_in + 1) % TX_PAGES; /* Next free tx page */ #ifdef CHECK_LOST_DE600 /* This costs about 40 instructions per packet... */ de600_setup_address(NODE_ADDRESS, RW_ADDR); de600_read_byte(READ_DATA, dev); if (was_down || (de600_read_byte(READ_DATA, dev) != 0xde)) { if (adapter_init(dev)) { restore_flags(flags); return 1; } } #endif de600_setup_address(transmit_from, RW_ADDR); for ( ; len > 0; --len, ++buffer) de600_put_byte(*buffer); if (free_tx_pages-- == TX_PAGES) { /* No transmission going on */ dev->trans_start = jiffies; netif_start_queue(dev); /* allow more packets into adapter */ /* Send page and generate a faked interrupt */ de600_setup_address(transmit_from, TX_ADDR); de600_put_command(TX_ENABLE); } else { if (free_tx_pages) netif_start_queue(dev); else netif_stop_queue(dev); select_prn(); } restore_flags(flags); #ifdef FAKE_SMALL_MAX /* This will "patch" the socket TCP proto at an early moment */ if (skb->sk && (skb->sk->protocol == IPPROTO_TCP) && (skb->sk->prot->rspace != &de600_rspace)) skb->sk->prot->rspace = de600_rspace; /* Ugh! */ #endif dev_kfree_skb (skb); return 0; }
static int de600_start_xmit(struct sk_buff *skb, struct net_device *dev) { unsigned long flags; int transmit_from; int len; int tickssofar; u8 *buffer = skb->data; int i; if (free_tx_pages <= 0) { tickssofar = jiffies - dev->trans_start; if (tickssofar < 5) return NETDEV_TX_BUSY; printk(KERN_WARNING "%s: transmit timed out (%d), %s?\n", dev->name, tickssofar, "network cable problem"); spin_lock_irqsave(&de600_lock, flags); if (adapter_init(dev)) { spin_unlock_irqrestore(&de600_lock, flags); return NETDEV_TX_BUSY; } spin_unlock_irqrestore(&de600_lock, flags); } pr_debug("de600_start_xmit:len=%d, page %d/%d\n", skb->len, tx_fifo_in, free_tx_pages); if ((len = skb->len) < RUNT) len = RUNT; spin_lock_irqsave(&de600_lock, flags); select_nic(); tx_fifo[tx_fifo_in] = transmit_from = tx_page_adr(tx_fifo_in) - len; tx_fifo_in = (tx_fifo_in + 1) % TX_PAGES; if(check_lost) { de600_setup_address(NODE_ADDRESS, RW_ADDR); de600_read_byte(READ_DATA, dev); if (was_down || (de600_read_byte(READ_DATA, dev) != 0xde)) { if (adapter_init(dev)) { spin_unlock_irqrestore(&de600_lock, flags); return NETDEV_TX_BUSY; } } } de600_setup_address(transmit_from, RW_ADDR); for (i = 0; i < skb->len ; ++i, ++buffer) de600_put_byte(*buffer); for (; i < len; ++i) de600_put_byte(0); if (free_tx_pages-- == TX_PAGES) { dev->trans_start = jiffies; netif_start_queue(dev); de600_setup_address(transmit_from, TX_ADDR); de600_put_command(TX_ENABLE); } else { if (free_tx_pages) netif_start_queue(dev); else netif_stop_queue(dev); select_prn(); } spin_unlock_irqrestore(&de600_lock, flags); dev_kfree_skb(skb); return NETDEV_TX_OK; }
static int __init mic_init(void) { int ret, i; adapter_init(); unaligned_cache = micscif_kmem_cache_create(); if (!unaligned_cache) { ret = -ENOMEM; goto init_free_ports; } mic_lindata.dd_pcidriver.name = "mic"; mic_lindata.dd_pcidriver.id_table = mic_pci_tbl; mic_lindata.dd_pcidriver.probe = mic_probe; mic_lindata.dd_pcidriver.remove = mic_remove; mic_lindata.dd_pcidriver.driver.pm = &pci_dev_pm_ops; mic_lindata.dd_pcidriver.shutdown = mic_shutdown; if ((ret = alloc_chrdev_region(&mic_lindata.dd_dev, 0, MAX_DLDR_MINORS, "mic") != 0)) { printk("Error allocating device nodes: %d\n", ret); goto init_free_ports; } cdev_init(&mic_lindata.dd_cdev, &mic_fops); mic_lindata.dd_cdev.owner = THIS_MODULE; mic_lindata.dd_cdev.ops = &mic_fops; if ((ret = cdev_add(&mic_lindata.dd_cdev, mic_lindata.dd_dev, MAX_DLDR_MINORS) != 0)) { kobject_put(&mic_lindata.dd_cdev.kobj); goto init_free_region; } mic_lindata.dd_class = class_create(THIS_MODULE, "mic"); if (IS_ERR(mic_lindata.dd_class)) { printk("MICDLDR: Error createing mic class\n"); cdev_del(&mic_lindata.dd_cdev); ret = PTR_ERR(mic_lindata.dd_class); goto init_free_region; } #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,31) mic_lindata.dd_class->devnode = mic_devnode; #endif mic_lindata.dd_hostdev = device_create(mic_lindata.dd_class, NULL, mic_lindata.dd_dev, NULL, "ctrl"); mic_lindata.dd_scifdev = device_create(mic_lindata.dd_class, NULL, mic_lindata.dd_dev + 1, NULL, "scif"); ret = sysfs_create_group(&mic_lindata.dd_hostdev->kobj, &host_attr_group); ret = sysfs_create_group(&mic_lindata.dd_scifdev->kobj, &scif_attr_group); #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,31) mic_lindata.dd_class->devnode = NULL; #endif if (micveth_init(mic_lindata.dd_hostdev)) printk(KERN_ERR "%s: micveth_init failed\n", __func__); ret = pci_register_driver(&mic_lindata.dd_pcidriver); if (ret) { micscif_destroy(); printk("mic: failed to register pci driver %d\n", ret); goto clean_unregister; } if (!mic_data.dd_numdevs) { printk("mic: No MIC boards present. SCIF available in loopback mode\n"); } else { printk("mic: number of devices detected %d \n", mic_data.dd_numdevs); } for (i = 0; i < mic_data.dd_numdevs; i++) { mic_ctx_t *mic_ctx = get_per_dev_ctx(i); wait_event(mic_ctx->ioremapwq, mic_ctx->aper.va || mic_ctx->state == MIC_RESETFAIL); destroy_workqueue(mic_ctx->ioremapworkq); } micveth_init_legacy(mic_data.dd_numdevs, mic_lindata.dd_hostdev); ret = acptboot_init(); #ifdef USE_VCONSOLE micvcons_create(mic_data.dd_numdevs); #endif /* Initialize Data structures for PM Disconnect */ ret = micpm_disconn_init(mic_data.dd_numdevs + 1); if (ret) printk(KERN_ERR "%s: Failed to initialize PM disconnect" " data structures. PM may not work as expected." " ret = %d\n", __func__, ret); register_pm_notifier(&mic_pm_notifer); #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,34)) ret = pm_qos_add_requirement(PM_QOS_CPU_DMA_LATENCY, "mic", mic_pm_qos_cpu_dma_lat); if (ret) { printk(KERN_ERR "%s %d mic_pm_qos_cpu_dma_lat %d ret %d\n", __func__, __LINE__, mic_pm_qos_cpu_dma_lat, ret); ret = 0; /* Dont fail driver load due to PM QoS API. Fall through */ } #endif return 0; clean_unregister: device_destroy(mic_lindata.dd_class, mic_lindata.dd_dev + 1); device_destroy(mic_lindata.dd_class, mic_lindata.dd_dev); class_destroy(mic_lindata.dd_class); cdev_del(&mic_lindata.dd_cdev); unregister_pm_notifier(&mic_pm_notifer); init_free_region: unregister_chrdev_region(mic_lindata.dd_dev, MAX_DLDR_MINORS); init_free_ports: micpm_uninit(); return ret; }
/* * Copy a buffer to the adapter transmit page memory. * Start sending. */ static int d_link_start_xmit(struct sk_buff *skb, struct device *dev) { int transmit_from; int len; int tickssofar; unsigned char *buffer = skb->data; /* * If some higher layer thinks we've missed a * tx-done interrupt we are passed NULL. * Caution: dev_tint() handles the cli()/sti() itself. */ if (skb == NULL) { dev_tint(dev); return 0; } /* For ethernet, fill in the header (hardware addresses) with an arp. */ if (!skb->arp) if(dev->rebuild_header(skb->data, dev)) { skb->dev = dev; arp_queue (skb); return 0; } skb->arp = 1; if (free_tx_pages <= 0) { /* Do timeouts, to avoid hangs. */ tickssofar = jiffies - dev->trans_start; if (tickssofar < 5) return 1; /* else */ printk("%s: transmit timed out (%d), %s?\n", dev->name, tickssofar, "network cable problem" ); /* Restart the adapter. */ adapter_init(dev); } /* Start real output */ PRINTK(("d_link_start_xmit:len=%d, page %d/%d\n", skb->len, tx_fifo_in, free_tx_pages)); if ((len = skb->len) < RUNT) len = RUNT; cli(); select_nic(); tx_fifo[tx_fifo_in] = transmit_from = tx_page_adr(tx_fifo_in) - len; tx_fifo_in = (tx_fifo_in + 1) % TX_PAGES; /* Next free tx page */ d_link_setup_address(transmit_from, RW_ADDR); for ( ; len > 0; --len, ++buffer) d_link_put_byte(*buffer); if (free_tx_pages-- == TX_PAGES) { /* No transmission going on */ dev->trans_start = jiffies; dev->tbusy = 0; /* allow more packets into adapter */ /* Send page and generate an interrupt */ d_link_setup_address(transmit_from, TX_ADDR); d_link_put_command(TX_ENABLE); } else { dev->tbusy = !free_tx_pages; select_prn(); } sti(); /* interrupts back on */ if (skb->free) kfree_skb (skb, FREE_WRITE); return 0; }