aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/pcmcia/driver-changes.txt7
-rw-r--r--drivers/pcmcia/cistpl.c61
-rw-r--r--drivers/pcmcia/cs_internal.h7
-rw-r--r--drivers/pcmcia/pcmcia_resource.c217
-rw-r--r--drivers/pcmcia/rsrc_mgr.c1
-rw-r--r--include/pcmcia/ds.h57
6 files changed, 304 insertions, 46 deletions
diff --git a/Documentation/pcmcia/driver-changes.txt b/Documentation/pcmcia/driver-changes.txt
index 059934363caf..adfb83e58675 100644
--- a/Documentation/pcmcia/driver-changes.txt
+++ b/Documentation/pcmcia/driver-changes.txt
@@ -1,5 +1,12 @@
1This file details changes in 2.6 which affect PCMCIA card driver authors: 1This file details changes in 2.6 which affect PCMCIA card driver authors:
2 2
3* New CIS tuple access (as of 2.6.33)
4 Instead of pcmcia_get_{first,next}_tuple(), pcmcia_get_tuple_data() and
5 pcmcia_parse_tuple(), a driver shall use "pcmcia_get_tuple()" if it is
6 only interested in one (raw) tuple, or "pcmcia_loop_tuple()" if it is
7 interested in all tuples of one type. To decode the MAC from CISTPL_FUNCE,
8 a new helper "pcmcia_get_mac_from_cis()" was added.
9
3* New configuration loop helper (as of 2.6.28) 10* New configuration loop helper (as of 2.6.28)
4 By calling pcmcia_loop_config(), a driver can iterate over all available 11 By calling pcmcia_loop_config(), a driver can iterate over all available
5 configuration options. During a driver's probe() phase, one doesn't need 12 configuration options. During a driver's probe() phase, one doesn't need
diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c
index 6c4a4fc83630..24dd3c1eac0b 100644
--- a/drivers/pcmcia/cistpl.c
+++ b/drivers/pcmcia/cistpl.c
@@ -1482,6 +1482,67 @@ done:
1482} 1482}
1483EXPORT_SYMBOL(pccard_read_tuple); 1483EXPORT_SYMBOL(pccard_read_tuple);
1484 1484
1485
1486/**
1487 * pccard_loop_tuple() - loop over tuples in the CIS
1488 * @s: the struct pcmcia_socket where the card is inserted
1489 * @function: the device function we loop for
1490 * @code: which CIS code shall we look for?
1491 * @parse: buffer where the tuple shall be parsed (or NULL, if no parse)
1492 * @priv_data: private data to be passed to the loop_tuple function.
1493 * @loop_tuple: function to call for each CIS entry of type @function. IT
1494 * gets passed the raw tuple, the paresed tuple (if @parse is
1495 * set) and @priv_data.
1496 *
1497 * pccard_loop_tuple() loops over all CIS entries of type @function, and
1498 * calls the @loop_tuple function for each entry. If the call to @loop_tuple
1499 * returns 0, the loop exits. Returns 0 on success or errorcode otherwise.
1500 */
1501int pccard_loop_tuple(struct pcmcia_socket *s, unsigned int function,
1502 cisdata_t code, cisparse_t *parse, void *priv_data,
1503 int (*loop_tuple) (tuple_t *tuple,
1504 cisparse_t *parse,
1505 void *priv_data))
1506{
1507 tuple_t tuple;
1508 cisdata_t *buf;
1509 int ret;
1510
1511 buf = kzalloc(256, GFP_KERNEL);
1512 if (buf == NULL) {
1513 dev_printk(KERN_WARNING, &s->dev, "no memory to read tuple\n");
1514 return -ENOMEM;
1515 }
1516
1517 tuple.TupleData = buf;
1518 tuple.TupleDataMax = 255;
1519 tuple.TupleOffset = 0;
1520 tuple.DesiredTuple = code;
1521 tuple.Attributes = 0;
1522
1523 ret = pccard_get_first_tuple(s, function, &tuple);
1524 while (!ret) {
1525 if (pccard_get_tuple_data(s, &tuple))
1526 goto next_entry;
1527
1528 if (parse)
1529 if (pcmcia_parse_tuple(&tuple, parse))
1530 goto next_entry;
1531
1532 ret = loop_tuple(&tuple, parse, priv_data);
1533 if (!ret)
1534 break;
1535
1536next_entry:
1537 ret = pccard_get_next_tuple(s, function, &tuple);
1538 }
1539
1540 kfree(buf);
1541 return ret;
1542}
1543EXPORT_SYMBOL(pccard_loop_tuple);
1544
1545
1485/*====================================================================== 1546/*======================================================================
1486 1547
1487 This tries to determine if a card has a sensible CIS. It returns 1548 This tries to determine if a card has a sensible CIS. It returns
diff --git a/drivers/pcmcia/cs_internal.h b/drivers/pcmcia/cs_internal.h
index 1f4098f1354d..06a14c951e92 100644
--- a/drivers/pcmcia/cs_internal.h
+++ b/drivers/pcmcia/cs_internal.h
@@ -199,6 +199,13 @@ int pcmcia_replace_cis(struct pcmcia_socket *s,
199 const u8 *data, const size_t len); 199 const u8 *data, const size_t len);
200int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *count); 200int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *count);
201 201
202/* loop over CIS entries */
203int pccard_loop_tuple(struct pcmcia_socket *s, unsigned int function,
204 cisdata_t code, cisparse_t *parse, void *priv_data,
205 int (*loop_tuple) (tuple_t *tuple,
206 cisparse_t *parse,
207 void *priv_data));
208
202/* rsrc_mgr.c */ 209/* rsrc_mgr.c */
203int pcmcia_validate_mem(struct pcmcia_socket *s); 210int pcmcia_validate_mem(struct pcmcia_socket *s);
204struct resource *pcmcia_find_io_region(unsigned long base, 211struct resource *pcmcia_find_io_region(unsigned long base,
diff --git a/drivers/pcmcia/pcmcia_resource.c b/drivers/pcmcia/pcmcia_resource.c
index d919e96c0afd..0bfb05aa8f85 100644
--- a/drivers/pcmcia/pcmcia_resource.c
+++ b/drivers/pcmcia/pcmcia_resource.c
@@ -20,6 +20,7 @@
20#include <linux/delay.h> 20#include <linux/delay.h>
21#include <linux/pci.h> 21#include <linux/pci.h>
22#include <linux/device.h> 22#include <linux/device.h>
23#include <linux/netdevice.h>
23 24
24#include <pcmcia/cs_types.h> 25#include <pcmcia/cs_types.h>
25#include <pcmcia/ss.h> 26#include <pcmcia/ss.h>
@@ -885,13 +886,40 @@ EXPORT_SYMBOL(pcmcia_disable_device);
885 886
886 887
887struct pcmcia_cfg_mem { 888struct pcmcia_cfg_mem {
888 tuple_t tuple; 889 struct pcmcia_device *p_dev;
890 void *priv_data;
891 int (*conf_check) (struct pcmcia_device *p_dev,
892 cistpl_cftable_entry_t *cfg,
893 cistpl_cftable_entry_t *dflt,
894 unsigned int vcc,
895 void *priv_data);
889 cisparse_t parse; 896 cisparse_t parse;
890 u8 buf[256];
891 cistpl_cftable_entry_t dflt; 897 cistpl_cftable_entry_t dflt;
892}; 898};
893 899
894/** 900/**
901 * pcmcia_do_loop_config() - internal helper for pcmcia_loop_config()
902 *
903 * pcmcia_do_loop_config() is the internal callback for the call from
904 * pcmcia_loop_config() to pccard_loop_tuple(). Data is transferred
905 * by a struct pcmcia_cfg_mem.
906 */
907static int pcmcia_do_loop_config(tuple_t *tuple, cisparse_t *parse, void *priv)
908{
909 cistpl_cftable_entry_t *cfg = &parse->cftable_entry;
910 struct pcmcia_cfg_mem *cfg_mem = priv;
911
912 /* default values */
913 cfg_mem->p_dev->conf.ConfigIndex = cfg->index;
914 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
915 cfg_mem->dflt = *cfg;
916
917 return cfg_mem->conf_check(cfg_mem->p_dev, cfg, &cfg_mem->dflt,
918 cfg_mem->p_dev->socket->socket.Vcc,
919 cfg_mem->priv_data);
920}
921
922/**
895 * pcmcia_loop_config() - loop over configuration options 923 * pcmcia_loop_config() - loop over configuration options
896 * @p_dev: the struct pcmcia_device which we need to loop for. 924 * @p_dev: the struct pcmcia_device which we need to loop for.
897 * @conf_check: function to call for each configuration option. 925 * @conf_check: function to call for each configuration option.
@@ -913,48 +941,173 @@ int pcmcia_loop_config(struct pcmcia_device *p_dev,
913 void *priv_data) 941 void *priv_data)
914{ 942{
915 struct pcmcia_cfg_mem *cfg_mem; 943 struct pcmcia_cfg_mem *cfg_mem;
916
917 tuple_t *tuple;
918 int ret; 944 int ret;
919 unsigned int vcc;
920 945
921 cfg_mem = kzalloc(sizeof(struct pcmcia_cfg_mem), GFP_KERNEL); 946 cfg_mem = kzalloc(sizeof(struct pcmcia_cfg_mem), GFP_KERNEL);
922 if (cfg_mem == NULL) 947 if (cfg_mem == NULL)
923 return -ENOMEM; 948 return -ENOMEM;
924 949
925 /* get the current Vcc setting */ 950 cfg_mem->p_dev = p_dev;
926 vcc = p_dev->socket->socket.Vcc; 951 cfg_mem->conf_check = conf_check;
952 cfg_mem->priv_data = priv_data;
927 953
928 tuple = &cfg_mem->tuple; 954 ret = pccard_loop_tuple(p_dev->socket, p_dev->func,
929 tuple->TupleData = cfg_mem->buf; 955 CISTPL_CFTABLE_ENTRY, &cfg_mem->parse,
930 tuple->TupleDataMax = 255; 956 cfg_mem, pcmcia_do_loop_config);
931 tuple->TupleOffset = 0;
932 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
933 tuple->Attributes = 0;
934 957
935 ret = pcmcia_get_first_tuple(p_dev, tuple); 958 kfree(cfg_mem);
936 while (!ret) { 959 return ret;
937 cistpl_cftable_entry_t *cfg = &cfg_mem->parse.cftable_entry; 960}
961EXPORT_SYMBOL(pcmcia_loop_config);
938 962
939 if (pcmcia_get_tuple_data(p_dev, tuple))
940 goto next_entry;
941 963
942 if (pcmcia_parse_tuple(tuple, &cfg_mem->parse)) 964struct pcmcia_loop_mem {
943 goto next_entry; 965 struct pcmcia_device *p_dev;
966 void *priv_data;
967 int (*loop_tuple) (struct pcmcia_device *p_dev,
968 tuple_t *tuple,
969 void *priv_data);
970};
944 971
945 /* default values */ 972/**
946 p_dev->conf.ConfigIndex = cfg->index; 973 * pcmcia_do_loop_tuple() - internal helper for pcmcia_loop_config()
947 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) 974 *
948 cfg_mem->dflt = *cfg; 975 * pcmcia_do_loop_tuple() is the internal callback for the call from
976 * pcmcia_loop_tuple() to pccard_loop_tuple(). Data is transferred
977 * by a struct pcmcia_cfg_mem.
978 */
979static int pcmcia_do_loop_tuple(tuple_t *tuple, cisparse_t *parse, void *priv)
980{
981 struct pcmcia_loop_mem *loop = priv;
949 982
950 ret = conf_check(p_dev, cfg, &cfg_mem->dflt, vcc, priv_data); 983 return loop->loop_tuple(loop->p_dev, tuple, loop->priv_data);
951 if (!ret) 984};
952 break; 985
986/**
987 * pcmcia_loop_tuple() - loop over tuples in the CIS
988 * @p_dev: the struct pcmcia_device which we need to loop for.
989 * @code: which CIS code shall we look for?
990 * @priv_data: private data to be passed to the loop_tuple function.
991 * @loop_tuple: function to call for each CIS entry of type @function. IT
992 * gets passed the raw tuple and @priv_data.
993 *
994 * pcmcia_loop_tuple() loops over all CIS entries of type @function, and
995 * calls the @loop_tuple function for each entry. If the call to @loop_tuple
996 * returns 0, the loop exits. Returns 0 on success or errorcode otherwise.
997 */
998int pcmcia_loop_tuple(struct pcmcia_device *p_dev, cisdata_t code,
999 int (*loop_tuple) (struct pcmcia_device *p_dev,
1000 tuple_t *tuple,
1001 void *priv_data),
1002 void *priv_data)
1003{
1004 struct pcmcia_loop_mem loop = {
1005 .p_dev = p_dev,
1006 .loop_tuple = loop_tuple,
1007 .priv_data = priv_data};
1008
1009 return pccard_loop_tuple(p_dev->socket, p_dev->func, code, NULL,
1010 &loop, pcmcia_do_loop_tuple);
1011};
1012EXPORT_SYMBOL(pcmcia_loop_tuple);
953 1013
954next_entry: 1014
955 ret = pcmcia_get_next_tuple(p_dev, tuple); 1015struct pcmcia_loop_get {
1016 size_t len;
1017 cisdata_t **buf;
1018};
1019
1020/**
1021 * pcmcia_do_get_tuple() - internal helper for pcmcia_get_tuple()
1022 *
1023 * pcmcia_do_get_tuple() is the internal callback for the call from
1024 * pcmcia_get_tuple() to pcmcia_loop_tuple(). As we're only interested in
1025 * the first tuple, return 0 unconditionally. Create a memory buffer large
1026 * enough to hold the content of the tuple, and fill it with the tuple data.
1027 * The caller is responsible to free the buffer.
1028 */
1029static int pcmcia_do_get_tuple(struct pcmcia_device *p_dev, tuple_t *tuple,
1030 void *priv)
1031{
1032 struct pcmcia_loop_get *get = priv;
1033
1034 *get->buf = kzalloc(tuple->TupleDataLen, GFP_KERNEL);
1035 if (*get->buf) {
1036 get->len = tuple->TupleDataLen;
1037 memcpy(*get->buf, tuple->TupleData, tuple->TupleDataLen);
956 } 1038 }
1039 return 0;
1040};
1041
1042/**
1043 * pcmcia_get_tuple() - get first tuple from CIS
1044 * @p_dev: the struct pcmcia_device which we need to loop for.
1045 * @code: which CIS code shall we look for?
1046 * @buf: pointer to store the buffer to.
1047 *
1048 * pcmcia_get_tuple() gets the content of the first CIS entry of type @code.
1049 * It returns the buffer length (or zero). The caller is responsible to free
1050 * the buffer passed in @buf.
1051 */
1052size_t pcmcia_get_tuple(struct pcmcia_device *p_dev, cisdata_t code,
1053 unsigned char **buf)
1054{
1055 struct pcmcia_loop_get get = {
1056 .len = 0,
1057 .buf = buf,
1058 };
1059
1060 *get.buf = NULL;
1061 pcmcia_loop_tuple(p_dev, code, pcmcia_do_get_tuple, &get);
1062
1063 return get.len;
1064};
1065EXPORT_SYMBOL(pcmcia_get_tuple);
1066
1067
1068/**
1069 * pcmcia_do_get_mac() - internal helper for pcmcia_get_mac_from_cis()
1070 *
1071 * pcmcia_do_get_mac() is the internal callback for the call from
1072 * pcmcia_get_mac_from_cis() to pcmcia_loop_tuple(). We check whether the
1073 * tuple contains a proper LAN_NODE_ID of length 6, and copy the data
1074 * to struct net_device->dev_addr[i].
1075 */
1076static int pcmcia_do_get_mac(struct pcmcia_device *p_dev, tuple_t *tuple,
1077 void *priv)
1078{
1079 struct net_device *dev = priv;
1080 int i;
1081
1082 if (tuple->TupleData[0] != CISTPL_FUNCE_LAN_NODE_ID)
1083 return -EINVAL;
1084 if (tuple->TupleDataLen < ETH_ALEN + 2) {
1085 dev_warn(&p_dev->dev, "Invalid CIS tuple length for "
1086 "LAN_NODE_ID\n");
1087 return -EINVAL;
1088 }
1089
1090 if (tuple->TupleData[1] != ETH_ALEN) {
1091 dev_warn(&p_dev->dev, "Invalid header for LAN_NODE_ID\n");
1092 return -EINVAL;
1093 }
1094 for (i = 0; i < 6; i++)
1095 dev->dev_addr[i] = tuple->TupleData[i+2];
1096 return 0;
1097};
1098
1099/**
1100 * pcmcia_get_mac_from_cis() - read out MAC address from CISTPL_FUNCE
1101 * @p_dev: the struct pcmcia_device for which we want the address.
1102 * @dev: a properly prepared struct net_device to store the info to.
1103 *
1104 * pcmcia_get_mac_from_cis() reads out the hardware MAC address from
1105 * CISTPL_FUNCE and stores it into struct net_device *dev->dev_addr which
1106 * must be set up properly by the driver (see examples!).
1107 */
1108int pcmcia_get_mac_from_cis(struct pcmcia_device *p_dev, struct net_device *dev)
1109{
1110 return pcmcia_loop_tuple(p_dev, CISTPL_FUNCE, pcmcia_do_get_mac, dev);
1111};
1112EXPORT_SYMBOL(pcmcia_get_mac_from_cis);
957 1113
958 return ret;
959}
960EXPORT_SYMBOL(pcmcia_loop_config);
diff --git a/drivers/pcmcia/rsrc_mgr.c b/drivers/pcmcia/rsrc_mgr.c
index e592e0e0d7ed..de0e770ce6a3 100644
--- a/drivers/pcmcia/rsrc_mgr.c
+++ b/drivers/pcmcia/rsrc_mgr.c
@@ -18,6 +18,7 @@
18#include <pcmcia/cs_types.h> 18#include <pcmcia/cs_types.h>
19#include <pcmcia/ss.h> 19#include <pcmcia/ss.h>
20#include <pcmcia/cs.h> 20#include <pcmcia/cs.h>
21#include <pcmcia/cistpl.h>
21#include "cs_internal.h" 22#include "cs_internal.h"
22 23
23 24
diff --git a/include/pcmcia/ds.h b/include/pcmcia/ds.h
index a2be80b9a095..2eb6e24d1a6b 100644
--- a/include/pcmcia/ds.h
+++ b/include/pcmcia/ds.h
@@ -34,6 +34,7 @@
34struct pcmcia_socket; 34struct pcmcia_socket;
35struct pcmcia_device; 35struct pcmcia_device;
36struct config_t; 36struct config_t;
37struct net_device;
37 38
38/* dynamic device IDs for PCMCIA device drivers. See 39/* dynamic device IDs for PCMCIA device drivers. See
39 * Documentation/pcmcia/driver.txt for details. 40 * Documentation/pcmcia/driver.txt for details.
@@ -176,26 +177,39 @@ const char *pcmcia_error_ret(int ret);
176 pcmcia_error_ret(ret)); \ 177 pcmcia_error_ret(ret)); \
177 } 178 }
178 179
179/* CIS access. 180
180 * Use the pcmcia_* versions in PCMCIA drivers 181/*
182 * CIS access.
183 *
184 * Please use the following functions to access CIS tuples:
185 * - pcmcia_get_tuple()
186 * - pcmcia_loop_tuple()
187 * - pcmcia_get_mac_from_cis()
188 *
189 * To parse a tuple_t, pcmcia_parse_tuple() exists. Its interface
190 * might change in future.
181 */ 191 */
182int pcmcia_parse_tuple(tuple_t *tuple, cisparse_t *parse);
183 192
184int pccard_get_first_tuple(struct pcmcia_socket *s, unsigned int function, 193/* get the very first CIS entry of type @code. Note that buf is pointer
185 tuple_t *tuple); 194 * to u8 *buf; and that you need to kfree(buf) afterwards. */
186#define pcmcia_get_first_tuple(p_dev, tuple) \ 195size_t pcmcia_get_tuple(struct pcmcia_device *p_dev, cisdata_t code,
187 pccard_get_first_tuple(p_dev->socket, p_dev->func, tuple) 196 u8 **buf);
188 197
189int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, 198/* loop over CIS entries */
190 tuple_t *tuple); 199int pcmcia_loop_tuple(struct pcmcia_device *p_dev, cisdata_t code,
191#define pcmcia_get_next_tuple(p_dev, tuple) \ 200 int (*loop_tuple) (struct pcmcia_device *p_dev,
192 pccard_get_next_tuple(p_dev->socket, p_dev->func, tuple) 201 tuple_t *tuple,
202 void *priv_data),
203 void *priv_data);
193 204
194int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple); 205/* get the MAC address from CISTPL_FUNCE */
195#define pcmcia_get_tuple_data(p_dev, tuple) \ 206int pcmcia_get_mac_from_cis(struct pcmcia_device *p_dev,
196 pccard_get_tuple_data(p_dev->socket, tuple) 207 struct net_device *dev);
197 208
198 209
210/* parse a tuple_t */
211int pcmcia_parse_tuple(tuple_t *tuple, cisparse_t *parse);
212
199/* loop CIS entries for valid configuration */ 213/* loop CIS entries for valid configuration */
200int pcmcia_loop_config(struct pcmcia_device *p_dev, 214int pcmcia_loop_config(struct pcmcia_device *p_dev,
201 int (*conf_check) (struct pcmcia_device *p_dev, 215 int (*conf_check) (struct pcmcia_device *p_dev,
@@ -215,6 +229,21 @@ int pcmcia_reset_card(struct pcmcia_socket *skt);
215int pcmcia_access_configuration_register(struct pcmcia_device *p_dev, 229int pcmcia_access_configuration_register(struct pcmcia_device *p_dev,
216 conf_reg_t *reg); 230 conf_reg_t *reg);
217 231
232/* deprecated -- do not use in drivers. */
233int pccard_get_first_tuple(struct pcmcia_socket *s, unsigned int function,
234 tuple_t *tuple);
235#define pcmcia_get_first_tuple(p_dev, tuple) \
236 pccard_get_first_tuple(p_dev->socket, p_dev->func, tuple)
237
238int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function,
239 tuple_t *tuple);
240#define pcmcia_get_next_tuple(p_dev, tuple) \
241 pccard_get_next_tuple(p_dev->socket, p_dev->func, tuple)
242
243int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple);
244#define pcmcia_get_tuple_data(p_dev, tuple) \
245 pccard_get_tuple_data(p_dev->socket, tuple)
246
218/* device configuration */ 247/* device configuration */
219int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req); 248int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req);
220int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req); 249int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req);