📄 ibmtr_cs.c
字号:
/*====================================================================== A PCMCIA token-ring driver for IBM-based cards This driver supports the IBM PCMCIA Token-Ring Card. Written by Steve Kipisz, kipisz@vnet.ibm.com or bungy@ibm.net Written 1995,1996. This code is based on pcnet_cs.c from David Hinds. V2.2.0 February 1999 - Mike Phillips phillim@amtrak.com Linux V2.2.x presented significant changes to the underlying ibmtr.c code. Mainly the code became a lot more organized and modular. This caused the old PCMCIA Token Ring driver to give up and go home early. Instead of just patching the old code to make it work, the PCMCIA code has been streamlined, updated and possibly improved. This code now only contains code required for the Card Services. All we do here is set the card up enough so that the real ibmtr.c driver can find it and work with it properly. i.e. We set up the io port, irq, mmio memory and shared ram memory. This enables ibmtr_probe in ibmtr.c to find the card and configure it as though it was a normal ISA and/or PnP card. CHANGES v2.2.5 April 1999 Mike Phillips (phillim@amtrak.com) Obscure bug fix, required changed to ibmtr.c not ibmtr_cs.c v2.2.7 May 1999 Mike Phillips (phillim@amtrak.com) Updated to version 2.2.7 to match the first version of the kernel that the modification to ibmtr.c were incorporated into. v2.2.17 July 2000 Burt Silverman (burts@us.ibm.com) Address translation feature of PCMCIA controller is usable so memory windows can be placed in High memory (meaning above 0xFFFFF.)======================================================================*/#include <linux/kernel.h>#include <linux/init.h>#include <linux/ptrace.h>#include <linux/slab.h>#include <linux/string.h>#include <linux/timer.h>#include <linux/module.h>#include <linux/ethtool.h>#include <linux/netdevice.h>#include <linux/trdevice.h>#include <linux/ibmtr.h>#include <pcmcia/cs_types.h>#include <pcmcia/cs.h>#include <pcmcia/cistpl.h>#include <pcmcia/ds.h>#include <asm/uaccess.h>#include <asm/io.h>#include <asm/system.h>#define PCMCIA#include "../tokenring/ibmtr.c"#ifdef PCMCIA_DEBUGstatic int pc_debug = PCMCIA_DEBUG;module_param(pc_debug, int, 0);#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)static char *version ="ibmtr_cs.c 1.10 1996/01/06 05:19:00 (Steve Kipisz)\n"" 2.2.7 1999/05/03 12:00:00 (Mike Phillips)\n"" 2.4.2 2001/30/28 Midnight (Burt Silverman)\n";#else#define DEBUG(n, args...)#endif/*====================================================================*//* Parameters that can be set with 'insmod' *//* MMIO base address */static u_long mmiobase = 0xce000;/* SRAM base address */static u_long srambase = 0xd0000;/* SRAM size 8,16,32,64 */static u_long sramsize = 64;/* Ringspeed 4,16 */static int ringspeed = 16;module_param(mmiobase, ulong, 0);module_param(srambase, ulong, 0);module_param(sramsize, ulong, 0);module_param(ringspeed, int, 0);MODULE_LICENSE("GPL");/*====================================================================*/static void ibmtr_config(dev_link_t *link);static void ibmtr_hw_setup(struct net_device *dev, u_int mmiobase);static void ibmtr_release(dev_link_t *link);static int ibmtr_event(event_t event, int priority, event_callback_args_t *args);static dev_info_t dev_info = "ibmtr_cs";static dev_link_t *ibmtr_attach(void);static void ibmtr_detach(dev_link_t *);static dev_link_t *dev_list;/*====================================================================*/typedef struct ibmtr_dev_t { dev_link_t link; struct net_device *dev; dev_node_t node; window_handle_t sram_win_handle; struct tok_info *ti;} ibmtr_dev_t;static void netdev_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info){ strcpy(info->driver, "ibmtr_cs");}static struct ethtool_ops netdev_ethtool_ops = { .get_drvinfo = netdev_get_drvinfo,};/*====================================================================== ibmtr_attach() creates an "instance" of the driver, allocating local data structures for one device. The device is registered with Card Services.======================================================================*/static dev_link_t *ibmtr_attach(void){ ibmtr_dev_t *info; dev_link_t *link; struct net_device *dev; client_reg_t client_reg; int ret; DEBUG(0, "ibmtr_attach()\n"); /* Create new token-ring device */ info = kmalloc(sizeof(*info), GFP_KERNEL); if (!info) return NULL; memset(info,0,sizeof(*info)); dev = alloc_trdev(sizeof(struct tok_info)); if (!dev) { kfree(info); return NULL; } link = &info->link; link->priv = info; info->ti = netdev_priv(dev); link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; link->io.NumPorts1 = 4; link->io.IOAddrLines = 16; link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT; link->irq.IRQInfo1 = IRQ_LEVEL_ID; link->irq.Handler = &tok_interrupt; link->conf.Attributes = CONF_ENABLE_IRQ; link->conf.Vcc = 50; link->conf.IntType = INT_MEMORY_AND_IO; link->conf.Present = PRESENT_OPTION; link->irq.Instance = info->dev = dev; SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops); /* Register with Card Services */ link->next = dev_list; dev_list = link; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != 0) { cs_error(link->handle, RegisterClient, ret); goto out_detach; }out: return link;out_detach: ibmtr_detach(link); link = NULL; goto out;} /* ibmtr_attach *//*====================================================================== This deletes a driver "instance". The device is de-registered with Card Services. If it has been released, all local data structures are freed. Otherwise, the structures will be freed when the device is released.======================================================================*/static void ibmtr_detach(dev_link_t *link){ struct ibmtr_dev_t *info = link->priv; dev_link_t **linkp; struct net_device *dev; DEBUG(0, "ibmtr_detach(0x%p)\n", link); /* Locate device structure */ for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) if (*linkp == link) break; if (*linkp == NULL) return; dev = info->dev; if (link->dev) unregister_netdev(dev); { struct tok_info *ti = netdev_priv(dev); del_timer_sync(&(ti->tr_timer)); } if (link->state & DEV_CONFIG) ibmtr_release(link); if (link->handle) pcmcia_deregister_client(link->handle); /* Unlink device structure, free bits */ *linkp = link->next; free_netdev(dev); kfree(info); } /* ibmtr_detach *//*====================================================================== ibmtr_config() is scheduled to run after a CARD_INSERTION event is received, to configure the PCMCIA socket, and to make the token-ring device available to the system.======================================================================*/#define CS_CHECK(fn, ret) \do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)static void ibmtr_config(dev_link_t *link){ client_handle_t handle = link->handle; ibmtr_dev_t *info = link->priv; struct net_device *dev = info->dev;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -