follow-up-patches [10/10] tuple-related functions by socket and function

Dominik Brodowski linux at brodo.de
Sat Nov 22 14:10:32 GMT 2003


The PCMCIA "tuple" functions don't need to know about the handle, as
long as they know about the socket and, at least some of them,
the device number. As ray_cs.c accessed these functions directly, it
needs to be fixed as well.

 drivers/net/wireless/ray_cs.c |   12 +++---
 drivers/pcmcia/cistpl.c       |   75 ++++++++++++++++--------------------------
 drivers/pcmcia/ds.c           |   37 +++++++++++++-------
 drivers/pcmcia/rsrc_mgr.c     |    2 -
 include/pcmcia/cistpl.h       |   12 +++---
 5 files changed, 67 insertions(+), 71 deletions(-)

diff -ruN linux-original/drivers/net/wireless/ray_cs.c linux/drivers/net/wireless/ray_cs.c
--- linux-original/drivers/net/wireless/ray_cs.c	2003-11-20 20:21:22.000000000 +0100
+++ linux/drivers/net/wireless/ray_cs.c	2003-11-22 13:50:56.522313168 +0100
@@ -492,6 +492,8 @@
 =============================================================================*/
 #define CS_CHECK(fn, args...) \
 while ((last_ret=fn(args))!=0) goto cs_failed
+#define CSCS_CHECK(args...) \
+while ((last_ret=CardServices(args))!=0) goto cs_failed
 #define MAX_TUPLE_SIZE 128
 static void ray_config(dev_link_t *link)
 {
@@ -510,23 +512,23 @@
 
     /* This reads the card's CONFIG tuple to find its configuration regs */
     tuple.DesiredTuple = CISTPL_CONFIG;
-    CS_CHECK(pcmcia_get_first_tuple, handle, &tuple);
+    CSCS_CHECK(GetFirstTuple, handle, &tuple);
     tuple.TupleData = buf;
     tuple.TupleDataMax = MAX_TUPLE_SIZE;
     tuple.TupleOffset = 0;
-    CS_CHECK(pcmcia_get_tuple_data, handle, &tuple);
-    CS_CHECK(pcmcia_parse_tuple, handle, &tuple, &parse);
+    CSCS_CHECK(GetTupleData, handle, &tuple);
+    CSCS_CHECK(ParseTuple, &tuple, &parse);
     link->conf.ConfigBase = parse.config.base;
     link->conf.Present = parse.config.rmask[0];
 
     /* Determine card type and firmware version */
     buf[0] = buf[MAX_TUPLE_SIZE - 1] = 0;
     tuple.DesiredTuple = CISTPL_VERS_1;
-    CS_CHECK(pcmcia_get_first_tuple, handle, &tuple);
+    CSCS_CHECK(GetFirstTuple, handle, &tuple);
     tuple.TupleData = buf;
     tuple.TupleDataMax = MAX_TUPLE_SIZE;
     tuple.TupleOffset = 2;
-    CS_CHECK(pcmcia_get_tuple_data, handle, &tuple);
+    CSCS_CHECK(GetTupleData, handle, &tuple);
 
     for (i=0; i<tuple.TupleDataLen - 4; i++) 
         if (buf[i] == 0) buf[i] = ' ';
diff -ruN linux-original/drivers/pcmcia/cistpl.c linux/drivers/pcmcia/cistpl.c
--- linux-original/drivers/pcmcia/cistpl.c	2003-11-20 20:21:24.000000000 +0100
+++ linux/drivers/pcmcia/cistpl.c	2003-11-22 13:50:56.562307088 +0100
@@ -368,12 +368,8 @@
     
 ======================================================================*/
 
-int pcmcia_replace_cis(client_handle_t handle, cisdump_t *cis)
+int pcmcia_replace_cis(struct pcmcia_socket *s, cisdump_t *cis)
 {
-    struct pcmcia_socket *s;
-    if (CHECK_HANDLE(handle))
-	return CS_BAD_HANDLE;
-    s = SOCKET(handle);
     if (s->fake_cis != NULL) {
 	kfree(s->fake_cis);
 	s->fake_cis = NULL;
@@ -406,14 +402,10 @@
 #define MFC_FN(f)	(((tuple_flags *)(&(f)))->mfc_fn)
 #define SPACE(f)	(((tuple_flags *)(&(f)))->space)
 
-int pcmcia_get_next_tuple(client_handle_t handle, tuple_t *tuple);
+int pcmcia_get_next_tuple(struct pcmcia_socket *s, unsigned int func, tuple_t *tuple);
 
-int pcmcia_get_first_tuple(client_handle_t handle, tuple_t *tuple)
+int pcmcia_get_first_tuple(struct pcmcia_socket *s, unsigned int func, tuple_t *tuple)
 {
-    struct pcmcia_socket *s;
-    if (CHECK_HANDLE(handle))
-	return CS_BAD_HANDLE;
-    s = SOCKET(handle);
     if (!(s->state & SOCKET_PRESENT))
 	return CS_NO_CARD;
     tuple->TupleLink = tuple->Flags = 0;
@@ -435,15 +427,15 @@
 	!(tuple->Attributes & TUPLE_RETURN_COMMON)) {
 	cisdata_t req = tuple->DesiredTuple;
 	tuple->DesiredTuple = CISTPL_LONGLINK_MFC;
-	if (pcmcia_get_next_tuple(handle, tuple) == CS_SUCCESS) {
+	if (pcmcia_get_next_tuple(s, func, tuple) == CS_SUCCESS) {
 	    tuple->DesiredTuple = CISTPL_LINKTARGET;
-	    if (pcmcia_get_next_tuple(handle, tuple) != CS_SUCCESS)
+	    if (pcmcia_get_next_tuple(s, func, tuple) != CS_SUCCESS)
 		return CS_NO_MORE_ITEMS;
 	} else
 	    tuple->CISOffset = tuple->TupleLink = 0;
 	tuple->DesiredTuple = req;
     }
-    return pcmcia_get_next_tuple(handle, tuple);
+    return pcmcia_get_next_tuple(s, func, tuple);
 }
 
 static int follow_link(struct pcmcia_socket *s, tuple_t *tuple)
@@ -486,15 +478,11 @@
     return -1;
 }
 
-int pcmcia_get_next_tuple(client_handle_t handle, tuple_t *tuple)
+int pcmcia_get_next_tuple(struct pcmcia_socket *s, unsigned int func, tuple_t *tuple)
 {
-    struct pcmcia_socket *s;
     u_char link[2], tmp;
     int ofs, i, attr;
     
-    if (CHECK_HANDLE(handle))
-	return CS_BAD_HANDLE;
-    s = SOCKET(handle);
     if (!(s->state & SOCKET_PRESENT))
 	return CS_NO_CARD;
 
@@ -546,14 +534,14 @@
 	    case CISTPL_LONGLINK_MFC:
 		tuple->LinkOffset = ofs + 3;
 		LINK_SPACE(tuple->Flags) = attr;
-		if (handle->Function == BIND_FN_ALL) {
+		if (func == BIND_FN_ALL) {
 		    /* Follow all the MFC links */
 		    read_cis_cache(s, attr, ofs+2, 1, &tmp);
 		    MFC_FN(tuple->Flags) = tmp;
 		} else {
 		    /* Follow exactly one of the links */
 		    MFC_FN(tuple->Flags) = 1;
-		    tuple->LinkOffset += handle->Function * 5;
+		    tuple->LinkOffset += func * 5;
 		}
 		break;
 	    case CISTPL_NO_LINK:
@@ -572,8 +560,7 @@
 	ofs += link[1] + 2;
     }
     if (i == MAX_TUPLES) {
-	DEBUG(1, "cs: overrun in pcmcia_get_next_tuple for socket %d\n",
-	      handle->Socket);
+	DEBUG(1, "cs: overrun in pcmcia_get_next_tuple\n");
 	return CS_NO_MORE_ITEMS;
     }
     
@@ -587,16 +574,10 @@
 
 #define _MIN(a, b)		(((a) < (b)) ? (a) : (b))
 
-int pcmcia_get_tuple_data(client_handle_t handle, tuple_t *tuple)
+int pcmcia_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple)
 {
-    struct pcmcia_socket *s;
     u_int len;
     
-    if (CHECK_HANDLE(handle))
-	return CS_BAD_HANDLE;
-
-    s = SOCKET(handle);
-
     if (tuple->TupleLink < tuple->TupleOffset)
 	return CS_NO_MORE_ITEMS;
     len = tuple->TupleLink - tuple->TupleOffset;
@@ -1313,7 +1294,7 @@
 
 /*====================================================================*/
 
-int pcmcia_parse_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse)
+int pcmcia_parse_tuple(tuple_t *tuple, cisparse_t *parse)
 {
     int ret = CS_SUCCESS;
     
@@ -1401,7 +1382,7 @@
     
 ======================================================================*/
 
-int read_tuple(client_handle_t handle, cisdata_t code, void *parse)
+static int __read_tuple(struct pcmcia_socket *s, unsigned int func, cisdata_t code, void *parse)
 {
     tuple_t tuple;
     cisdata_t buf[255];
@@ -1409,17 +1390,22 @@
     
     tuple.DesiredTuple = code;
     tuple.Attributes = TUPLE_RETURN_COMMON;
-    ret = pcmcia_get_first_tuple(handle, &tuple);
+    ret = pcmcia_get_first_tuple(s, func, &tuple);
     if (ret != CS_SUCCESS) return ret;
     tuple.TupleData = buf;
     tuple.TupleOffset = 0;
     tuple.TupleDataMax = sizeof(buf);
-    ret = pcmcia_get_tuple_data(handle, &tuple);
+    ret = pcmcia_get_tuple_data(s, &tuple);
     if (ret != CS_SUCCESS) return ret;
-    ret = pcmcia_parse_tuple(handle, &tuple, parse);
+    ret = pcmcia_parse_tuple(&tuple, parse);
     return ret;
 }
 
+int read_tuple(client_handle_t handle, cisdata_t code, void *parse)
+{
+	return __read_tuple(handle->Socket, handle->Function, code, parse);
+}
+
 /*======================================================================
 
     This tries to determine if a card has a sensible CIS.  It returns
@@ -1430,42 +1416,39 @@
     
 ======================================================================*/
 
-int pcmcia_validate_cis(client_handle_t handle, cisinfo_t *info)
+int pcmcia_validate_cis(struct pcmcia_socket *s, unsigned int func, cisinfo_t *info)
 {
     tuple_t tuple;
     cisparse_t p;
     int ret, reserved, dev_ok = 0, ident_ok = 0;
 
-    if (CHECK_HANDLE(handle))
-	return CS_BAD_HANDLE;
-
     info->Chains = reserved = 0;
     tuple.DesiredTuple = RETURN_FIRST_TUPLE;
     tuple.Attributes = TUPLE_RETURN_COMMON;
-    ret = pcmcia_get_first_tuple(handle, &tuple);
+    ret = pcmcia_get_first_tuple(s, func, &tuple);
     if (ret != CS_SUCCESS)
 	return CS_SUCCESS;
 
     /* First tuple should be DEVICE; we should really have either that
        or a CFTABLE_ENTRY of some sort */
     if ((tuple.TupleCode == CISTPL_DEVICE) ||
-	(read_tuple(handle, CISTPL_CFTABLE_ENTRY, &p) == CS_SUCCESS) ||
-	(read_tuple(handle, CISTPL_CFTABLE_ENTRY_CB, &p) == CS_SUCCESS))
+	(__read_tuple(s, func, CISTPL_CFTABLE_ENTRY, &p) == CS_SUCCESS) ||
+	(__read_tuple(s, func, CISTPL_CFTABLE_ENTRY_CB, &p) == CS_SUCCESS))
 	dev_ok++;
 
     /* All cards should have a MANFID tuple, and/or a VERS_1 or VERS_2
        tuple, for card identification.  Certain old D-Link and Linksys
        cards have only a broken VERS_2 tuple; hence the bogus test. */
-    if ((read_tuple(handle, CISTPL_MANFID, &p) == CS_SUCCESS) ||
-	(read_tuple(handle, CISTPL_VERS_1, &p) == CS_SUCCESS) ||
-	(read_tuple(handle, CISTPL_VERS_2, &p) != CS_NO_MORE_ITEMS))
+    if ((__read_tuple(s, func, CISTPL_MANFID, &p) == CS_SUCCESS) ||
+	(__read_tuple(s, func, CISTPL_VERS_1, &p) == CS_SUCCESS) ||
+	(__read_tuple(s, func, CISTPL_VERS_2, &p) != CS_NO_MORE_ITEMS))
 	ident_ok++;
 
     if (!dev_ok && !ident_ok)
 	return CS_SUCCESS;
 
     for (info->Chains = 1; info->Chains < MAX_TUPLES; info->Chains++) {
-	ret = pcmcia_get_next_tuple(handle, &tuple);
+	ret = pcmcia_get_next_tuple(s, func, &tuple);
 	if (ret != CS_SUCCESS) break;
 	if (((tuple.TupleCode > 0x23) && (tuple.TupleCode < 0x40)) ||
 	    ((tuple.TupleCode > 0x47) && (tuple.TupleCode < 0x80)) ||
diff -ruN linux-original/drivers/pcmcia/ds.c linux/drivers/pcmcia/ds.c
--- linux-original/drivers/pcmcia/ds.c	2003-11-22 13:51:46.397730952 +0100
+++ linux/drivers/pcmcia/ds.c	2003-11-22 13:50:56.563306936 +0100
@@ -383,15 +383,24 @@
 	case GetFirstRegion:
 		return pcmcia_get_first_region(a1, a2); break;
 	case GetFirstTuple:
-		return pcmcia_get_first_tuple(a1, a2); break;
+	{
+		client_handle_t h = a1;
+		return pcmcia_get_first_tuple(h->Socket, h->Function, a2); break;
+	}
 	case GetNextRegion:
 		return pcmcia_get_next_region(a1, a2); break;
 	case GetNextTuple:
-		return pcmcia_get_next_tuple(a1, a2); break;
+	{
+		client_handle_t h = a1;
+		return pcmcia_get_next_tuple(h->Socket, h->Function, a2); break;
+	}
 	case GetStatus:
 		return pcmcia_get_status(a1, a2); break;
 	case GetTupleData:
-		return pcmcia_get_tuple_data(a1, a2); break;
+	{
+		client_handle_t h = a1;
+		return pcmcia_get_tuple_data(h->Socket, a2); break;
+	}
 	case MapMemPage:
 		return pcmcia_map_mem_page(a1, a2); break;
 	case ModifyConfiguration:
@@ -408,7 +417,7 @@
 	}
         break;
 	case ParseTuple:
-		return pcmcia_parse_tuple(a1, a2, a3); break;
+		return pcmcia_parse_tuple(a2, a3); break;
 	case ReadMemory:
 		return pcmcia_read_memory(a1, a2, a3); break;
 	case RegisterClient:
@@ -454,19 +463,21 @@
 	case SetEventMask:
 		return pcmcia_set_event_mask(a1, a2); break;
 	case ValidateCIS:
-		return pcmcia_validate_cis(a1, a2); break;
+	{
+		client_handle_t h = a1;
+		return pcmcia_validate_cis(h->Socket, h->Function, a2); break;
+	}
 	case WriteMemory:
 		return pcmcia_write_memory(a1, a2, a3); break;
 	case ReportError:
 		return pcmcia_report_error(a1, a2); break;
-	case ReplaceCIS:
-		return pcmcia_replace_cis(a1, a2); break;
 	case GetFirstWindow:
 		return pcmcia_get_first_window(a1, a2); break;
 	case GetNextWindow:
 		return pcmcia_get_next_window(a1, a2); break;
 	case GetMemPage:
 		return pcmcia_get_mem_page(a1, a2); break;
+	case ReplaceCIS:
 	case AdjustResourceInfo:
 	case BindDevice:
 	case BindMTD:
@@ -1055,19 +1066,19 @@
 	ret = pcmcia_get_configuration_info(s->parent, BIND_FN_ALL, &buf.config);
 	break;
     case DS_GET_FIRST_TUPLE:
-	ret = pcmcia_get_first_tuple(s->handle, &buf.tuple);
+	ret = pcmcia_get_first_tuple(s->parent, BIND_FN_ALL, &buf.tuple);
 	break;
     case DS_GET_NEXT_TUPLE:
-	ret = pcmcia_get_next_tuple(s->handle, &buf.tuple);
+	ret = pcmcia_get_next_tuple(s->parent, BIND_FN_ALL, &buf.tuple);
 	break;
     case DS_GET_TUPLE_DATA:
 	buf.tuple.TupleData = buf.tuple_parse.data;
 	buf.tuple.TupleDataMax = sizeof(buf.tuple_parse.data);
-	ret = pcmcia_get_tuple_data(s->handle, &buf.tuple);
+	ret = pcmcia_get_tuple_data(s->parent, &buf.tuple);
 	break;
     case DS_PARSE_TUPLE:
 	buf.tuple.TupleData = buf.tuple_parse.data;
-	ret = pcmcia_parse_tuple(s->handle, &buf.tuple, &buf.tuple_parse.parse);
+	ret = pcmcia_parse_tuple(&buf.tuple, &buf.tuple_parse.parse);
 	break;
     case DS_RESET_CARD:
 	ret = pcmcia_reset_card(s->parent);
@@ -1076,7 +1087,7 @@
 	ret = pcmcia_get_status(s->handle, &buf.status);
 	break;
     case DS_VALIDATE_CIS:
-	ret = pcmcia_validate_cis(s->handle, &buf.cisinfo);
+	ret = pcmcia_validate_cis(s->parent, BIND_FN_ALL, &buf.cisinfo);
 	break;
     case DS_SUSPEND_CARD:
 	ret = pcmcia_suspend_card(s->parent);
@@ -1113,7 +1124,7 @@
 			   &buf.win_info.map);
 	break;
     case DS_REPLACE_CIS:
-	ret = pcmcia_replace_cis(s->handle, &buf.cisdump);
+	ret = pcmcia_replace_cis(s->parent, &buf.cisdump);
 	break;
     case DS_BIND_REQUEST:
 	if (!capable(CAP_SYS_ADMIN)) return -EPERM;
diff -ruN linux-original/drivers/pcmcia/rsrc_mgr.c linux/drivers/pcmcia/rsrc_mgr.c
--- linux-original/drivers/pcmcia/rsrc_mgr.c	2003-11-22 12:18:43.000000000 +0100
+++ linux/drivers/pcmcia/rsrc_mgr.c	2003-11-22 13:50:56.570305872 +0100
@@ -336,7 +336,7 @@
 	s->cis_mem.sys_stop = res->end;
 	s->cis_virt = ioremap(res->start, s->map_size);
 	if (s->cis_virt) {
-		ret = pcmcia_validate_cis(s->clients, info);
+		ret = pcmcia_validate_cis(s, BIND_FN_ALL, info);
 		/* invalidate mapping and CIS cache */
 		iounmap(s->cis_virt);
 		s->cis_virt = NULL;
diff -ruN linux-original/include/pcmcia/cistpl.h linux/include/pcmcia/cistpl.h
--- linux-original/include/pcmcia/cistpl.h	2003-11-20 20:21:28.000000000 +0100
+++ linux/include/pcmcia/cistpl.h	2003-11-22 13:50:56.589302984 +0100
@@ -601,12 +601,12 @@
     cisdata_t	Data[CISTPL_MAX_CIS_SIZE];
 } cisdump_t;
 
-int pcmcia_get_first_tuple(client_handle_t handle, tuple_t *tuple);
-int pcmcia_get_next_tuple(client_handle_t handle, tuple_t *tuple);
-int pcmcia_get_tuple_data(client_handle_t handle, tuple_t *tuple);
-int pcmcia_parse_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse);
+int pcmcia_get_first_tuple(struct pcmcia_socket *s, unsigned int func, tuple_t *tuple);
+int pcmcia_get_next_tuple(struct pcmcia_socket *s, unsigned int func, tuple_t *tuple);
+int pcmcia_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple);
+int pcmcia_parse_tuple(tuple_t *tuple, cisparse_t *parse);
 
-int pcmcia_validate_cis(client_handle_t handle, cisinfo_t *info);
-int pcmcia_replace_cis(client_handle_t handle, cisdump_t *cis);
+int pcmcia_validate_cis(struct pcmcia_socket *s, unsigned int func, cisinfo_t *info);
+int pcmcia_replace_cis(struct pcmcia_socket *s, cisdump_t *cis);
 
 #endif /* LINUX_CISTPL_H */



More information about the linux-pcmcia mailing list