/*
* ds.c -- 16-bit PCMCIA core support
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* The initial developer of the original code is David A. Hinds
* <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
* are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
*
* (C) 1999 David A. Hinds
* (C) 2003 - 2006 Dominik Brodowski
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/errno.h>
#include <linux/list.h>
#include <linux/delay.h>
#include <linux/workqueue.h>
#include <linux/crc32.h>
#include <linux/firmware.h>
#include <linux/kref.h>
#include <linux/dma-mapping.h>
#include <pcmcia/cs_types.h>
#include <pcmcia/cs.h>
#include <pcmcia/cistpl.h>
#include <pcmcia/ds.h>
#include <pcmcia/ss.h>
#include "cs_internal.h"
/*====================================================================*/
/* Module parameters */
MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");
MODULE_DESCRIPTION("PCMCIA Driver Services");
MODULE_LICENSE("GPL");
#ifdef CONFIG_PCMCIA_DEBUG
int ds_pc_debug;
module_param_named(pc_debug, ds_pc_debug, int, 0644);
#define ds_dbg(lvl, fmt, arg...) do { \
if (ds_pc_debug > (lvl)) \
printk(KERN_DEBUG "ds: " fmt , ## arg); \
} while (0)
#define ds_dev_dbg(lvl, dev, fmt, arg...) do { \
if (ds_pc_debug > (lvl)) \
dev_printk(KERN_DEBUG, dev, "ds: " fmt , ## arg); \
} while (0)
#else
#define ds_dbg(lvl, fmt, arg...) do { } while (0)
#define ds_dev_dbg(lvl, dev, fmt, arg...) do { } while (0)
#endif
spinlock_t pcmcia_dev_list_lock;
/*====================================================================*/
/* code which was in cs.c before */
/* String tables for error messages */
typedef struct lookup_t {
const int key;
const char *msg;
} lookup_t;
static const lookup_t error_table[] = {
{ 0, "Operation succeeded" },
{ -EIO, "Input/Output error" },
{ -ENODEV, "No card present" },
{ -EINVAL, "Bad parameter" },
{ -EACCES, "Configuration locked" },
{ -EBUSY, "Resource in use" },
{ -ENOSPC, "No more items" },
{ -ENOMEM, "Out of resource" },
};
static const lookup_t service_table[] = {
{ AccessConfigurationRegister, "AccessConfigurationRegister" },
{ AddSocketServices, "AddSocketServices" },
{ AdjustResourceInfo, "AdjustResourceInfo" },
{ CheckEraseQueue, "CheckEraseQueue" },
{ CloseMemory, "CloseMemory" },
{ DeregisterClient, "DeregisterClient" },
{ DeregisterEraseQueue, "DeregisterEraseQueue" },
{ GetCardServicesInfo, "GetCardServicesInfo" },
{ GetClientInfo, "GetClientInfo" },
{ GetConfigurationInfo, "GetConfigurationInfo" },
{ GetEventMask, "GetEventMask" },
{ GetFirstClient, "GetFirstClient" },
{ GetFirstRegion, "GetFirstRegion" },
{ GetFirstTuple, "GetFirstTuple" },
{ GetNextClient, "GetNextClient" },
{ GetNextRegion, "GetNextRegion" },
{ GetNextTuple, "GetNextTuple" },
{ GetStatus, "GetStatus" },
{ GetTupleData, "GetTupleData" },
{ MapMemPage, "MapMemPage" },
{ ModifyConfiguration, "ModifyConfiguration" },
{ ModifyWindow, "ModifyWindow" },
{ OpenMemory, "OpenMemory" },
{ ParseTuple, "ParseTuple" },
{ ReadMemory, "ReadMemory" },
{ RegisterClient, "RegisterClient" },
{ RegisterEraseQueue, "RegisterEraseQueue" },
{ RegisterMTD, "RegisterMTD" },
{ ReleaseConfiguration, "ReleaseConfiguration" },
{ ReleaseIO, "ReleaseIO" },
{ ReleaseIRQ, "ReleaseIRQ" },
{ ReleaseWindow, "ReleaseWindow" },
{ RequestConfiguration, "RequestConfiguration" },
{ RequestIO, "RequestIO" },
{ RequestIRQ, "RequestIRQ" },
{ RequestSocketMask, "RequestSocketMask" },
{ RequestWindow, "RequestWindow" },
{ ResetCard, "ResetCard" },
{ SetEventMask, "SetEventMask" },
{ ValidateCIS, "ValidateCIS" },
{ WriteMemory, "WriteMemory" },
{ BindDevice, "BindDevice" },
{ BindMTD, "BindMTD" },
{ ReportError, "ReportError" },
{ SuspendCard, "SuspendCard" },
{ ResumeCard, "ResumeCard" },
{ EjectCard, "EjectCard" },
{ InsertCard, "InsertCard" },
{ ReplaceCIS, "ReplaceCIS" }
};
const char *pcmcia_error_func(int func)
{
int i;
for (i = 0; i < ARRAY_SIZE(service_table); i++)
if (service_table[i].key == func)
return service_table[i].msg;
return "Unknown service number";
}
EXPORT_SYMBOL(pcmcia_error_func);
const char *pcmcia_error_ret(int ret)
{
int i;
for (i = 0; i < ARRAY_SIZE(error_table); i++)
if (error_table[i].key == ret)
return error_table[i].msg;
return "unknown";
}
EXPORT_SYMBOL(pcmcia_error_ret);
/*======================================================================*/
static void pcmcia_check_driver(struct pcmcia_driver *p_drv)
{
struct pcmcia_device_id *did = p_drv->id_table;
unsigned int i;
u32 hash;
if (!p_drv->probe || !p_drv->remove)
printk(KERN_DEBUG "pcmcia: %s lacks a requisite callback "
"function\n", p_drv->drv.name);
while (did && did->match_flags) {
for (i=0; i<4; i++) {
if (!did->prod_id[i])
continue;
hash = crc32(0, did->prod_id[i], strlen(did->prod_id[i]));
if (hash == did->prod_id_hash[i])
continue;
printk(KERN_DEBUG "pcmcia: %s: invalid hash for "
"product string \"%s\": is 0x%x, should "
"be 0x%x\n", p_drv->drv.name, did->prod_id[i],
did->prod_id_hash[i], hash);
printk(KERN_DEBUG "pcmcia: see "
"Documentation/pcmcia/devicetable.txt for "
"details\n");
}
did++;
}
return;
}
/*======================================================================*/
struct pcmcia_dynid {
struct list_head node;
struct pcmcia_device_id id;
};
/**
* pcmcia_store_new_id - add a new PCMCIA device ID to this driver and re-probe devices
* @driver: target device driver
* @buf: buffer for scanning device ID data
* @count: input size
*
* Adds a new dynamic PCMCIA device ID to this driver,
* and causes the driver to probe for all devices again.
*/
static ssize_t
pcmcia_store_new_id(struct device_driver *driver, const char *buf, size_t count)
{
struct pcmcia_dynid *dynid;
struct pcmcia_driver *pdrv = to_pcmcia_drv(driver);
__u16 match_flags, manf_id, card_id;
__u8 func_id, function, device_no;
__u32 prod_id_hash[4] = {0, 0, 0, 0};
int fields=0;
int retval = 0;
fields = sscanf(buf, "%hx %hx %hx %hhx %hhx %hhx %x %x %x %x",
&match_flags, &manf_id, &card_id, &func_id, &function, &device_no,
&prod_id_hash[0], &prod_id_hash[1], &prod_id_hash[2], &prod_id_hash[3]);
if (fields < 6)
return -EINVAL;
dynid = kzalloc(sizeof(struc
|