diff options
author | Dominik Brodowski <linux@dominikbrodowski.net> | 2010-03-20 15:03:57 -0400 |
---|---|---|
committer | Dominik Brodowski <linux@dominikbrodowski.net> | 2010-05-10 04:23:18 -0400 |
commit | 5c128e84324ca9389bc5f7d39f6b18f6de4a58ec (patch) | |
tree | 603f269717cd5c9183071629553b273b79d161ba /drivers/pcmcia/pcmcia_resource.c | |
parent | b9300aa7449f6636b188743d09199dcf27b1a4b4 (diff) |
pcmcia: move high level CIS access code to separate file
No code changes.
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
Diffstat (limited to 'drivers/pcmcia/pcmcia_resource.c')
-rw-r--r-- | drivers/pcmcia/pcmcia_resource.c | 229 |
1 files changed, 0 insertions, 229 deletions
diff --git a/drivers/pcmcia/pcmcia_resource.c b/drivers/pcmcia/pcmcia_resource.c index f355c5ac407b..9c5f9cd5e03d 100644 --- a/drivers/pcmcia/pcmcia_resource.c +++ b/drivers/pcmcia/pcmcia_resource.c | |||
@@ -923,232 +923,3 @@ void pcmcia_disable_device(struct pcmcia_device *p_dev) | |||
923 | pcmcia_release_window(p_dev, p_dev->win); | 923 | pcmcia_release_window(p_dev, p_dev->win); |
924 | } | 924 | } |
925 | EXPORT_SYMBOL(pcmcia_disable_device); | 925 | EXPORT_SYMBOL(pcmcia_disable_device); |
926 | |||
927 | |||
928 | struct pcmcia_cfg_mem { | ||
929 | struct pcmcia_device *p_dev; | ||
930 | void *priv_data; | ||
931 | int (*conf_check) (struct pcmcia_device *p_dev, | ||
932 | cistpl_cftable_entry_t *cfg, | ||
933 | cistpl_cftable_entry_t *dflt, | ||
934 | unsigned int vcc, | ||
935 | void *priv_data); | ||
936 | cisparse_t parse; | ||
937 | cistpl_cftable_entry_t dflt; | ||
938 | }; | ||
939 | |||
940 | /** | ||
941 | * pcmcia_do_loop_config() - internal helper for pcmcia_loop_config() | ||
942 | * | ||
943 | * pcmcia_do_loop_config() is the internal callback for the call from | ||
944 | * pcmcia_loop_config() to pccard_loop_tuple(). Data is transferred | ||
945 | * by a struct pcmcia_cfg_mem. | ||
946 | */ | ||
947 | static int pcmcia_do_loop_config(tuple_t *tuple, cisparse_t *parse, void *priv) | ||
948 | { | ||
949 | cistpl_cftable_entry_t *cfg = &parse->cftable_entry; | ||
950 | struct pcmcia_cfg_mem *cfg_mem = priv; | ||
951 | |||
952 | /* default values */ | ||
953 | cfg_mem->p_dev->conf.ConfigIndex = cfg->index; | ||
954 | if (cfg->flags & CISTPL_CFTABLE_DEFAULT) | ||
955 | cfg_mem->dflt = *cfg; | ||
956 | |||
957 | return cfg_mem->conf_check(cfg_mem->p_dev, cfg, &cfg_mem->dflt, | ||
958 | cfg_mem->p_dev->socket->socket.Vcc, | ||
959 | cfg_mem->priv_data); | ||
960 | } | ||
961 | |||
962 | /** | ||
963 | * pcmcia_loop_config() - loop over configuration options | ||
964 | * @p_dev: the struct pcmcia_device which we need to loop for. | ||
965 | * @conf_check: function to call for each configuration option. | ||
966 | * It gets passed the struct pcmcia_device, the CIS data | ||
967 | * describing the configuration option, and private data | ||
968 | * being passed to pcmcia_loop_config() | ||
969 | * @priv_data: private data to be passed to the conf_check function. | ||
970 | * | ||
971 | * pcmcia_loop_config() loops over all configuration options, and calls | ||
972 | * the driver-specific conf_check() for each one, checking whether | ||
973 | * it is a valid one. Returns 0 on success or errorcode otherwise. | ||
974 | */ | ||
975 | int pcmcia_loop_config(struct pcmcia_device *p_dev, | ||
976 | int (*conf_check) (struct pcmcia_device *p_dev, | ||
977 | cistpl_cftable_entry_t *cfg, | ||
978 | cistpl_cftable_entry_t *dflt, | ||
979 | unsigned int vcc, | ||
980 | void *priv_data), | ||
981 | void *priv_data) | ||
982 | { | ||
983 | struct pcmcia_cfg_mem *cfg_mem; | ||
984 | int ret; | ||
985 | |||
986 | cfg_mem = kzalloc(sizeof(struct pcmcia_cfg_mem), GFP_KERNEL); | ||
987 | if (cfg_mem == NULL) | ||
988 | return -ENOMEM; | ||
989 | |||
990 | cfg_mem->p_dev = p_dev; | ||
991 | cfg_mem->conf_check = conf_check; | ||
992 | cfg_mem->priv_data = priv_data; | ||
993 | |||
994 | ret = pccard_loop_tuple(p_dev->socket, p_dev->func, | ||
995 | CISTPL_CFTABLE_ENTRY, &cfg_mem->parse, | ||
996 | cfg_mem, pcmcia_do_loop_config); | ||
997 | |||
998 | kfree(cfg_mem); | ||
999 | return ret; | ||
1000 | } | ||
1001 | EXPORT_SYMBOL(pcmcia_loop_config); | ||
1002 | |||
1003 | |||
1004 | struct pcmcia_loop_mem { | ||
1005 | struct pcmcia_device *p_dev; | ||
1006 | void *priv_data; | ||
1007 | int (*loop_tuple) (struct pcmcia_device *p_dev, | ||
1008 | tuple_t *tuple, | ||
1009 | void *priv_data); | ||
1010 | }; | ||
1011 | |||
1012 | /** | ||
1013 | * pcmcia_do_loop_tuple() - internal helper for pcmcia_loop_config() | ||
1014 | * | ||
1015 | * pcmcia_do_loop_tuple() is the internal callback for the call from | ||
1016 | * pcmcia_loop_tuple() to pccard_loop_tuple(). Data is transferred | ||
1017 | * by a struct pcmcia_cfg_mem. | ||
1018 | */ | ||
1019 | static int pcmcia_do_loop_tuple(tuple_t *tuple, cisparse_t *parse, void *priv) | ||
1020 | { | ||
1021 | struct pcmcia_loop_mem *loop = priv; | ||
1022 | |||
1023 | return loop->loop_tuple(loop->p_dev, tuple, loop->priv_data); | ||
1024 | }; | ||
1025 | |||
1026 | /** | ||
1027 | * pcmcia_loop_tuple() - loop over tuples in the CIS | ||
1028 | * @p_dev: the struct pcmcia_device which we need to loop for. | ||
1029 | * @code: which CIS code shall we look for? | ||
1030 | * @priv_data: private data to be passed to the loop_tuple function. | ||
1031 | * @loop_tuple: function to call for each CIS entry of type @function. IT | ||
1032 | * gets passed the raw tuple and @priv_data. | ||
1033 | * | ||
1034 | * pcmcia_loop_tuple() loops over all CIS entries of type @function, and | ||
1035 | * calls the @loop_tuple function for each entry. If the call to @loop_tuple | ||
1036 | * returns 0, the loop exits. Returns 0 on success or errorcode otherwise. | ||
1037 | */ | ||
1038 | int pcmcia_loop_tuple(struct pcmcia_device *p_dev, cisdata_t code, | ||
1039 | int (*loop_tuple) (struct pcmcia_device *p_dev, | ||
1040 | tuple_t *tuple, | ||
1041 | void *priv_data), | ||
1042 | void *priv_data) | ||
1043 | { | ||
1044 | struct pcmcia_loop_mem loop = { | ||
1045 | .p_dev = p_dev, | ||
1046 | .loop_tuple = loop_tuple, | ||
1047 | .priv_data = priv_data}; | ||
1048 | |||
1049 | return pccard_loop_tuple(p_dev->socket, p_dev->func, code, NULL, | ||
1050 | &loop, pcmcia_do_loop_tuple); | ||
1051 | } | ||
1052 | EXPORT_SYMBOL(pcmcia_loop_tuple); | ||
1053 | |||
1054 | |||
1055 | struct pcmcia_loop_get { | ||
1056 | size_t len; | ||
1057 | cisdata_t **buf; | ||
1058 | }; | ||
1059 | |||
1060 | /** | ||
1061 | * pcmcia_do_get_tuple() - internal helper for pcmcia_get_tuple() | ||
1062 | * | ||
1063 | * pcmcia_do_get_tuple() is the internal callback for the call from | ||
1064 | * pcmcia_get_tuple() to pcmcia_loop_tuple(). As we're only interested in | ||
1065 | * the first tuple, return 0 unconditionally. Create a memory buffer large | ||
1066 | * enough to hold the content of the tuple, and fill it with the tuple data. | ||
1067 | * The caller is responsible to free the buffer. | ||
1068 | */ | ||
1069 | static int pcmcia_do_get_tuple(struct pcmcia_device *p_dev, tuple_t *tuple, | ||
1070 | void *priv) | ||
1071 | { | ||
1072 | struct pcmcia_loop_get *get = priv; | ||
1073 | |||
1074 | *get->buf = kzalloc(tuple->TupleDataLen, GFP_KERNEL); | ||
1075 | if (*get->buf) { | ||
1076 | get->len = tuple->TupleDataLen; | ||
1077 | memcpy(*get->buf, tuple->TupleData, tuple->TupleDataLen); | ||
1078 | } else | ||
1079 | dev_dbg(&p_dev->dev, "do_get_tuple: out of memory\n"); | ||
1080 | return 0; | ||
1081 | } | ||
1082 | |||
1083 | /** | ||
1084 | * pcmcia_get_tuple() - get first tuple from CIS | ||
1085 | * @p_dev: the struct pcmcia_device which we need to loop for. | ||
1086 | * @code: which CIS code shall we look for? | ||
1087 | * @buf: pointer to store the buffer to. | ||
1088 | * | ||
1089 | * pcmcia_get_tuple() gets the content of the first CIS entry of type @code. | ||
1090 | * It returns the buffer length (or zero). The caller is responsible to free | ||
1091 | * the buffer passed in @buf. | ||
1092 | */ | ||
1093 | size_t pcmcia_get_tuple(struct pcmcia_device *p_dev, cisdata_t code, | ||
1094 | unsigned char **buf) | ||
1095 | { | ||
1096 | struct pcmcia_loop_get get = { | ||
1097 | .len = 0, | ||
1098 | .buf = buf, | ||
1099 | }; | ||
1100 | |||
1101 | *get.buf = NULL; | ||
1102 | pcmcia_loop_tuple(p_dev, code, pcmcia_do_get_tuple, &get); | ||
1103 | |||
1104 | return get.len; | ||
1105 | } | ||
1106 | EXPORT_SYMBOL(pcmcia_get_tuple); | ||
1107 | |||
1108 | |||
1109 | /** | ||
1110 | * pcmcia_do_get_mac() - internal helper for pcmcia_get_mac_from_cis() | ||
1111 | * | ||
1112 | * pcmcia_do_get_mac() is the internal callback for the call from | ||
1113 | * pcmcia_get_mac_from_cis() to pcmcia_loop_tuple(). We check whether the | ||
1114 | * tuple contains a proper LAN_NODE_ID of length 6, and copy the data | ||
1115 | * to struct net_device->dev_addr[i]. | ||
1116 | */ | ||
1117 | static int pcmcia_do_get_mac(struct pcmcia_device *p_dev, tuple_t *tuple, | ||
1118 | void *priv) | ||
1119 | { | ||
1120 | struct net_device *dev = priv; | ||
1121 | int i; | ||
1122 | |||
1123 | if (tuple->TupleData[0] != CISTPL_FUNCE_LAN_NODE_ID) | ||
1124 | return -EINVAL; | ||
1125 | if (tuple->TupleDataLen < ETH_ALEN + 2) { | ||
1126 | dev_warn(&p_dev->dev, "Invalid CIS tuple length for " | ||
1127 | "LAN_NODE_ID\n"); | ||
1128 | return -EINVAL; | ||
1129 | } | ||
1130 | |||
1131 | if (tuple->TupleData[1] != ETH_ALEN) { | ||
1132 | dev_warn(&p_dev->dev, "Invalid header for LAN_NODE_ID\n"); | ||
1133 | return -EINVAL; | ||
1134 | } | ||
1135 | for (i = 0; i < 6; i++) | ||
1136 | dev->dev_addr[i] = tuple->TupleData[i+2]; | ||
1137 | return 0; | ||
1138 | } | ||
1139 | |||
1140 | /** | ||
1141 | * pcmcia_get_mac_from_cis() - read out MAC address from CISTPL_FUNCE | ||
1142 | * @p_dev: the struct pcmcia_device for which we want the address. | ||
1143 | * @dev: a properly prepared struct net_device to store the info to. | ||
1144 | * | ||
1145 | * pcmcia_get_mac_from_cis() reads out the hardware MAC address from | ||
1146 | * CISTPL_FUNCE and stores it into struct net_device *dev->dev_addr which | ||
1147 | * must be set up properly by the driver (see examples!). | ||
1148 | */ | ||
1149 | int pcmcia_get_mac_from_cis(struct pcmcia_device *p_dev, struct net_device *dev) | ||
1150 | { | ||
1151 | return pcmcia_loop_tuple(p_dev, CISTPL_FUNCE, pcmcia_do_get_mac, dev); | ||
1152 | } | ||
1153 | EXPORT_SYMBOL(pcmcia_get_mac_from_cis); | ||
1154 | |||