Only in ozscrlx-2.6.17: .ozscrlx.ko.cmd Only in ozscrlx-2.6.17: .ozscrlx.mod.o.cmd Only in ozscrlx-2.6.17: .ozscrlx.o.cmd Only in ozscrlx-2.6.17: .tmp_versions diff -ur ozscrlx-2.6.13/Makefile ozscrlx-2.6.17/Makefile --- ozscrlx-2.6.13/Makefile 2005-10-12 10:58:05.000000000 +0200 +++ ozscrlx-2.6.17/Makefile 2006-07-06 00:31:36.000000000 +0200 @@ -13,7 +13,7 @@ endif default: $(objs-m) - $(MAKE) -C /lib/modules/`uname -r`/build SUBDIRS=`pwd` modules + $(MAKE) -C /lib/modules/`uname -r`/build M=`pwd` modules install: cp -f ozscrlx.ko /lib/modules/`uname -r`/pcmcia Only in ozscrlx-2.6.17: Makefile~ Only in ozscrlx-2.6.17: Modules.symvers diff -ur ozscrlx-2.6.13/ozscrlx.c ozscrlx-2.6.17/ozscrlx.c --- ozscrlx-2.6.13/ozscrlx.c 2005-10-13 06:22:46.000000000 +0200 +++ ozscrlx-2.6.17/ozscrlx.c 2006-07-06 22:39:47.000000000 +0200 @@ -142,25 +142,28 @@ /* Bit map of interrupts to choose from */ static u_long irq_mask = 0xffff; -/* - * The event() function is this driver's Card Services event handler. - * It will be called by Card Services when an appropriate card status - * event is received. The config() and release() entry points are - * used to configure or release a socket, in response to card insertion - * and ejection events. They are invoked from the OZSCR event - * handler. - */ -static int ozscr_event(event_t event,int priority, event_callback_args_t *args); -static void ozscr_config(dev_link_t *link); -static void ozscr_release(u_long arg); + +static void ozscr_config(struct pcmcia_device *link, int devno); +static void ozscr_release(struct pcmcia_device *link); /* * The attach() and detach() entry points are used to create and destroy * "instances" of the driver, where each instance represents everything * needed to manage one actual PCMCIA card. */ -static dev_link_t* ozscr_attach(void); -static void ozscr_detach(dev_link_t *); +static int ozscr_attach(struct pcmcia_device *link); +static void ozscr_detach(struct pcmcia_device *link); + +static struct pcmcia_device_id ozscrlx_ids[] = { + PCMCIA_DEVICE_PROD_ID12("O2Micro", "SmartCardBus Reader", + 0x97299583, 0xB8501BA9), + PCMCIA_DEVICE_NULL, +}; +MODULE_DEVICE_TABLE(pcmcia, ozscrlx_ids); + + +static struct pcmcia_device *dev_table[10]; +static struct class *ozscr_class; /* * Prototypes of card access functions(File Operations) @@ -169,20 +172,6 @@ /* - * The dev_info variable is the "key" that is used to match up this - * device driver with appropriate cards, through the card configuration - * database. - */ -static dev_info_t dev_info = "ozscrlx_cs"; - -/* - * A linked list of "instances" of the OZSCR device. Each actual - * PCMCIA card corresponds to one device instance, and is described - * by one dev_link_t structure (defined in ds.h). - */ -static dev_link_t *dev_list = NULL; - -/* * Private data for OZSCR reader. Need to provide a dev_node_t * structure for the device. * FIX: Possibly needs to be extended to support PRG encryption and/or @@ -202,14 +191,14 @@ .drv ={ .name ="ozscrlx_cs", }, - .attach =ozscr_attach, - .event =ozscr_event, - .detach =ozscr_detach, + .probe =ozscr_attach, + .remove =ozscr_detach, + .id_table = ozscrlx_ids, }; /* Parameters that can be set with "insmod" */ static int mem_speed = 0; /* in ns */ -MODULE_PARM(mem_speed, "i"); +module_param(mem_speed, int, 0600); static UCHAR ct; /*Contact current value*/ static PPSCR_REGISTERS sync_IOBase; static PUCHAR sync_membase; @@ -221,27 +210,17 @@ */ static irqreturn_t ozscr_interrupt(int irq, void *dev_id, struct pt_regs *regs) { - dev_link_t *link; - struct ozscr_dev_t *dev; + struct pcmcia_device *link = dev_id; + struct ozscr_dev_t *dev = link->priv; u_char ack; #ifdef PCMCIA_DEBUG printk(KERN_INFO "OZSCRLX: interrupt\n"); #endif - - /* Find device that caused the interrupt.*/ - for (link = dev_list; link; link = link->next) - { - dev = (struct ozscr_dev_t *)link->priv; - if (dev && dev->irq == irq) - break; - } - - if (!DEV_OK(link)) + + if (!pcmcia_dev_present(link) || dev->irq != irq) return IRQ_NONE; - dev = (struct ozscr_dev_t *)link->priv; - /* Acknowledge interrupt to reader.*/ ack = inb(dev->io_base); ack &= ~OZSCR_IRQACK; @@ -258,22 +237,18 @@ #undef FUNC_NAME #define FUNC_NAME "ozscr_open: " - int minor = MINOR(inode->i_rdev); - dev_link_t *link; + struct pcmcia_device *link; struct ozscr_dev_t *dev; #ifdef PCMCIA_DEBUG printk(KERN_INFO MODULE_NAME FUNC_NAME "minor(%d)\n", minor); #endif - for (link = dev_list; link; link = link->next) - if (link->dev && link->dev->minor == minor) - break; - - if (!DEV_OK(link)) - return (-ENODEV); + link = dev_table[iminor(inode)]; + if (!link || !pcmcia_dev_present(link)) + return -ENODEV; - dev = (struct ozscr_dev_t *)link->priv; + dev = link->priv; /* Only one process may use the reader*/ if (link->open > 0) @@ -292,30 +267,22 @@ #define FUNC_NAME "ozscr_close: " - int minor = MINOR(inode->i_rdev); - dev_link_t *link; + struct pcmcia_device * link; struct ozscr_dev_t *dev; #ifdef PCMCIA_DEBUG printk(KERN_INFO MODULE_NAME FUNC_NAME "minor(%d)\n", minor); #endif - for (link = dev_list; link; link = link->next) - if (link->dev && link->dev->minor == minor) - break; - - if (!DEV_OK(link)) - return 0; + link = dev_table[iminor(inode)]; + if (!link || !pcmcia_dev_present(link)) + return 0; dev = (struct ozscr_dev_t *)link->priv; /* Make device available again, regardless of errors during close.*/ --(link->open); - /* If card was removed clean up*/ - if (link->state & DEV_STALE_CONFIG) - ozscr_release((u_long)link); - return 0; } @@ -338,8 +305,7 @@ #undef FUNC_NAME #define FUNC_NAME "ozscr_ioctl: " - int minor = MINOR(inode->i_rdev); - dev_link_t *link; + struct pcmcia_device *link; struct ozscr_dev_t *dev; int ret = 0; /* return value */ u_int size; /* size for data transfers */ @@ -349,13 +315,9 @@ struct ozscr_apdu apdu; - for (link = dev_list; link!=NULL; link = link->next) - if ((link->dev != NULL) && (link->dev->minor == minor)) - break; - if (!DEV_OK(link)) - { + link = dev_table[iminor(inode)]; + if (!link || !pcmcia_dev_present(link)) return -ENODEV; - } dev = (struct ozscr_dev_t *)link->priv; size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT; @@ -540,12 +502,11 @@ * is received, to configure the PCMCIA socket, and to make the * device available to the system. */ -static void ozscr_config(dev_link_t *link) +static void ozscr_config(struct pcmcia_device *link, int devno) { #undef FUNC_NAME #define FUNC_NAME "ozscr_config: " - client_handle_t handle = link->handle; struct ozscr_dev_t *dev = link->priv; tuple_t tuple; cisparse_t parse; @@ -570,16 +531,14 @@ printk(KERN_INFO MODULE_NAME FUNC_NAME "get tuple\n"); #endif - if((i = pcmcia_get_first_tuple(handle, &tuple)) != CS_SUCCESS) + if((i = pcmcia_get_first_tuple(link, &tuple)) != CS_SUCCESS) { - cs_error(link->handle, ParseTuple, i); - link->state &= ~DEV_CONFIG_PENDING; + cs_error(link, ParseTuple, i); goto error_return; } - if((i = get_tuple(handle, &tuple, &parse)) != CS_SUCCESS) + if((i = get_tuple(link, &tuple, &parse)) != CS_SUCCESS) { - cs_error(link->handle, ParseTuple, i); - link->state &= ~DEV_CONFIG_PENDING; + cs_error(link, ParseTuple, i); goto error_return; } @@ -591,7 +550,6 @@ link->conf.Present = parse.config.rmask[0]; /* Configure card Find I/O port for the card.*/ - link->state |= DEV_CONFIG; tuple.TupleOffset = 0; tuple.Attributes = 0; @@ -604,36 +562,34 @@ printk(KERN_INFO MODULE_NAME FUNC_NAME "config card (Find IO port)\n"); #endif - if((i = pcmcia_get_first_tuple(handle, &tuple)) != CS_SUCCESS) + if((i = pcmcia_get_first_tuple(link, &tuple)) != CS_SUCCESS) { - cs_error(link->handle, ParseTuple, i); - link->state &= ~DEV_CONFIG_PENDING; + cs_error(link, ParseTuple, i); goto error_return; } - i = get_tuple(handle, &tuple, &parse); + i = get_tuple(link, &tuple, &parse); while (i == CS_SUCCESS) { if (cf->io.nwin > 0) { link->conf.ConfigIndex = cf->index; link->io.BasePort1 = cf->io.win[0].base; - i = pcmcia_request_io(link->handle, &link->io); + i = pcmcia_request_io(link, &link->io); if (i == CS_SUCCESS) break; } - if((i = pcmcia_get_next_tuple(handle, &tuple)) != CS_SUCCESS) + if((i = pcmcia_get_next_tuple(link, &tuple)) != CS_SUCCESS) { - cs_error(link->handle, ParseTuple, i); - link->state &= ~DEV_CONFIG_PENDING; + cs_error(link, ParseTuple, i); goto error_return; } - i = get_tuple(handle, &tuple, &parse); + i = get_tuple(link, &tuple, &parse); } if (i != CS_SUCCESS) { - cs_error(link->handle, RequestIO, i); + cs_error(link, RequestIO, i); goto error_return; } #ifdef PCMCIA_DEBUG @@ -641,12 +597,12 @@ printk(KERN_INFO MODULE_NAME FUNC_NAME "Begin to request IRQ\n"); #endif /* Configure card Now allocate an interrupt line. (IRQ)*/ - if ((i = pcmcia_request_irq(handle, &link->irq)) != CS_SUCCESS) + if ((i = pcmcia_request_irq(link, &link->irq)) != CS_SUCCESS) { #ifdef PCMCIA_DEBUG printk(KERN_INFO MODULE_NAME FUNC_NAME "Request IRQ fail!\n"); #endif - cs_error(link->handle, RequestIRQ, i); + cs_error(link, RequestIRQ, i); goto error_return; } #ifdef PCMCIA_DEBUG @@ -655,10 +611,10 @@ #endif /* Set up the I/O window and the interrupt mapping.*/ - i = pcmcia_request_configuration(link->handle, &link->conf); + i = pcmcia_request_configuration(link, &link->conf); if ( i != CS_SUCCESS) { - cs_error(link->handle, RequestConfiguration, i); + cs_error(link, RequestConfiguration, i); goto error_return; } #ifdef PCMCIA_DEBUG @@ -671,13 +627,13 @@ req.Base = 0; req.Size = 0x1000; /* Request 2K memory */ req.AccessSpeed = mem_speed; - link->win = (window_handle_t)link->handle; - if ((i = pcmcia_request_window(&link->handle, &req, &link->win)) != CS_SUCCESS) + link->win = (window_handle_t)link; + if ((i = pcmcia_request_window(&link, &req, &link->win)) != CS_SUCCESS) { #ifdef PCMCIA_DEBUG printk(KERN_INFO MODULE_NAME FUNC_NAME "Request memory fail!\n"); #endif - cs_error(link->handle, RequestWindow, i); + cs_error(link, RequestWindow, i); goto error_return; } dev->cm_base = (caddr_t)req.Base; @@ -689,7 +645,7 @@ #ifdef PCMCIA_DEBUG printk(KERN_INFO MODULE_NAME FUNC_NAME "Map Memory Page fail!\n"); #endif - cs_error(link->handle, MapMemPage, i); + cs_error(link, MapMemPage, i); goto error_return; } @@ -698,16 +654,14 @@ #endif /* Initialize the dev_node_t structure */ - sprintf(dev->node.dev_name, "ozscrlx"); + sprintf(dev->node.dev_name, "ozscrlx%d", devno); dev->node.major = ozscr_major; - dev->node.minor = 0; + dev->node.minor = devno; dev->cm_base = (caddr_t)req.Base; dev->io_base = link->io.BasePort1; dev->irq = link->irq.AssignedIRQ; - link->dev = &dev->node; - - link->state &= ~DEV_CONFIG_PENDING; + link->dev_node = &dev->node; #ifdef PCMCIA_DEBUG printk(KERN_INFO MODULE_NAME FUNC_NAME "OZSCR device loaded\n"); @@ -717,159 +671,60 @@ error_return: /* If any step failed, release any partially configured state */ - ozscr_release((u_long)link); + ozscr_release(link); return; } -/* - * The card status event handler. Mostly, this schedules other - * stuff to run after an event is received. A CARD_REMOVAL event - * also sets some flags to discourage the net drivers from trying - * to talk to the card any more. - * - * When a CARD_REMOVAL event is received, we immediately set a flag - * to block future accesses to this device. All the functions that - - * actually access the device should check this flag to make sure - * the card is still present. - */ -static int ozscr_event(event_t event, int priority, event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - -#undef FUNC_NAME -#define FUNC_NAME "ozscr_event: " -#ifdef PCMCIA_DEBUG - printk(KERN_INFO MODULE_NAME FUNC_NAME "function begins\n"); -#endif - - switch (event) - { - case CS_EVENT_CARD_INSERTION: - -#ifdef PCMCIA_DEBUG - printk(KERN_INFO MODULE_NAME FUNC_NAME "Event: Card_Inserted\n"); -#endif - - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - ozscr_config(link); - break; - case CS_EVENT_REGISTRATION_COMPLETE: -#ifdef PCMCIA_DEBUG - printk(KERN_INFO MODULE_NAME FUNC_NAME "registration complete\n"); -#endif - break; - case CS_EVENT_CARD_REMOVAL: -#ifdef PCMCIA_DEBUG - printk(KERN_INFO MODULE_NAME FUNC_NAME "Event: Card_Removed\n"); -#endif - link->state &= ~DEV_PRESENT; - link->state &= DEV_STALE_CONFIG; - if (link->state & DEV_CONFIG) - { - flush_scheduled_work(); - } - ozscr_release((u_long)link); - break; - case CS_EVENT_PM_SUSPEND: -#ifdef PCMCIA_DEBUG - printk(KERN_INFO MODULE_NAME FUNC_NAME "Event: Card_Suspend\n"); -#endif - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: -#ifdef PCMCIA_DEBUG - printk(KERN_INFO MODULE_NAME FUNC_NAME "Event: Card_Physical_Reset\n"); -#endif - if (link->state & DEV_CONFIG) - pcmcia_release_configuration(link->handle); - break; - case CS_EVENT_PM_RESUME: - -#ifdef PCMCIA_DEBUG - printk(KERN_INFO MODULE_NAME FUNC_NAME "Event: Card_Resume\n"); -#endif - - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: -#ifdef PCMCIA_DEBUG - printk(KERN_INFO MODULE_NAME FUNC_NAME "Event: Card_Reset\n"); -#endif - if (link->state & DEV_CONFIG) - pcmcia_request_configuration(link->handle, &link->conf); - break; - default: -#ifdef PCMCIA_DEBUG - printk(KERN_INFO MODULE_NAME FUNC_NAME "Event: Unknown\n"); -#endif - break; - } - return 0; -} - - /* * ozscr_attach() creates an "instance" of the driver, allocating - * local data structures for one device. The device is registered - * with Card Services. - * - * The dev_link structure is initialized, but we don't actually - * configure the card at this point -- we wait until we receive a - * card insertion event. + * local data structures for one device. */ -static dev_link_t *ozscr_attach(void) +static int ozscr_attach(struct pcmcia_device * link) { #undef FUNC_NAME #define FUNC_NAME "ozscr_attach: " - client_reg_t client_reg; - dev_link_t *link=NULL; struct ozscr_dev_t *local=NULL; - int ret=0; PREADER_EXTENSION pRdrExt=NULL; + int i; #ifdef PCMCIA_DEBUG printk(KERN_INFO MODULE_NAME FUNC_NAME "function begins\n"); -#endif - /* Initialize the dev_link_t structure */ - link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL); - if (link == NULL) - { -#ifdef PCMCIA_DEBUG - printk(KERN_INFO MODULE_NAME FUNC_NAME "allocate dev_link_t fail\n"); #endif - goto ErrHandle; + for (i = 0; i < 10; i++) + if (dev_table[i] == NULL) + break; + if (i == 10) { + printk(KERN_NOTICE MODULE_NAME ": all devices in use\n"); + return -ENODEV; } - memset(link, 0, sizeof(struct dev_link_t)); /* Allocate space for private device-specific data */ - local = kmalloc(sizeof(struct ozscr_dev_t), GFP_KERNEL); + local = kzalloc(sizeof(struct ozscr_dev_t), GFP_KERNEL); if (local == NULL) { #ifdef PCMCIA_DEBUG - printk(KERN_INFO MODULE_NAME FUNC_NAME "allocate dev_link_t fail\n"); + printk(KERN_INFO MODULE_NAME FUNC_NAME "allocate ozscr_dev_t fail\n"); #endif - goto ErrHandle; + goto err1; } - memset(local, 0, sizeof(struct ozscr_dev_t)); /* Allocate space for private device-specific data */ - pRdrExt = kmalloc(sizeof(PREADER_EXTENSION), GFP_KERNEL); + pRdrExt = kzalloc(sizeof(PREADER_EXTENSION), GFP_KERNEL); if (pRdrExt == NULL) { #ifdef PCMCIA_DEBUG printk(KERN_INFO MODULE_NAME FUNC_NAME "allocate dev_link_t fail\n"); #endif - goto ErrHandle; + goto err2; } - memset(local, 0, sizeof(PREADER_EXTENSION)); link->priv = local; + link->conf.IntType = INT_MEMORY_AND_IO; /* The io structure describes IO port mapping */ link->io.NumPorts1 = 32; @@ -886,27 +741,16 @@ /* General socket nfiguration */ link->conf.Attributes = CONF_ENABLE_IRQ; - link->conf.Vcc = 50; - link->conf.Vpp1 = link->conf.Vpp2 = 50; link->conf.IntType = INT_MEMORY_AND_IO; link->conf.Present = PRESENT_OPTION | PRESENT_STATUS; - link->next = dev_list; /* build linked to handle multiple instances */ - dev_list = link; + dev_table[i] = link; - client_reg.dev_info = &dev_info; - client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; + ozscr_config(link, i); + + class_device_create(ozscr_class, NULL, MKDEV(ozscr_major, i), NULL, + "ozscr%d", i); - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != CS_SUCCESS) - { -#ifdef PCMCIA_DEBUG - printk(KERN_INFO MODULE_NAME FUNC_NAME "register client fail!\n"); -#endif - goto ErrHandle; - } #ifdef PCMCIA_DEBUG printk(KERN_INFO MODULE_NAME FUNC_NAME "function complete\n"); #endif @@ -914,33 +758,12 @@ pRdrExt->membase = local->am_base; CmdResetInterface(pRdrExt); - return link; - -ErrHandle: - - if (ret != 0) - { - cs_error(link->handle, RegisterClient, ret); - ozscr_detach(link); link = NULL; - } - /* Free the allocated memory space */ - if (link != NULL) - { - kfree(link); - link = NULL; - } - if (local != NULL) - { - kfree(local); - local = NULL; - } - if (pRdrExt != NULL) - { - kfree(pRdrExt); - pRdrExt = NULL; - } + return 0; - return NULL; + err1: + kfree(local); + err2: + return -ENODEV; } @@ -952,11 +775,9 @@ * been removed. */ static void -ozscr_release(u_long arg) +ozscr_release(struct pcmcia_device * link) { - dev_link_t *link = (dev_link_t *)arg; - #undef FUNC_NAME #define FUNC_NAME "ozscr_release: " #ifdef PCMCIA_DEBUG @@ -975,40 +796,26 @@ #ifdef PCMCIA_DEBUG printk(KERN_INFO MODULE_NAME FUNC_NAME "release postponed,%s still open\n", link->dev->dev_name); #endif - link->state |= DEV_STALE_CONFIG; return; } - /* Unlink the device chain */ - link->dev = NULL; - /* Don't bother checking to see if these succeed or not */ pcmcia_release_window(link->win); - pcmcia_release_configuration(link->handle); - - pcmcia_release_io(link->handle, &link->io); - pcmcia_release_irq(link->handle, &link->irq); - link->state &= ~DEV_CONFIG; - - if (link->state & DEV_STALE_LINK) - ozscr_detach(link); - - return; } /* * This deletes a driver "instance". The device is de-registered - * with Card Services. If it has been released, all local data - * structures are freed. + * with Card Services. */ static void -ozscr_detach(dev_link_t *link) +ozscr_detach(struct pcmcia_device *link) { #undef FUNC_NAME #define FUNC_NAME "ozscr_detach: " - dev_link_t **linkp; + struct ozscr_dev_t * dev = link->priv; + int devno; #ifdef PCMCIA_DEBUG printk(KERN_INFO MODULE_NAME FUNC_NAME "Device Link (0x%p)\n", link); @@ -1017,45 +824,20 @@ /* * Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - { - if (*linkp == link) - break; - } - if (*linkp == NULL) - return; - - if (link->state & DEV_CONFIG) - { -#ifdef PCMCIA_DEBUG - printk(KERN_INFO MODULE_NAME FUNC_NAME ": detach of %s postponed" - " - device still configured", link->dev->dev_name); -#endif - - ozscr_release((u_long)*linkp); - if (link->state & DEV_STALE_CONFIG) - { - link->state |= DEV_STALE_LINK; - return; - } - } - + for (devno = 0; devno < 10; devno++) + if (dev_table[devno] == link) + break; + if (devno == 10) + return; - /* Break the link with Card Services */ - if (link->handle) - pcmcia_deregister_client(link->handle); + ozscr_release(dev_table[devno]); - /* Unlink device structure, free pieces */ - *linkp = link->next; + dev_table[devno] = NULL; + kfree(dev); - if (link->priv) - { - kfree(link->priv); - } - kfree(link); + class_device_destroy(ozscr_class, MKDEV(ozscr_major, devno)); return; - } ssize_t ozscr_read( @@ -1105,6 +887,8 @@ printk(KERN_INFO MODULE_NAME "version: %s\n", version); + ozscr_class = class_create(THIS_MODULE, "ozscr"); + pcmcia_register_driver(&ozscrlx_driver); /* Register new character device with kernel */ @@ -1137,14 +921,7 @@ #endif unregister_chrdev(ozscr_major, "ozscrlx"); pcmcia_unregister_driver(&ozscrlx_driver); - while (dev_list != NULL) - { - if (dev_list->state & DEV_CONFIG) - ozscr_release((u_long)dev_list); - ozscr_detach(dev_list); - } - - return; + class_destroy(ozscr_class); } Only in ozscrlx-2.6.17: ozscrlx.c~ Only in ozscrlx-2.6.17: ozscrlx.ko Only in ozscrlx-2.6.17: ozscrlx.mod.c Only in ozscrlx-2.6.17: ozscrlx.mod.o Only in ozscrlx-2.6.17: ozscrlx.o