From 408045afbdb46e109a1a44e67af688e9ddf7ad66 Mon Sep 17 00:00:00 2001 From: Alex Williamson Date: Wed, 21 Dec 2005 15:21:36 -0700 Subject: [PATCH 01/48] [IA64] incorrect return from ia64_pci_legacy_write() The function ia64_pci_legacy_write() returns 0 for everything except errors. This return value gets sent back to the user from pci_write_legacy_io(), making it look like every write fails. The trivial patch below copies the behavior of the SGI sn machvec and does what would be expected from something implementing a write() function. Signed-off-by: Alex Williamson Signed-off-by: Tony Luck --- arch/ia64/pci/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/ia64/pci/pci.c b/arch/ia64/pci/pci.c index 20d76fae24e8..30dbc98bf0b3 100644 --- a/arch/ia64/pci/pci.c +++ b/arch/ia64/pci/pci.c @@ -700,7 +700,7 @@ int ia64_pci_legacy_read(struct pci_bus *bus, u16 port, u32 *val, u8 size) */ int ia64_pci_legacy_write(struct pci_dev *bus, u16 port, u32 val, u8 size) { - int ret = 0; + int ret = size; switch (size) { case 1: From 4ffd2e4907184813101cefa7196102927cdbe104 Mon Sep 17 00:00:00 2001 From: Adrian Bunk Date: Thu, 5 Jan 2006 12:14:43 -0800 Subject: [PATCH 02/48] [IPVS]: Fix compilation Signed-off-by: Adrian Bunk Acked-by: Arnaldo Carvalho de Melo Signed-off-by: David S. Miller --- net/ipv4/ipvs/ip_vs_est.c | 1 + net/ipv4/ipvs/ip_vs_sched.c | 1 + 2 files changed, 2 insertions(+) diff --git a/net/ipv4/ipvs/ip_vs_est.c b/net/ipv4/ipvs/ip_vs_est.c index e7004741ac73..c453e1e57f4b 100644 --- a/net/ipv4/ipvs/ip_vs_est.c +++ b/net/ipv4/ipvs/ip_vs_est.c @@ -18,6 +18,7 @@ #include #include #include +#include #include diff --git a/net/ipv4/ipvs/ip_vs_sched.c b/net/ipv4/ipvs/ip_vs_sched.c index 0f7c56a225bd..8bc42b76223d 100644 --- a/net/ipv4/ipvs/ip_vs_sched.c +++ b/net/ipv4/ipvs/ip_vs_sched.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include From 3e4ead4fe5d0d9fdd7ad6749e6e608d39dd46e8a Mon Sep 17 00:00:00 2001 From: Jesper Juhl Date: Thu, 5 Jan 2006 12:15:58 -0800 Subject: [PATCH 03/48] [NETFILTER]: Decrease number of pointer derefs in nfnetlink_queue.c Benefits of the patch: - Fewer pointer dereferences should make the code slightly faster. - Size of generated code is smaller - improved readability Signed-off-by: Jesper Juhl Signed-off-by: Patrick McHardy Signed-off-by: David S. Miller --- net/netfilter/nfnetlink_queue.c | 79 ++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 35 deletions(-) diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c index 55afdda3d940..18ed9c5d209c 100644 --- a/net/netfilter/nfnetlink_queue.c +++ b/net/netfilter/nfnetlink_queue.c @@ -345,6 +345,10 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue, struct nfqnl_msg_packet_hdr pmsg; struct nlmsghdr *nlh; struct nfgenmsg *nfmsg; + struct nf_info *entinf = entry->info; + struct sk_buff *entskb = entry->skb; + struct net_device *indev; + struct net_device *outdev; unsigned int tmp_uint; QDEBUG("entered\n"); @@ -361,6 +365,8 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue, + NLMSG_SPACE(sizeof(struct nfqnl_msg_packet_hw)) + NLMSG_SPACE(sizeof(struct nfqnl_msg_packet_timestamp)); + outdev = entinf->outdev; + spin_lock_bh(&queue->lock); switch (queue->copy_mode) { @@ -370,15 +376,15 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue, break; case NFQNL_COPY_PACKET: - if (entry->skb->ip_summed == CHECKSUM_HW && - (*errp = skb_checksum_help(entry->skb, - entry->info->outdev == NULL))) { + if (entskb->ip_summed == CHECKSUM_HW && + (*errp = skb_checksum_help(entskb, + outdev == NULL))) { spin_unlock_bh(&queue->lock); return NULL; } if (queue->copy_range == 0 - || queue->copy_range > entry->skb->len) - data_len = entry->skb->len; + || queue->copy_range > entskb->len) + data_len = entskb->len; else data_len = queue->copy_range; @@ -402,29 +408,30 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue, NFNL_SUBSYS_QUEUE << 8 | NFQNL_MSG_PACKET, sizeof(struct nfgenmsg)); nfmsg = NLMSG_DATA(nlh); - nfmsg->nfgen_family = entry->info->pf; + nfmsg->nfgen_family = entinf->pf; nfmsg->version = NFNETLINK_V0; nfmsg->res_id = htons(queue->queue_num); pmsg.packet_id = htonl(entry->id); - pmsg.hw_protocol = htons(entry->skb->protocol); - pmsg.hook = entry->info->hook; + pmsg.hw_protocol = htons(entskb->protocol); + pmsg.hook = entinf->hook; NFA_PUT(skb, NFQA_PACKET_HDR, sizeof(pmsg), &pmsg); - if (entry->info->indev) { - tmp_uint = htonl(entry->info->indev->ifindex); + indev = entinf->indev; + if (indev) { + tmp_uint = htonl(indev->ifindex); #ifndef CONFIG_BRIDGE_NETFILTER NFA_PUT(skb, NFQA_IFINDEX_INDEV, sizeof(tmp_uint), &tmp_uint); #else - if (entry->info->pf == PF_BRIDGE) { + if (entinf->pf == PF_BRIDGE) { /* Case 1: indev is physical input device, we need to * look for bridge group (when called from * netfilter_bridge) */ NFA_PUT(skb, NFQA_IFINDEX_PHYSINDEV, sizeof(tmp_uint), &tmp_uint); /* this is the bridge group "brX" */ - tmp_uint = htonl(entry->info->indev->br_port->br->dev->ifindex); + tmp_uint = htonl(indev->br_port->br->dev->ifindex); NFA_PUT(skb, NFQA_IFINDEX_INDEV, sizeof(tmp_uint), &tmp_uint); } else { @@ -432,9 +439,9 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue, * physical device (when called from ipv4) */ NFA_PUT(skb, NFQA_IFINDEX_INDEV, sizeof(tmp_uint), &tmp_uint); - if (entry->skb->nf_bridge - && entry->skb->nf_bridge->physindev) { - tmp_uint = htonl(entry->skb->nf_bridge->physindev->ifindex); + if (entskb->nf_bridge + && entskb->nf_bridge->physindev) { + tmp_uint = htonl(entskb->nf_bridge->physindev->ifindex); NFA_PUT(skb, NFQA_IFINDEX_PHYSINDEV, sizeof(tmp_uint), &tmp_uint); } @@ -442,19 +449,19 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue, #endif } - if (entry->info->outdev) { - tmp_uint = htonl(entry->info->outdev->ifindex); + if (outdev) { + tmp_uint = htonl(outdev->ifindex); #ifndef CONFIG_BRIDGE_NETFILTER NFA_PUT(skb, NFQA_IFINDEX_OUTDEV, sizeof(tmp_uint), &tmp_uint); #else - if (entry->info->pf == PF_BRIDGE) { + if (entinf->pf == PF_BRIDGE) { /* Case 1: outdev is physical output device, we need to * look for bridge group (when called from * netfilter_bridge) */ NFA_PUT(skb, NFQA_IFINDEX_PHYSOUTDEV, sizeof(tmp_uint), &tmp_uint); /* this is the bridge group "brX" */ - tmp_uint = htonl(entry->info->outdev->br_port->br->dev->ifindex); + tmp_uint = htonl(outdev->br_port->br->dev->ifindex); NFA_PUT(skb, NFQA_IFINDEX_OUTDEV, sizeof(tmp_uint), &tmp_uint); } else { @@ -462,9 +469,9 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue, * physical output device (when called from ipv4) */ NFA_PUT(skb, NFQA_IFINDEX_OUTDEV, sizeof(tmp_uint), &tmp_uint); - if (entry->skb->nf_bridge - && entry->skb->nf_bridge->physoutdev) { - tmp_uint = htonl(entry->skb->nf_bridge->physoutdev->ifindex); + if (entskb->nf_bridge + && entskb->nf_bridge->physoutdev) { + tmp_uint = htonl(entskb->nf_bridge->physoutdev->ifindex); NFA_PUT(skb, NFQA_IFINDEX_PHYSOUTDEV, sizeof(tmp_uint), &tmp_uint); } @@ -472,27 +479,27 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue, #endif } - if (entry->skb->nfmark) { - tmp_uint = htonl(entry->skb->nfmark); + if (entskb->nfmark) { + tmp_uint = htonl(entskb->nfmark); NFA_PUT(skb, NFQA_MARK, sizeof(u_int32_t), &tmp_uint); } - if (entry->info->indev && entry->skb->dev - && entry->skb->dev->hard_header_parse) { + if (indev && entskb->dev + && entskb->dev->hard_header_parse) { struct nfqnl_msg_packet_hw phw; phw.hw_addrlen = - entry->skb->dev->hard_header_parse(entry->skb, + entskb->dev->hard_header_parse(entskb, phw.hw_addr); phw.hw_addrlen = htons(phw.hw_addrlen); NFA_PUT(skb, NFQA_HWADDR, sizeof(phw), &phw); } - if (entry->skb->tstamp.off_sec) { + if (entskb->tstamp.off_sec) { struct nfqnl_msg_packet_timestamp ts; - ts.sec = cpu_to_be64(entry->skb->tstamp.off_sec); - ts.usec = cpu_to_be64(entry->skb->tstamp.off_usec); + ts.sec = cpu_to_be64(entskb->tstamp.off_sec); + ts.usec = cpu_to_be64(entskb->tstamp.off_usec); NFA_PUT(skb, NFQA_TIMESTAMP, sizeof(ts), &ts); } @@ -510,7 +517,7 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue, nfa->nfa_type = NFQA_PAYLOAD; nfa->nfa_len = size; - if (skb_copy_bits(entry->skb, 0, NFA_DATA(nfa), data_len)) + if (skb_copy_bits(entskb, 0, NFA_DATA(nfa), data_len)) BUG(); } @@ -667,12 +674,14 @@ nfqnl_set_mode(struct nfqnl_instance *queue, static int dev_cmp(struct nfqnl_queue_entry *entry, unsigned long ifindex) { - if (entry->info->indev) - if (entry->info->indev->ifindex == ifindex) + struct nf_info *entinf = entry->info; + + if (entinf->indev) + if (entinf->indev->ifindex == ifindex) return 1; - if (entry->info->outdev) - if (entry->info->outdev->ifindex == ifindex) + if (entinf->outdev) + if (entinf->outdev->ifindex == ifindex) return 1; return 0; From d695aa8a1f133359485e15db06d53e15e7309e4d Mon Sep 17 00:00:00 2001 From: Jesper Juhl Date: Thu, 5 Jan 2006 12:16:16 -0800 Subject: [PATCH 04/48] [NETFILTER]: Decrease number of pointer derefs in nf_conntrack_core.c Benefits of the patch: - Fewer pointer dereferences should make the code slightly faster. - Size of generated code is smaller - improved readability Signed-off-by: Jesper Juhl Signed-off-by: Patrick McHardy Signed-off-by: David S. Miller --- net/netfilter/nf_conntrack_core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c index a7c7b490cf22..0c5b01d732d8 100644 --- a/net/netfilter/nf_conntrack_core.c +++ b/net/netfilter/nf_conntrack_core.c @@ -1129,6 +1129,7 @@ static inline int refresh_timer(struct nf_conntrack_expect *i) int nf_conntrack_expect_related(struct nf_conntrack_expect *expect) { struct nf_conntrack_expect *i; + struct nf_conn *master = expect->master; int ret; DEBUGP("nf_conntrack_expect_related %p\n", related_to); @@ -1149,9 +1150,9 @@ int nf_conntrack_expect_related(struct nf_conntrack_expect *expect) } } /* Will be over limit? */ - if (expect->master->helper->max_expected && - expect->master->expecting >= expect->master->helper->max_expected) - evict_oldest_expect(expect->master); + if (master->helper->max_expected && + master->expecting >= master->helper->max_expected) + evict_oldest_expect(master); nf_conntrack_expect_insert(expect); nf_conntrack_expect_event(IPEXP_NEW, expect); From 684f7b296c0cb8238ce63f1828d33a00d5f3a26e Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Thu, 5 Jan 2006 12:16:41 -0800 Subject: [PATCH 05/48] [NETFILTER]: ctnetlink: remove bogus checks in ICMP protocol at dumping Signed-off-by: Pablo Neira Ayuso Signed-off-by: Patrick McHardy Signed-off-by: David S. Miller --- net/ipv4/netfilter/ip_conntrack_proto_icmp.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/net/ipv4/netfilter/ip_conntrack_proto_icmp.c b/net/ipv4/netfilter/ip_conntrack_proto_icmp.c index 5f9925db608e..19cc55055584 100644 --- a/net/ipv4/netfilter/ip_conntrack_proto_icmp.c +++ b/net/ipv4/netfilter/ip_conntrack_proto_icmp.c @@ -279,10 +279,6 @@ static int icmp_tuple_to_nfattr(struct sk_buff *skb, NFA_PUT(skb, CTA_PROTO_ICMP_CODE, sizeof(u_int8_t), &t->dst.u.icmp.code); - if (t->dst.u.icmp.type >= sizeof(valid_new) - || !valid_new[t->dst.u.icmp.type]) - return -EINVAL; - return 0; nfattr_failure: From 90c4656eb4871c47a5d9fe7050590c9bb8b78b5a Mon Sep 17 00:00:00 2001 From: Yasuyuki Kozakai Date: Thu, 5 Jan 2006 12:17:03 -0800 Subject: [PATCH 06/48] [NETFILTER]: ctnetlink: Add sanity checkings for ICMP Signed-off-by: Yasuyuki Kozakai Signed-off-by: Patrick McHardy Signed-off-by: David S. Miller --- net/ipv4/netfilter/ip_conntrack_proto_icmp.c | 43 +++++++++++--------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/net/ipv4/netfilter/ip_conntrack_proto_icmp.c b/net/ipv4/netfilter/ip_conntrack_proto_icmp.c index 19cc55055584..30fc21d6165a 100644 --- a/net/ipv4/netfilter/ip_conntrack_proto_icmp.c +++ b/net/ipv4/netfilter/ip_conntrack_proto_icmp.c @@ -47,20 +47,21 @@ static int icmp_pkt_to_tuple(const struct sk_buff *skb, return 1; } +/* Add 1; spaces filled with 0. */ +static const u_int8_t invmap[] = { + [ICMP_ECHO] = ICMP_ECHOREPLY + 1, + [ICMP_ECHOREPLY] = ICMP_ECHO + 1, + [ICMP_TIMESTAMP] = ICMP_TIMESTAMPREPLY + 1, + [ICMP_TIMESTAMPREPLY] = ICMP_TIMESTAMP + 1, + [ICMP_INFO_REQUEST] = ICMP_INFO_REPLY + 1, + [ICMP_INFO_REPLY] = ICMP_INFO_REQUEST + 1, + [ICMP_ADDRESS] = ICMP_ADDRESSREPLY + 1, + [ICMP_ADDRESSREPLY] = ICMP_ADDRESS + 1 +}; + static int icmp_invert_tuple(struct ip_conntrack_tuple *tuple, const struct ip_conntrack_tuple *orig) { - /* Add 1; spaces filled with 0. */ - static const u_int8_t invmap[] - = { [ICMP_ECHO] = ICMP_ECHOREPLY + 1, - [ICMP_ECHOREPLY] = ICMP_ECHO + 1, - [ICMP_TIMESTAMP] = ICMP_TIMESTAMPREPLY + 1, - [ICMP_TIMESTAMPREPLY] = ICMP_TIMESTAMP + 1, - [ICMP_INFO_REQUEST] = ICMP_INFO_REPLY + 1, - [ICMP_INFO_REPLY] = ICMP_INFO_REQUEST + 1, - [ICMP_ADDRESS] = ICMP_ADDRESSREPLY + 1, - [ICMP_ADDRESSREPLY] = ICMP_ADDRESS + 1}; - if (orig->dst.u.icmp.type >= sizeof(invmap) || !invmap[orig->dst.u.icmp.type]) return 0; @@ -110,17 +111,17 @@ static int icmp_packet(struct ip_conntrack *ct, return NF_ACCEPT; } -static const u_int8_t valid_new[] = { - [ICMP_ECHO] = 1, - [ICMP_TIMESTAMP] = 1, - [ICMP_INFO_REQUEST] = 1, - [ICMP_ADDRESS] = 1 -}; - /* Called when a new connection for this protocol found. */ static int icmp_new(struct ip_conntrack *conntrack, const struct sk_buff *skb) { + static const u_int8_t valid_new[] = { + [ICMP_ECHO] = 1, + [ICMP_TIMESTAMP] = 1, + [ICMP_INFO_REQUEST] = 1, + [ICMP_ADDRESS] = 1 + }; + if (conntrack->tuplehash[0].tuple.dst.u.icmp.type >= sizeof(valid_new) || !valid_new[conntrack->tuplehash[0].tuple.dst.u.icmp.type]) { /* Can't create a new ICMP `conn' with this. */ @@ -291,7 +292,7 @@ static int icmp_nfattr_to_tuple(struct nfattr *tb[], if (!tb[CTA_PROTO_ICMP_TYPE-1] || !tb[CTA_PROTO_ICMP_CODE-1] || !tb[CTA_PROTO_ICMP_ID-1]) - return -1; + return -EINVAL; tuple->dst.u.icmp.type = *(u_int8_t *)NFA_DATA(tb[CTA_PROTO_ICMP_TYPE-1]); @@ -300,6 +301,10 @@ static int icmp_nfattr_to_tuple(struct nfattr *tb[], tuple->src.u.icmp.id = *(u_int16_t *)NFA_DATA(tb[CTA_PROTO_ICMP_ID-1]); + if (tuple->dst.u.icmp.type >= sizeof(invmap) + || !invmap[tuple->dst.u.icmp.type]) + return -EINVAL; + return 0; } #endif From 984955b3d7f9943becf9915601f49a1fb7a41f7a Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Thu, 5 Jan 2006 12:17:29 -0800 Subject: [PATCH 07/48] [NETFILTER]: ctnetlink: propagate ctnetlink_dump_tuples_proto return value back Signed-off-by: Pablo Neira Ayuso Signed-off-by: Patrick McHardy Signed-off-by: David S. Miller --- net/ipv4/netfilter/ip_conntrack_netlink.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/net/ipv4/netfilter/ip_conntrack_netlink.c b/net/ipv4/netfilter/ip_conntrack_netlink.c index 91fe8f2e38ff..5e9affdd0dbe 100644 --- a/net/ipv4/netfilter/ip_conntrack_netlink.c +++ b/net/ipv4/netfilter/ip_conntrack_netlink.c @@ -79,6 +79,7 @@ ctnetlink_dump_tuples(struct sk_buff *skb, const struct ip_conntrack_tuple *tuple) { struct nfattr *nest_parms; + int ret; nest_parms = NFA_NEST(skb, CTA_TUPLE_IP); NFA_PUT(skb, CTA_IP_V4_SRC, sizeof(u_int32_t), &tuple->src.ip); @@ -86,10 +87,10 @@ ctnetlink_dump_tuples(struct sk_buff *skb, NFA_NEST_END(skb, nest_parms); nest_parms = NFA_NEST(skb, CTA_TUPLE_PROTO); - ctnetlink_dump_tuples_proto(skb, tuple); + ret = ctnetlink_dump_tuples_proto(skb, tuple); NFA_NEST_END(skb, nest_parms); - return 0; + return ret; nfattr_failure: return -1; From 47116eb201571ad1198a8d76dc3571e85ba7c8c9 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Thu, 5 Jan 2006 12:17:50 -0800 Subject: [PATCH 08/48] [NETFILTER]: ctnetlink: use u_int32_t instead of unsigned int Signed-off-by: Pablo Neira Ayuso Signed-off-by: Patrick McHardy Signed-off-by: David S. Miller --- net/ipv4/netfilter/ip_conntrack_netlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/netfilter/ip_conntrack_netlink.c b/net/ipv4/netfilter/ip_conntrack_netlink.c index 5e9affdd0dbe..faa027ba687e 100644 --- a/net/ipv4/netfilter/ip_conntrack_netlink.c +++ b/net/ipv4/netfilter/ip_conntrack_netlink.c @@ -230,7 +230,7 @@ nfattr_failure: static inline int ctnetlink_dump_use(struct sk_buff *skb, const struct ip_conntrack *ct) { - unsigned int use = htonl(atomic_read(&ct->ct_general.use)); + u_int32_t use = htonl(atomic_read(&ct->ct_general.use)); NFA_PUT(skb, CTA_USE, sizeof(u_int32_t), &use); return 0; From 0368309cb45bbba99f84a01d5fc6a18780788480 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Thu, 5 Jan 2006 12:18:08 -0800 Subject: [PATCH 09/48] [NETFILTER]: ctnetlink: ctnetlink_event cleanup Cleanup: Use 'else if' instead of a ugly 'goto' statement. Signed-off-by: Pablo Neira Ayuso Signed-off-by: Patrick McHardy Signed-off-by: David S. Miller --- net/ipv4/netfilter/ip_conntrack_netlink.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/net/ipv4/netfilter/ip_conntrack_netlink.c b/net/ipv4/netfilter/ip_conntrack_netlink.c index faa027ba687e..04137d0c164c 100644 --- a/net/ipv4/netfilter/ip_conntrack_netlink.c +++ b/net/ipv4/netfilter/ip_conntrack_netlink.c @@ -312,29 +312,22 @@ static int ctnetlink_conntrack_event(struct notifier_block *this, if (events & IPCT_DESTROY) { type = IPCTNL_MSG_CT_DELETE; group = NFNLGRP_CONNTRACK_DESTROY; - goto alloc_skb; - } - if (events & (IPCT_NEW | IPCT_RELATED)) { + } else if (events & (IPCT_NEW | IPCT_RELATED)) { type = IPCTNL_MSG_CT_NEW; flags = NLM_F_CREATE|NLM_F_EXCL; /* dump everything */ events = ~0UL; group = NFNLGRP_CONNTRACK_NEW; - goto alloc_skb; - } - if (events & (IPCT_STATUS | + } else if (events & (IPCT_STATUS | IPCT_PROTOINFO | IPCT_HELPER | IPCT_HELPINFO | IPCT_NATINFO)) { type = IPCTNL_MSG_CT_NEW; group = NFNLGRP_CONNTRACK_UPDATE; - goto alloc_skb; - } + } else + return NOTIFY_DONE; - return NOTIFY_DONE; - -alloc_skb: /* FIXME: Check if there are any listeners before, don't hurt performance */ skb = alloc_skb(NLMSG_GOODSIZE, GFP_ATOMIC); From d4d6bb41e09f07668ca2655da707eab936e8e8f0 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Thu, 5 Jan 2006 12:18:25 -0800 Subject: [PATCH 10/48] [NETFILTER]: ctnetlink: fix conntrack mark race Set conntrack mark before it is in hashes. Signed-off-by: Pablo Neira Ayuso Signed-off-by: Patrick McHardy Signed-off-by: David S. Miller --- net/ipv4/netfilter/ip_conntrack_netlink.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/net/ipv4/netfilter/ip_conntrack_netlink.c b/net/ipv4/netfilter/ip_conntrack_netlink.c index 04137d0c164c..df04ad873cc2 100644 --- a/net/ipv4/netfilter/ip_conntrack_netlink.c +++ b/net/ipv4/netfilter/ip_conntrack_netlink.c @@ -1031,6 +1031,11 @@ ctnetlink_create_conntrack(struct nfattr *cda[], return err; } +#if defined(CONFIG_IP_NF_CONNTRACK_MARK) + if (cda[CTA_MARK-1]) + ct->mark = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_MARK-1])); +#endif + ct->helper = ip_conntrack_helper_find_get(rtuple); add_timer(&ct->timeout); @@ -1039,11 +1044,6 @@ ctnetlink_create_conntrack(struct nfattr *cda[], if (ct->helper) ip_conntrack_helper_put(ct->helper); -#if defined(CONFIG_IP_NF_CONNTRACK_MARK) - if (cda[CTA_MARK-1]) - ct->mark = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_MARK-1])); -#endif - DEBUGP("conntrack with id %u inserted\n", ct->id); return 0; From 205d67c7d942c057648148fefb17e46f77e3efd6 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Thu, 5 Jan 2006 12:18:44 -0800 Subject: [PATCH 11/48] [NETFILTER]: ctnetlink: remove unused variable Signed-off-by: Pablo Neira Ayuso Signed-off-by: Patrick McHardy Signed-off-by: David S. Miller --- net/ipv4/netfilter/ip_conntrack_netlink.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/net/ipv4/netfilter/ip_conntrack_netlink.c b/net/ipv4/netfilter/ip_conntrack_netlink.c index df04ad873cc2..703f2d2e3464 100644 --- a/net/ipv4/netfilter/ip_conntrack_netlink.c +++ b/net/ipv4/netfilter/ip_conntrack_netlink.c @@ -1203,7 +1203,6 @@ static int ctnetlink_expect_event(struct notifier_block *this, unsigned int type; unsigned char *b; int flags = 0; - u16 proto; if (events & IPEXP_NEW) { type = IPCTNL_MSG_EXP_NEW; @@ -1230,7 +1229,6 @@ static int ctnetlink_expect_event(struct notifier_block *this, goto nfattr_failure; nlh->nlmsg_len = skb->tail - b; - proto = exp->tuple.dst.protonum; nfnetlink_send(skb, 0, NFNLGRP_CONNTRACK_EXP_NEW, 0); return NOTIFY_DONE; From c1d10adb4a521de5760112853f42aaeefcec96eb Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Thu, 5 Jan 2006 12:19:05 -0800 Subject: [PATCH 12/48] [NETFILTER]: Add ctnetlink port for nf_conntrack Signed-off-by: Pablo Neira Ayuso Signed-off-by: Patrick McHardy Signed-off-by: David S. Miller --- include/linux/netfilter/nfnetlink_conntrack.h | 3 + include/net/netfilter/nf_conntrack.h | 31 + include/net/netfilter/nf_conntrack_helper.h | 2 + include/net/netfilter/nf_conntrack_l3proto.h | 15 +- include/net/netfilter/nf_conntrack_protocol.h | 26 +- .../netfilter/nf_conntrack_l3proto_ipv4.c | 47 + net/ipv4/netfilter/nf_conntrack_proto_icmp.c | 97 +- .../netfilter/nf_conntrack_l3proto_ipv6.c | 47 + .../netfilter/nf_conntrack_proto_icmpv6.c | 77 +- net/netfilter/Kconfig | 7 + net/netfilter/Makefile | 3 + net/netfilter/nf_conntrack_core.c | 232 ++- net/netfilter/nf_conntrack_netlink.c | 1642 +++++++++++++++++ net/netfilter/nf_conntrack_proto_tcp.c | 71 + net/netfilter/nf_conntrack_proto_udp.c | 10 + net/netfilter/nf_conntrack_standalone.c | 42 +- 16 files changed, 2289 insertions(+), 63 deletions(-) create mode 100644 net/netfilter/nf_conntrack_netlink.c diff --git a/include/linux/netfilter/nfnetlink_conntrack.h b/include/linux/netfilter/nfnetlink_conntrack.h index 116fcaced909..b8e9a5b6fb1e 100644 --- a/include/linux/netfilter/nfnetlink_conntrack.h +++ b/include/linux/netfilter/nfnetlink_conntrack.h @@ -64,6 +64,9 @@ enum ctattr_l4proto { CTA_PROTO_ICMP_ID, CTA_PROTO_ICMP_TYPE, CTA_PROTO_ICMP_CODE, + CTA_PROTO_ICMPV6_ID, + CTA_PROTO_ICMPV6_TYPE, + CTA_PROTO_ICMPV6_CODE, __CTA_PROTO_MAX }; #define CTA_PROTO_MAX (__CTA_PROTO_MAX - 1) diff --git a/include/net/netfilter/nf_conntrack.h b/include/net/netfilter/nf_conntrack.h index cc4825610795..64b82b74a650 100644 --- a/include/net/netfilter/nf_conntrack.h +++ b/include/net/netfilter/nf_conntrack.h @@ -94,6 +94,9 @@ struct nf_conn /* Current number of expected connections */ unsigned int expecting; + /* Unique ID that identifies this conntrack*/ + unsigned int id; + /* Helper. if any */ struct nf_conntrack_helper *helper; @@ -140,6 +143,9 @@ struct nf_conntrack_expect /* Usage count. */ atomic_t use; + /* Unique ID */ + unsigned int id; + /* Flags */ unsigned int flags; @@ -190,6 +196,31 @@ static inline void nf_ct_put(struct nf_conn *ct) nf_conntrack_put(&ct->ct_general); } +extern struct nf_conntrack_tuple_hash * +__nf_conntrack_find(const struct nf_conntrack_tuple *tuple, + const struct nf_conn *ignored_conntrack); + +extern void nf_conntrack_hash_insert(struct nf_conn *ct); + +extern struct nf_conntrack_expect * +__nf_conntrack_expect_find(const struct nf_conntrack_tuple *tuple); + +extern struct nf_conntrack_expect * +nf_conntrack_expect_find(const struct nf_conntrack_tuple *tuple); + +extern void nf_ct_unlink_expect(struct nf_conntrack_expect *exp); + +extern void nf_ct_remove_expectations(struct nf_conn *ct); + +extern void nf_conntrack_flush(void); + +extern struct nf_conntrack_helper * +nf_ct_helper_find_get( const struct nf_conntrack_tuple *tuple); +extern void nf_ct_helper_put(struct nf_conntrack_helper *helper); + +extern struct nf_conntrack_helper * +__nf_conntrack_helper_find_byname(const char *name); + /* call to create an explicit dependency on nf_conntrack. */ extern void need_nf_conntrack(void); diff --git a/include/net/netfilter/nf_conntrack_helper.h b/include/net/netfilter/nf_conntrack_helper.h index 5a66b2a3a623..86ec8174ad02 100644 --- a/include/net/netfilter/nf_conntrack_helper.h +++ b/include/net/netfilter/nf_conntrack_helper.h @@ -33,6 +33,8 @@ struct nf_conntrack_helper unsigned int protoff, struct nf_conn *ct, enum ip_conntrack_info conntrackinfo); + + int (*to_nfattr)(struct sk_buff *skb, const struct nf_conn *ct); }; extern int nf_conntrack_helper_register(struct nf_conntrack_helper *); diff --git a/include/net/netfilter/nf_conntrack_l3proto.h b/include/net/netfilter/nf_conntrack_l3proto.h index 01663e5b33df..67856eb93b43 100644 --- a/include/net/netfilter/nf_conntrack_l3proto.h +++ b/include/net/netfilter/nf_conntrack_l3proto.h @@ -14,6 +14,8 @@ #include #include +struct nfattr; + struct nf_conntrack_l3proto { /* Next pointer. */ @@ -70,6 +72,12 @@ struct nf_conntrack_l3proto u_int32_t (*get_features)(const struct nf_conntrack_tuple *tuple); + int (*tuple_to_nfattr)(struct sk_buff *skb, + const struct nf_conntrack_tuple *t); + + int (*nfattr_to_tuple)(struct nfattr *tb[], + struct nf_conntrack_tuple *t); + /* Module (if any) which this is connected to. */ struct module *me; }; @@ -81,11 +89,16 @@ extern int nf_conntrack_l3proto_register(struct nf_conntrack_l3proto *proto); extern void nf_conntrack_l3proto_unregister(struct nf_conntrack_l3proto *proto); static inline struct nf_conntrack_l3proto * -nf_ct_find_l3proto(u_int16_t l3proto) +__nf_ct_l3proto_find(u_int16_t l3proto) { return nf_ct_l3protos[l3proto]; } +extern struct nf_conntrack_l3proto * +nf_ct_l3proto_find_get(u_int16_t l3proto); + +extern void nf_ct_l3proto_put(struct nf_conntrack_l3proto *p); + /* Existing built-in protocols */ extern struct nf_conntrack_l3proto nf_conntrack_l3proto_ipv4; extern struct nf_conntrack_l3proto nf_conntrack_l3proto_ipv6; diff --git a/include/net/netfilter/nf_conntrack_protocol.h b/include/net/netfilter/nf_conntrack_protocol.h index b3afda35397a..1f33737fcea5 100644 --- a/include/net/netfilter/nf_conntrack_protocol.h +++ b/include/net/netfilter/nf_conntrack_protocol.h @@ -12,6 +12,7 @@ #include struct seq_file; +struct nfattr; struct nf_conntrack_protocol { @@ -66,6 +67,18 @@ struct nf_conntrack_protocol enum ip_conntrack_info *ctinfo, int pf, unsigned int hooknum); + /* convert protoinfo to nfnetink attributes */ + int (*to_nfattr)(struct sk_buff *skb, struct nfattr *nfa, + const struct nf_conn *ct); + + /* convert nfnetlink attributes to protoinfo */ + int (*from_nfattr)(struct nfattr *tb[], struct nf_conn *ct); + + int (*tuple_to_nfattr)(struct sk_buff *skb, + const struct nf_conntrack_tuple *t); + int (*nfattr_to_tuple)(struct nfattr *tb[], + struct nf_conntrack_tuple *t); + /* Module (if any) which this is connected to. */ struct module *me; }; @@ -80,12 +93,23 @@ extern struct nf_conntrack_protocol nf_conntrack_generic_protocol; extern struct nf_conntrack_protocol **nf_ct_protos[PF_MAX]; extern struct nf_conntrack_protocol * -nf_ct_find_proto(u_int16_t l3proto, u_int8_t protocol); +__nf_ct_proto_find(u_int16_t l3proto, u_int8_t protocol); + +extern struct nf_conntrack_protocol * +nf_ct_proto_find_get(u_int16_t l3proto, u_int8_t protocol); + +extern void nf_ct_proto_put(struct nf_conntrack_protocol *p); /* Protocol registration. */ extern int nf_conntrack_protocol_register(struct nf_conntrack_protocol *proto); extern void nf_conntrack_protocol_unregister(struct nf_conntrack_protocol *proto); +/* Generic netlink helpers */ +extern int nf_ct_port_tuple_to_nfattr(struct sk_buff *skb, + const struct nf_conntrack_tuple *tuple); +extern int nf_ct_port_nfattr_to_tuple(struct nfattr *tb[], + struct nf_conntrack_tuple *t); + /* Log invalid packets */ extern unsigned int nf_ct_log_invalid; diff --git a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c index 8202c1c0afad..385867efd481 100644 --- a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c +++ b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c @@ -392,6 +392,48 @@ getorigdst(struct sock *sk, int optval, void __user *user, int *len) return -ENOENT; } +#if defined(CONFIG_NF_CT_NETLINK) || \ + defined(CONFIG_NF_CT_NETLINK_MODULE) + +#include +#include + +static int ipv4_tuple_to_nfattr(struct sk_buff *skb, + const struct nf_conntrack_tuple *tuple) +{ + NFA_PUT(skb, CTA_IP_V4_SRC, sizeof(u_int32_t), + &tuple->src.u3.ip); + NFA_PUT(skb, CTA_IP_V4_DST, sizeof(u_int32_t), + &tuple->dst.u3.ip); + return 0; + +nfattr_failure: + return -1; +} + +static const size_t cta_min_ip[CTA_IP_MAX] = { + [CTA_IP_V4_SRC-1] = sizeof(u_int32_t), + [CTA_IP_V4_DST-1] = sizeof(u_int32_t), +}; + +static int ipv4_nfattr_to_tuple(struct nfattr *tb[], + struct nf_conntrack_tuple *t) +{ + if (!tb[CTA_IP_V4_SRC-1] || !tb[CTA_IP_V4_DST-1]) + return -EINVAL; + + if (nfattr_bad_size(tb, CTA_IP_MAX, cta_min_ip)) + return -EINVAL; + + t->src.u3.ip = + *(u_int32_t *)NFA_DATA(tb[CTA_IP_V4_SRC-1]); + t->dst.u3.ip = + *(u_int32_t *)NFA_DATA(tb[CTA_IP_V4_DST-1]); + + return 0; +} +#endif + static struct nf_sockopt_ops so_getorigdst = { .pf = PF_INET, .get_optmin = SO_ORIGINAL_DST, @@ -408,6 +450,11 @@ struct nf_conntrack_l3proto nf_conntrack_l3proto_ipv4 = { .print_conntrack = ipv4_print_conntrack, .prepare = ipv4_prepare, .get_features = ipv4_get_features, +#if defined(CONFIG_NF_CT_NETLINK) || \ + defined(CONFIG_NF_CT_NETLINK_MODULE) + .tuple_to_nfattr = ipv4_tuple_to_nfattr, + .nfattr_to_tuple = ipv4_nfattr_to_tuple, +#endif .me = THIS_MODULE, }; diff --git a/net/ipv4/netfilter/nf_conntrack_proto_icmp.c b/net/ipv4/netfilter/nf_conntrack_proto_icmp.c index 7ddb5c08f7b8..52dc175be39a 100644 --- a/net/ipv4/netfilter/nf_conntrack_proto_icmp.c +++ b/net/ipv4/netfilter/nf_conntrack_proto_icmp.c @@ -50,20 +50,21 @@ static int icmp_pkt_to_tuple(const struct sk_buff *skb, return 1; } +/* Add 1; spaces filled with 0. */ +static const u_int8_t invmap[] = { + [ICMP_ECHO] = ICMP_ECHOREPLY + 1, + [ICMP_ECHOREPLY] = ICMP_ECHO + 1, + [ICMP_TIMESTAMP] = ICMP_TIMESTAMPREPLY + 1, + [ICMP_TIMESTAMPREPLY] = ICMP_TIMESTAMP + 1, + [ICMP_INFO_REQUEST] = ICMP_INFO_REPLY + 1, + [ICMP_INFO_REPLY] = ICMP_INFO_REQUEST + 1, + [ICMP_ADDRESS] = ICMP_ADDRESSREPLY + 1, + [ICMP_ADDRESSREPLY] = ICMP_ADDRESS + 1 +}; + static int icmp_invert_tuple(struct nf_conntrack_tuple *tuple, const struct nf_conntrack_tuple *orig) { - /* Add 1; spaces filled with 0. */ - static u_int8_t invmap[] - = { [ICMP_ECHO] = ICMP_ECHOREPLY + 1, - [ICMP_ECHOREPLY] = ICMP_ECHO + 1, - [ICMP_TIMESTAMP] = ICMP_TIMESTAMPREPLY + 1, - [ICMP_TIMESTAMPREPLY] = ICMP_TIMESTAMP + 1, - [ICMP_INFO_REQUEST] = ICMP_INFO_REPLY + 1, - [ICMP_INFO_REPLY] = ICMP_INFO_REQUEST + 1, - [ICMP_ADDRESS] = ICMP_ADDRESSREPLY + 1, - [ICMP_ADDRESSREPLY] = ICMP_ADDRESS + 1}; - if (orig->dst.u.icmp.type >= sizeof(invmap) || !invmap[orig->dst.u.icmp.type]) return 0; @@ -120,11 +121,12 @@ static int icmp_packet(struct nf_conn *ct, static int icmp_new(struct nf_conn *conntrack, const struct sk_buff *skb, unsigned int dataoff) { - static u_int8_t valid_new[] - = { [ICMP_ECHO] = 1, - [ICMP_TIMESTAMP] = 1, - [ICMP_INFO_REQUEST] = 1, - [ICMP_ADDRESS] = 1 }; + static const u_int8_t valid_new[] = { + [ICMP_ECHO] = 1, + [ICMP_TIMESTAMP] = 1, + [ICMP_INFO_REQUEST] = 1, + [ICMP_ADDRESS] = 1 + }; if (conntrack->tuplehash[0].tuple.dst.u.icmp.type >= sizeof(valid_new) || !valid_new[conntrack->tuplehash[0].tuple.dst.u.icmp.type]) { @@ -168,7 +170,7 @@ icmp_error_message(struct sk_buff *skb, return -NF_ACCEPT; } - innerproto = nf_ct_find_proto(PF_INET, inside->ip.protocol); + innerproto = __nf_ct_proto_find(PF_INET, inside->ip.protocol); dataoff = skb->nh.iph->ihl*4 + sizeof(inside->icmp); /* Are they talking about one of our connections? */ if (!nf_ct_get_tuple(skb, dataoff, dataoff + inside->ip.ihl*4, PF_INET, @@ -281,6 +283,60 @@ checksum_skipped: return icmp_error_message(skb, ctinfo, hooknum); } +#if defined(CONFIG_NF_CT_NETLINK) || \ + defined(CONFIG_NF_CT_NETLINK_MODULE) + +#include +#include + +static int icmp_tuple_to_nfattr(struct sk_buff *skb, + const struct nf_conntrack_tuple *t) +{ + NFA_PUT(skb, CTA_PROTO_ICMP_ID, sizeof(u_int16_t), + &t->src.u.icmp.id); + NFA_PUT(skb, CTA_PROTO_ICMP_TYPE, sizeof(u_int8_t), + &t->dst.u.icmp.type); + NFA_PUT(skb, CTA_PROTO_ICMP_CODE, sizeof(u_int8_t), + &t->dst.u.icmp.code); + + return 0; + +nfattr_failure: + return -1; +} + +static const size_t cta_min_proto[CTA_PROTO_MAX] = { + [CTA_PROTO_ICMP_TYPE-1] = sizeof(u_int8_t), + [CTA_PROTO_ICMP_CODE-1] = sizeof(u_int8_t), + [CTA_PROTO_ICMP_ID-1] = sizeof(u_int16_t) +}; + +static int icmp_nfattr_to_tuple(struct nfattr *tb[], + struct nf_conntrack_tuple *tuple) +{ + if (!tb[CTA_PROTO_ICMP_TYPE-1] + || !tb[CTA_PROTO_ICMP_CODE-1] + || !tb[CTA_PROTO_ICMP_ID-1]) + return -EINVAL; + + if (nfattr_bad_size(tb, CTA_PROTO_MAX, cta_min_proto)) + return -EINVAL; + + tuple->dst.u.icmp.type = + *(u_int8_t *)NFA_DATA(tb[CTA_PROTO_ICMP_TYPE-1]); + tuple->dst.u.icmp.code = + *(u_int8_t *)NFA_DATA(tb[CTA_PROTO_ICMP_CODE-1]); + tuple->src.u.icmp.id = + *(u_int16_t *)NFA_DATA(tb[CTA_PROTO_ICMP_ID-1]); + + if (tuple->dst.u.icmp.type >= sizeof(invmap) + || !invmap[tuple->dst.u.icmp.type]) + return -EINVAL; + + return 0; +} +#endif + struct nf_conntrack_protocol nf_conntrack_protocol_icmp = { .list = { NULL, NULL }, @@ -295,7 +351,12 @@ struct nf_conntrack_protocol nf_conntrack_protocol_icmp = .new = icmp_new, .error = icmp_error, .destroy = NULL, - .me = NULL + .me = NULL, +#if defined(CONFIG_NF_CT_NETLINK) || \ + defined(CONFIG_NF_CT_NETLINK_MODULE) + .tuple_to_nfattr = icmp_tuple_to_nfattr, + .nfattr_to_tuple = icmp_nfattr_to_tuple, +#endif }; EXPORT_SYMBOL(nf_conntrack_protocol_icmp); diff --git a/net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c b/net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c index 753a3ae8502b..704fbbe74874 100644 --- a/net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c +++ b/net/ipv6/netfilter/nf_conntrack_l3proto_ipv6.c @@ -401,6 +401,48 @@ static ctl_table nf_ct_net_table[] = { }; #endif +#if defined(CONFIG_NF_CT_NETLINK) || \ + defined(CONFIG_NF_CT_NETLINK_MODULE) + +#include +#include + +static int ipv6_tuple_to_nfattr(struct sk_buff *skb, + const struct nf_conntrack_tuple *tuple) +{ + NFA_PUT(skb, CTA_IP_V6_SRC, sizeof(u_int32_t) * 4, + &tuple->src.u3.ip6); + NFA_PUT(skb, CTA_IP_V6_DST, sizeof(u_int32_t) * 4, + &tuple->dst.u3.ip6); + return 0; + +nfattr_failure: + return -1; +} + +static const size_t cta_min_ip[CTA_IP_MAX] = { + [CTA_IP_V6_SRC-1] = sizeof(u_int32_t)*4, + [CTA_IP_V6_DST-1] = sizeof(u_int32_t)*4, +}; + +static int ipv6_nfattr_to_tuple(struct nfattr *tb[], + struct nf_conntrack_tuple *t) +{ + if (!tb[CTA_IP_V6_SRC-1] || !tb[CTA_IP_V6_DST-1]) + return -EINVAL; + + if (nfattr_bad_size(tb, CTA_IP_MAX, cta_min_ip)) + return -EINVAL; + + memcpy(&t->src.u3.ip6, NFA_DATA(tb[CTA_IP_V6_SRC-1]), + sizeof(u_int32_t) * 4); + memcpy(&t->dst.u3.ip6, NFA_DATA(tb[CTA_IP_V6_DST-1]), + sizeof(u_int32_t) * 4); + + return 0; +} +#endif + struct nf_conntrack_l3proto nf_conntrack_l3proto_ipv6 = { .l3proto = PF_INET6, .name = "ipv6", @@ -409,6 +451,11 @@ struct nf_conntrack_l3proto nf_conntrack_l3proto_ipv6 = { .print_tuple = ipv6_print_tuple, .print_conntrack = ipv6_print_conntrack, .prepare = ipv6_prepare, +#if defined(CONFIG_NF_CT_NETLINK) || \ + defined(CONFIG_NF_CT_NETLINK_MODULE) + .tuple_to_nfattr = ipv6_tuple_to_nfattr, + .nfattr_to_tuple = ipv6_nfattr_to_tuple, +#endif .get_features = ipv6_get_features, .me = THIS_MODULE, }; diff --git a/net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c b/net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c index a7e03cfacd06..09945c333055 100644 --- a/net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c +++ b/net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c @@ -57,17 +57,17 @@ static int icmpv6_pkt_to_tuple(const struct sk_buff *skb, return 1; } +/* Add 1; spaces filled with 0. */ +static u_int8_t invmap[] = { + [ICMPV6_ECHO_REQUEST - 128] = ICMPV6_ECHO_REPLY + 1, + [ICMPV6_ECHO_REPLY - 128] = ICMPV6_ECHO_REQUEST + 1, + [ICMPV6_NI_QUERY - 128] = ICMPV6_NI_QUERY + 1, + [ICMPV6_NI_REPLY - 128] = ICMPV6_NI_REPLY +1 +}; + static int icmpv6_invert_tuple(struct nf_conntrack_tuple *tuple, const struct nf_conntrack_tuple *orig) { - /* Add 1; spaces filled with 0. */ - static u_int8_t invmap[] = { - [ICMPV6_ECHO_REQUEST - 128] = ICMPV6_ECHO_REPLY + 1, - [ICMPV6_ECHO_REPLY - 128] = ICMPV6_ECHO_REQUEST + 1, - [ICMPV6_NI_QUERY - 128] = ICMPV6_NI_QUERY + 1, - [ICMPV6_NI_REPLY - 128] = ICMPV6_NI_REPLY +1 - }; - int type = orig->dst.u.icmp.type - 128; if (type < 0 || type >= sizeof(invmap) || !invmap[type]) return 0; @@ -185,7 +185,7 @@ icmpv6_error_message(struct sk_buff *skb, return -NF_ACCEPT; } - inproto = nf_ct_find_proto(PF_INET6, inprotonum); + inproto = __nf_ct_proto_find(PF_INET6, inprotonum); /* Are they talking about one of our connections? */ if (!nf_ct_get_tuple(skb, inip6off, inprotoff, PF_INET6, inprotonum, @@ -255,6 +255,60 @@ skipped: return icmpv6_error_message(skb, dataoff, ctinfo, hooknum); } +#if defined(CONFIG_NF_CT_NETLINK) || \ + defined(CONFIG_NF_CT_NETLINK_MODULE) + +#include +#include +static int icmpv6_tuple_to_nfattr(struct sk_buff *skb, + const struct nf_conntrack_tuple *t) +{ + NFA_PUT(skb, CTA_PROTO_ICMPV6_ID, sizeof(u_int16_t), + &t->src.u.icmp.id); + NFA_PUT(skb, CTA_PROTO_ICMPV6_TYPE, sizeof(u_int8_t), + &t->dst.u.icmp.type); + NFA_PUT(skb, CTA_PROTO_ICMPV6_CODE, sizeof(u_int8_t), + &t->dst.u.icmp.code); + + return 0; + +nfattr_failure: + return -1; +} + +static const size_t cta_min_proto[CTA_PROTO_MAX] = { + [CTA_PROTO_ICMPV6_TYPE-1] = sizeof(u_int8_t), + [CTA_PROTO_ICMPV6_CODE-1] = sizeof(u_int8_t), + [CTA_PROTO_ICMPV6_ID-1] = sizeof(u_int16_t) +}; + +static int icmpv6_nfattr_to_tuple(struct nfattr *tb[], + struct nf_conntrack_tuple *tuple) +{ + if (!tb[CTA_PROTO_ICMPV6_TYPE-1] + || !tb[CTA_PROTO_ICMPV6_CODE-1] + || !tb[CTA_PROTO_ICMPV6_ID-1]) + return -EINVAL; + + if (nfattr_bad_size(tb, CTA_PROTO_MAX, cta_min_proto)) + return -EINVAL; + + tuple->dst.u.icmp.type = + *(u_int8_t *)NFA_DATA(tb[CTA_PROTO_ICMPV6_TYPE-1]); + tuple->dst.u.icmp.code = + *(u_int8_t *)NFA_DATA(tb[CTA_PROTO_ICMPV6_CODE-1]); + tuple->src.u.icmp.id = + *(u_int16_t *)NFA_DATA(tb[CTA_PROTO_ICMPV6_ID-1]); + + if (tuple->dst.u.icmp.type < 128 + || tuple->dst.u.icmp.type - 128 >= sizeof(invmap) + || !invmap[tuple->dst.u.icmp.type - 128]) + return -EINVAL; + + return 0; +} +#endif + struct nf_conntrack_protocol nf_conntrack_protocol_icmpv6 = { .l3proto = PF_INET6, @@ -267,6 +321,11 @@ struct nf_conntrack_protocol nf_conntrack_protocol_icmpv6 = .packet = icmpv6_packet, .new = icmpv6_new, .error = icmpv6_error, +#if defined(CONFIG_NF_CT_NETLINK) || \ + defined(CONFIG_NF_CT_NETLINK_MODULE) + .tuple_to_nfattr = icmpv6_tuple_to_nfattr, + .nfattr_to_tuple = icmpv6_nfattr_to_tuple, +#endif }; EXPORT_SYMBOL(nf_conntrack_protocol_icmpv6); diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig index 794c41d19b28..7d55f9cbd853 100644 --- a/net/netfilter/Kconfig +++ b/net/netfilter/Kconfig @@ -95,4 +95,11 @@ config NF_CONNTRACK_FTP To compile it as a module, choose M here. If unsure, say N. +config NF_CT_NETLINK + tristate 'Connection tracking netlink interface (EXPERIMENTAL)' + depends on EXPERIMENTAL && NF_CONNTRACK && NETFILTER_NETLINK + depends on NF_CONNTRACK!=y || NETFILTER_NETLINK!=m + help + This option enables support for a netlink-based userspace interface + endmenu diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile index 55f019ad2c08..cb2183145c37 100644 --- a/net/netfilter/Makefile +++ b/net/netfilter/Makefile @@ -13,3 +13,6 @@ obj-$(CONFIG_NF_CONNTRACK_FTP) += nf_conntrack_ftp.o # SCTP protocol connection tracking obj-$(CONFIG_NF_CT_PROTO_SCTP) += nf_conntrack_proto_sctp.o + +# netlink interface for nf_conntrack +obj-$(CONFIG_NF_CT_NETLINK) += nf_conntrack_netlink.o diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c index 0c5b01d732d8..62bb509f05d4 100644 --- a/net/netfilter/nf_conntrack_core.c +++ b/net/netfilter/nf_conntrack_core.c @@ -82,6 +82,8 @@ unsigned int nf_ct_log_invalid; static LIST_HEAD(unconfirmed); static int nf_conntrack_vmalloc; +static unsigned int nf_conntrack_next_id = 1; +static unsigned int nf_conntrack_expect_next_id = 1; #ifdef CONFIG_NF_CONNTRACK_EVENTS struct notifier_block *nf_conntrack_chain; struct notifier_block *nf_conntrack_expect_chain; @@ -184,7 +186,7 @@ DECLARE_MUTEX(nf_ct_cache_mutex); extern struct nf_conntrack_protocol nf_conntrack_generic_protocol; struct nf_conntrack_protocol * -nf_ct_find_proto(u_int16_t l3proto, u_int8_t protocol) +__nf_ct_proto_find(u_int16_t l3proto, u_int8_t protocol) { if (unlikely(nf_ct_protos[l3proto] == NULL)) return &nf_conntrack_generic_protocol; @@ -192,6 +194,50 @@ nf_ct_find_proto(u_int16_t l3proto, u_int8_t protocol) return nf_ct_protos[l3proto][protocol]; } +/* this is guaranteed to always return a valid protocol helper, since + * it falls back to generic_protocol */ +struct nf_conntrack_protocol * +nf_ct_proto_find_get(u_int16_t l3proto, u_int8_t protocol) +{ + struct nf_conntrack_protocol *p; + + preempt_disable(); + p = __nf_ct_proto_find(l3proto, protocol); + if (p) { + if (!try_module_get(p->me)) + p = &nf_conntrack_generic_protocol; + } + preempt_enable(); + + return p; +} + +void nf_ct_proto_put(struct nf_conntrack_protocol *p) +{ + module_put(p->me); +} + +struct nf_conntrack_l3proto * +nf_ct_l3proto_find_get(u_int16_t l3proto) +{ + struct nf_conntrack_l3proto *p; + + preempt_disable(); + p = __nf_ct_l3proto_find(l3proto); + if (p) { + if (!try_module_get(p->me)) + p = &nf_conntrack_generic_l3proto; + } + preempt_enable(); + + return p; +} + +void nf_ct_l3proto_put(struct nf_conntrack_l3proto *p) +{ + module_put(p->me); +} + static int nf_conntrack_hash_rnd_initted; static unsigned int nf_conntrack_hash_rnd; @@ -384,7 +430,7 @@ nf_ct_invert_tuple(struct nf_conntrack_tuple *inverse, } /* nf_conntrack_expect helper functions */ -static void nf_ct_unlink_expect(struct nf_conntrack_expect *exp) +void nf_ct_unlink_expect(struct nf_conntrack_expect *exp) { ASSERT_WRITE_LOCK(&nf_conntrack_lock); NF_CT_ASSERT(!timer_pending(&exp->timeout)); @@ -404,6 +450,33 @@ static void expectation_timed_out(unsigned long ul_expect) nf_conntrack_expect_put(exp); } +struct nf_conntrack_expect * +__nf_conntrack_expect_find(const struct nf_conntrack_tuple *tuple) +{ + struct nf_conntrack_expect *i; + + list_for_each_entry(i, &nf_conntrack_expect_list, list) { + if (nf_ct_tuple_mask_cmp(tuple, &i->tuple, &i->mask)) { + atomic_inc(&i->use); + return i; + } + } + return NULL; +} + +/* Just find a expectation corresponding to a tuple. */ +struct nf_conntrack_expect * +nf_conntrack_expect_find(const struct nf_conntrack_tuple *tuple) +{ + struct nf_conntrack_expect *i; + + read_lock_bh(&nf_conntrack_lock); + i = __nf_conntrack_expect_find(tuple); + read_unlock_bh(&nf_conntrack_lock); + + return i; +} + /* If an expectation for this connection is found, it gets delete from * global list then returned. */ static struct nf_conntrack_expect * @@ -432,7 +505,7 @@ find_expectation(const struct nf_conntrack_tuple *tuple) } /* delete all expectations for this conntrack */ -static void remove_expectations(struct nf_conn *ct) +void nf_ct_remove_expectations(struct nf_conn *ct) { struct nf_conntrack_expect *i, *tmp; @@ -462,7 +535,7 @@ clean_from_lists(struct nf_conn *ct) LIST_DELETE(&nf_conntrack_hash[hr], &ct->tuplehash[IP_CT_DIR_REPLY]); /* Destroy all pending expectations */ - remove_expectations(ct); + nf_ct_remove_expectations(ct); } static void @@ -482,12 +555,11 @@ destroy_conntrack(struct nf_conntrack *nfct) /* To make sure we don't get any weird locking issues here: * destroy_conntrack() MUST NOT be called with a write lock * to nf_conntrack_lock!!! -HW */ - l3proto = nf_ct_find_l3proto(ct->tuplehash[IP_CT_DIR_REPLY].tuple.src.l3num); + l3proto = __nf_ct_l3proto_find(ct->tuplehash[IP_CT_DIR_REPLY].tuple.src.l3num); if (l3proto && l3proto->destroy) l3proto->destroy(ct); - proto = nf_ct_find_proto(ct->tuplehash[IP_CT_DIR_REPLY].tuple.src.l3num, - ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.protonum); + proto = __nf_ct_proto_find(ct->tuplehash[IP_CT_DIR_REPLY].tuple.src.l3num, ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.protonum); if (proto && proto->destroy) proto->destroy(ct); @@ -499,7 +571,7 @@ destroy_conntrack(struct nf_conntrack *nfct) * except TFTP can create an expectation on the first packet, * before connection is in the list, so we need to clean here, * too. */ - remove_expectations(ct); + nf_ct_remove_expectations(ct); /* We overload first tuple to link into unconfirmed list. */ if (!nf_ct_is_confirmed(ct)) { @@ -540,7 +612,7 @@ conntrack_tuple_cmp(const struct nf_conntrack_tuple_hash *i, && nf_ct_tuple_equal(tuple, &i->tuple); } -static struct nf_conntrack_tuple_hash * +struct nf_conntrack_tuple_hash * __nf_conntrack_find(const struct nf_conntrack_tuple *tuple, const struct nf_conn *ignored_conntrack) { @@ -575,6 +647,29 @@ nf_conntrack_find_get(const struct nf_conntrack_tuple *tuple, return h; } +static void __nf_conntrack_hash_insert(struct nf_conn *ct, + unsigned int hash, + unsigned int repl_hash) +{ + ct->id = ++nf_conntrack_next_id; + list_prepend(&nf_conntrack_hash[hash], + &ct->tuplehash[IP_CT_DIR_ORIGINAL].list); + list_prepend(&nf_conntrack_hash[repl_hash], + &ct->tuplehash[IP_CT_DIR_REPLY].list); +} + +void nf_conntrack_hash_insert(struct nf_conn *ct) +{ + unsigned int hash, repl_hash; + + hash = hash_conntrack(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple); + repl_hash = hash_conntrack(&ct->tuplehash[IP_CT_DIR_REPLY].tuple); + + write_lock_bh(&nf_conntrack_lock); + __nf_conntrack_hash_insert(ct, hash, repl_hash); + write_unlock_bh(&nf_conntrack_lock); +} + /* Confirm a connection given skb; places it in hash table */ int __nf_conntrack_confirm(struct sk_buff **pskb) @@ -621,10 +716,7 @@ __nf_conntrack_confirm(struct sk_buff **pskb) /* Remove from unconfirmed list */ list_del(&ct->tuplehash[IP_CT_DIR_ORIGINAL].list); - list_prepend(&nf_conntrack_hash[hash], - &ct->tuplehash[IP_CT_DIR_ORIGINAL]); - list_prepend(&nf_conntrack_hash[repl_hash], - &ct->tuplehash[IP_CT_DIR_REPLY]); + __nf_conntrack_hash_insert(ct, hash, repl_hash); /* Timer relative to confirmation time, not original setting time, otherwise we'd get timer wrap in weird delay cases. */ @@ -708,13 +800,41 @@ static inline int helper_cmp(const struct nf_conntrack_helper *i, } static struct nf_conntrack_helper * -nf_ct_find_helper(const struct nf_conntrack_tuple *tuple) +__nf_ct_helper_find(const struct nf_conntrack_tuple *tuple) { return LIST_FIND(&helpers, helper_cmp, struct nf_conntrack_helper *, tuple); } +struct nf_conntrack_helper * +nf_ct_helper_find_get( const struct nf_conntrack_tuple *tuple) +{ + struct nf_conntrack_helper *helper; + + /* need nf_conntrack_lock to assure that helper exists until + * try_module_get() is called */ + read_lock_bh(&nf_conntrack_lock); + + helper = __nf_ct_helper_find(tuple); + if (helper) { + /* need to increase module usage count to assure helper will + * not go away while the caller is e.g. busy putting a + * conntrack in the hash that uses the helper */ + if (!try_module_get(helper->me)) + helper = NULL; + } + + read_unlock_bh(&nf_conntrack_lock); + + return helper; +} + +void nf_ct_helper_put(struct nf_conntrack_helper *helper) +{ + module_put(helper->me); +} + static struct nf_conn * __nf_conntrack_alloc(const struct nf_conntrack_tuple *orig, const struct nf_conntrack_tuple *repl, @@ -744,7 +864,7 @@ __nf_conntrack_alloc(const struct nf_conntrack_tuple *orig, /* find features needed by this conntrack. */ features = l3proto->get_features(orig); read_lock_bh(&nf_conntrack_lock); - if (nf_ct_find_helper(repl) != NULL) + if (__nf_ct_helper_find(repl) != NULL) features |= NF_CT_F_HELP; read_unlock_bh(&nf_conntrack_lock); @@ -794,7 +914,7 @@ struct nf_conn *nf_conntrack_alloc(const struct nf_conntrack_tuple *orig, { struct nf_conntrack_l3proto *l3proto; - l3proto = nf_ct_find_l3proto(orig->src.l3num); + l3proto = __nf_ct_l3proto_find(orig->src.l3num); return __nf_conntrack_alloc(orig, repl, l3proto); } @@ -853,7 +973,7 @@ init_conntrack(const struct nf_conntrack_tuple *tuple, nf_conntrack_get(&conntrack->master->ct_general); NF_CT_STAT_INC(expect_new); } else { - conntrack->helper = nf_ct_find_helper(&repl_tuple); + conntrack->helper = __nf_ct_helper_find(&repl_tuple); NF_CT_STAT_INC(new); } @@ -947,13 +1067,13 @@ nf_conntrack_in(int pf, unsigned int hooknum, struct sk_buff **pskb) return NF_ACCEPT; } - l3proto = nf_ct_find_l3proto((u_int16_t)pf); + l3proto = __nf_ct_l3proto_find((u_int16_t)pf); if ((ret = l3proto->prepare(pskb, hooknum, &dataoff, &protonum)) <= 0) { DEBUGP("not prepared to track yet or error occured\n"); return -ret; } - proto = nf_ct_find_proto((u_int16_t)pf, protonum); + proto = __nf_ct_proto_find((u_int16_t)pf, protonum); /* It may be an special packet, error, unclean... * inverse of the return code tells to the netfilter @@ -1002,9 +1122,9 @@ int nf_ct_invert_tuplepr(struct nf_conntrack_tuple *inverse, const struct nf_conntrack_tuple *orig) { return nf_ct_invert_tuple(inverse, orig, - nf_ct_find_l3proto(orig->src.l3num), - nf_ct_find_proto(orig->src.l3num, - orig->dst.protonum)); + __nf_ct_l3proto_find(orig->src.l3num), + __nf_ct_proto_find(orig->src.l3num, + orig->dst.protonum)); } /* Would two expected things clash? */ @@ -1096,6 +1216,7 @@ static void nf_conntrack_expect_insert(struct nf_conntrack_expect *exp) exp->timeout.expires = jiffies + exp->master->helper->timeout * HZ; add_timer(&exp->timeout); + exp->id = ++nf_conntrack_expect_next_id; atomic_inc(&exp->use); NF_CT_STAT_INC(expect_create); } @@ -1176,7 +1297,7 @@ void nf_conntrack_alter_reply(struct nf_conn *conntrack, conntrack->tuplehash[IP_CT_DIR_REPLY].tuple = *newreply; if (!conntrack->master && conntrack->expecting == 0) - conntrack->helper = nf_ct_find_helper(newreply); + conntrack->helper = __nf_ct_helper_find(newreply); write_unlock_bh(&nf_conntrack_lock); } @@ -1201,6 +1322,19 @@ int nf_conntrack_helper_register(struct nf_conntrack_helper *me) return 0; } +struct nf_conntrack_helper * +__nf_conntrack_helper_find_byname(const char *name) +{ + struct nf_conntrack_helper *h; + + list_for_each_entry(h, &helpers, list) { + if (!strcmp(h->name, name)) + return h; + } + + return NULL; +} + static inline int unhelp(struct nf_conntrack_tuple_hash *i, const struct nf_conntrack_helper *me) { @@ -1284,6 +1418,51 @@ void __nf_ct_refresh_acct(struct nf_conn *ct, nf_conntrack_event_cache(event, skb); } +#if defined(CONFIG_NF_CT_NETLINK) || \ + defined(CONFIG_NF_CT_NETLINK_MODULE) + +#include +#include + +/* Generic function for tcp/udp/sctp/dccp and alike. This needs to be + * in ip_conntrack_core, since we don't want the protocols to autoload + * or depend on ctnetlink */ +int nf_ct_port_tuple_to_nfattr(struct sk_buff *skb, + const struct nf_conntrack_tuple *tuple) +{ + NFA_PUT(skb, CTA_PROTO_SRC_PORT, sizeof(u_int16_t), + &tuple->src.u.tcp.port); + NFA_PUT(skb, CTA_PROTO_DST_PORT, sizeof(u_int16_t), + &tuple->dst.u.tcp.port); + return 0; + +nfattr_failure: + return -1; +} + +static const size_t cta_min_proto[CTA_PROTO_MAX] = { + [CTA_PROTO_SRC_PORT-1] = sizeof(u_int16_t), + [CTA_PROTO_DST_PORT-1] = sizeof(u_int16_t) +}; + +int nf_ct_port_nfattr_to_tuple(struct nfattr *tb[], + struct nf_conntrack_tuple *t) +{ + if (!tb[CTA_PROTO_SRC_PORT-1] || !tb[CTA_PROTO_DST_PORT-1]) + return -EINVAL; + + if (nfattr_bad_size(tb, CTA_PROTO_MAX, cta_min_proto)) + return -EINVAL; + + t->src.u.tcp.port = + *(u_int16_t *)NFA_DATA(tb[CTA_PROTO_SRC_PORT-1]); + t->dst.u.tcp.port = + *(u_int16_t *)NFA_DATA(tb[CTA_PROTO_DST_PORT-1]); + + return 0; +} +#endif + /* Used by ipt_REJECT and ip6t_REJECT. */ void __nf_conntrack_attach(struct sk_buff *nskb, struct sk_buff *skb) { @@ -1366,6 +1545,11 @@ static void free_conntrack_hash(struct list_head *hash, int vmalloced, int size) get_order(sizeof(struct list_head) * size)); } +void nf_conntrack_flush() +{ + nf_ct_iterate_cleanup(kill_all, NULL); +} + /* Mishearing the voices in his head, our hero wonders how he's supposed to kill the mall. */ void nf_conntrack_cleanup(void) @@ -1379,7 +1563,7 @@ void nf_conntrack_cleanup(void) nf_ct_event_cache_flush(); i_see_dead_people: - nf_ct_iterate_cleanup(kill_all, NULL); + nf_conntrack_flush(); if (atomic_read(&nf_conntrack_count) != 0) { schedule(); goto i_see_dead_people; diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c new file mode 100644 index 000000000000..4f2e50952a12 --- /dev/null +++ b/net/netfilter/nf_conntrack_netlink.c @@ -0,0 +1,1642 @@ +/* Connection tracking via netlink socket. Allows for user space + * protocol helpers and general trouble making from userspace. + * + * (C) 2001 by Jay Schulist + * (C) 2002-2005 by Harald Welte + * (C) 2003 by Patrick Mchardy + * (C) 2005 by Pablo Neira Ayuso + * + * I've reworked this stuff to use attributes instead of conntrack + * structures. 5.44 am. I need more tea. --pablo 05/07/11. + * + * Initial connection tracking via netlink development funded and + * generally made possible by Network Robots, Inc. (www.networkrobots.com) + * + * Further development of this code funded by Astaro AG (http://www.astaro.com) + * + * This software may be used and distributed according to the terms + * of the GNU General Public License, incorporated herein by reference. + * + * Derived from ip_conntrack_netlink.c: Port by Pablo Neira Ayuso (05/11/14) + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +MODULE_LICENSE("GPL"); + +static char __initdata version[] = "0.92"; + +#if 0 +#define DEBUGP printk +#else +#define DEBUGP(format, args...) +#endif + + +static inline int +ctnetlink_dump_tuples_proto(struct sk_buff *skb, + const struct nf_conntrack_tuple *tuple) +{ + struct nf_conntrack_protocol *proto; + int ret = 0; + + NFA_PUT(skb, CTA_PROTO_NUM, sizeof(u_int8_t), &tuple->dst.protonum); + + /* If no protocol helper is found, this function will return the + * generic protocol helper, so proto won't *ever* be NULL */ + proto = nf_ct_proto_find_get(tuple->src.l3num, tuple->dst.protonum); + if (likely(proto->tuple_to_nfattr)) + ret = proto->tuple_to_nfattr(skb, tuple); + + nf_ct_proto_put(proto); + + return ret; + +nfattr_failure: + return -1; +} + +static inline int +ctnetlink_dump_tuples(struct sk_buff *skb, + const struct nf_conntrack_tuple *tuple) +{ + struct nfattr *nest_parms; + struct nf_conntrack_l3proto *l3proto; + int ret = 0; + + l3proto = nf_ct_l3proto_find_get(tuple->src.l3num); + + nest_parms = NFA_NEST(skb, CTA_TUPLE_IP); + if (likely(l3proto->tuple_to_nfattr)) + ret = l3proto->tuple_to_nfattr(skb, tuple); + NFA_NEST_END(skb, nest_parms); + + nf_ct_l3proto_put(l3proto); + + if (unlikely(ret < 0)) + return ret; + + nest_parms = NFA_NEST(skb, CTA_TUPLE_PROTO); + ret = ctnetlink_dump_tuples_proto(skb, tuple); + NFA_NEST_END(skb, nest_parms); + + return ret; + +nfattr_failure: + return -1; +} + +static inline int +ctnetlink_dump_status(struct sk_buff *skb, const struct nf_conn *ct) +{ + u_int32_t status = htonl((u_int32_t) ct->status); + NFA_PUT(skb, CTA_STATUS, sizeof(status), &status); + return 0; + +nfattr_failure: + return -1; +} + +static inline int +ctnetlink_dump_timeout(struct sk_buff *skb, const struct nf_conn *ct) +{ + long timeout_l = ct->timeout.expires - jiffies; + u_int32_t timeout; + + if (timeout_l < 0) + timeout = 0; + else + timeout = htonl(timeout_l / HZ); + + NFA_PUT(skb, CTA_TIMEOUT, sizeof(timeout), &timeout); + return 0; + +nfattr_failure: + return -1; +} + +static inline int +ctnetlink_dump_protoinfo(struct sk_buff *skb, const struct nf_conn *ct) +{ + struct nf_conntrack_protocol *proto = nf_ct_proto_find_get(ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.l3num, ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum); + struct nfattr *nest_proto; + int ret; + + if (!proto->to_nfattr) { + nf_ct_proto_put(proto); + return 0; + } + + nest_proto = NFA_NEST(skb, CTA_PROTOINFO); + + ret = proto->to_nfattr(skb, nest_proto, ct); + + nf_ct_proto_put(proto); + + NFA_NEST_END(skb, nest_proto); + + return ret; + +nfattr_failure: + return -1; +} + +static inline int +ctnetlink_dump_helpinfo(struct sk_buff *skb, const struct nf_conn *ct) +{ + struct nfattr *nest_helper; + + if (!ct->helper) + return 0; + + nest_helper = NFA_NEST(skb, CTA_HELP); + NFA_PUT(skb, CTA_HELP_NAME, strlen(ct->helper->name), ct->helper->name); + + if (ct->helper->to_nfattr) + ct->helper->to_nfattr(skb, ct); + + NFA_NEST_END(skb, nest_helper); + + return 0; + +nfattr_failure: + return -1; +} + +#ifdef CONFIG_NF_CT_ACCT +static inline int +ctnetlink_dump_counters(struct sk_buff *skb, const struct nf_conn *ct, + enum ip_conntrack_dir dir) +{ + enum ctattr_type type = dir ? CTA_COUNTERS_REPLY: CTA_COUNTERS_ORIG; + struct nfattr *nest_count = NFA_NEST(skb, type); + u_int32_t tmp; + + tmp = htonl(ct->counters[dir].packets); + NFA_PUT(skb, CTA_COUNTERS32_PACKETS, sizeof(u_int32_t), &tmp); + + tmp = htonl(ct->counters[dir].bytes); + NFA_PUT(skb, CTA_COUNTERS32_BYTES, sizeof(u_int32_t), &tmp); + + NFA_NEST_END(skb, nest_count); + + return 0; + +nfattr_failure: + return -1; +} +#else +#define ctnetlink_dump_counters(a, b, c) (0) +#endif + +#ifdef CONFIG_NF_CONNTRACK_MARK +static inline int +ctnetlink_dump_mark(struct sk_buff *skb, const struct nf_conn *ct) +{ + u_int32_t mark = htonl(ct->mark); + + NFA_PUT(skb, CTA_MARK, sizeof(u_int32_t), &mark); + return 0; + +nfattr_failure: + return -1; +} +#else +#define ctnetlink_dump_mark(a, b) (0) +#endif + +static inline int +ctnetlink_dump_id(struct sk_buff *skb, const struct nf_conn *ct) +{ + u_int32_t id = htonl(ct->id); + NFA_PUT(skb, CTA_ID, sizeof(u_int32_t), &id); + return 0; + +nfattr_failure: + return -1; +} + +static inline int +ctnetlink_dump_use(struct sk_buff *skb, const struct nf_conn *ct) +{ + u_int32_t use = htonl(atomic_read(&ct->ct_general.use)); + + NFA_PUT(skb, CTA_USE, sizeof(u_int32_t), &use); + return 0; + +nfattr_failure: + return -1; +} + +#define tuple(ct, dir) (&(ct)->tuplehash[dir].tuple) + +static int +ctnetlink_fill_info(struct sk_buff *skb, u32 pid, u32 seq, + int event, int nowait, + const struct nf_conn *ct) +{ + struct nlmsghdr *nlh; + struct nfgenmsg *nfmsg; + struct nfattr *nest_parms; + unsigned char *b; + + b = skb->tail; + + event |= NFNL_SUBSYS_CTNETLINK << 8; + nlh = NLMSG_PUT(skb, pid, seq, event, sizeof(struct nfgenmsg)); + nfmsg = NLMSG_DATA(nlh); + + nlh->nlmsg_flags = (nowait && pid) ? NLM_F_MULTI : 0; + nfmsg->nfgen_family = + ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.l3num; + nfmsg->version = NFNETLINK_V0; + nfmsg->res_id = 0; + + nest_parms = NFA_NEST(skb, CTA_TUPLE_ORIG); + if (ctnetlink_dump_tuples(skb, tuple(ct, IP_CT_DIR_ORIGINAL)) < 0) + goto nfattr_failure; + NFA_NEST_END(skb, nest_parms); + + nest_parms = NFA_NEST(skb, CTA_TUPLE_REPLY); + if (ctnetlink_dump_tuples(skb, tuple(ct, IP_CT_DIR_REPLY)) < 0) + goto nfattr_failure; + NFA_NEST_END(skb, nest_parms); + + if (ctnetlink_dump_status(skb, ct) < 0 || + ctnetlink_dump_timeout(skb, ct) < 0 || + ctnetlink_dump_counters(skb, ct, IP_CT_DIR_ORIGINAL) < 0 || + ctnetlink_dump_counters(skb, ct, IP_CT_DIR_REPLY) < 0 || + ctnetlink_dump_protoinfo(skb, ct) < 0 || + ctnetlink_dump_helpinfo(skb, ct) < 0 || + ctnetlink_dump_mark(skb, ct) < 0 || + ctnetlink_dump_id(skb, ct) < 0 || + ctnetlink_dump_use(skb, ct) < 0) + goto nfattr_failure; + + nlh->nlmsg_len = skb->tail - b; + return skb->len; + +nlmsg_failure: +nfattr_failure: + skb_trim(skb, b - skb->data); + return -1; +} + +#ifdef CONFIG_NF_CONNTRACK_EVENTS +static int ctnetlink_conntrack_event(struct notifier_block *this, + unsigned long events, void *ptr) +{ + struct nlmsghdr *nlh; + struct nfgenmsg *nfmsg; + struct nfattr *nest_parms; + struct nf_conn *ct = (struct nf_conn *)ptr; + struct sk_buff *skb; + unsigned int type; + unsigned char *b; + unsigned int flags = 0, group; + + /* ignore our fake conntrack entry */ + if (ct == &nf_conntrack_untracked) + return NOTIFY_DONE; + + if (events & IPCT_DESTROY) { + type = IPCTNL_MSG_CT_DELETE; + group = NFNLGRP_CONNTRACK_DESTROY; + } else if (events & (IPCT_NEW | IPCT_RELATED)) { + type = IPCTNL_MSG_CT_NEW; + flags = NLM_F_CREATE|NLM_F_EXCL; + /* dump everything */ + events = ~0UL; + group = NFNLGRP_CONNTRACK_NEW; + } else if (events & (IPCT_STATUS | + IPCT_PROTOINFO | + IPCT_HELPER | + IPCT_HELPINFO | + IPCT_NATINFO)) { + type = IPCTNL_MSG_CT_NEW; + group = NFNLGRP_CONNTRACK_UPDATE; + } else + return NOTIFY_DONE; + + /* FIXME: Check if there are any listeners before, don't hurt performance */ + + skb = alloc_skb(NLMSG_GOODSIZE, GFP_ATOMIC); + if (!skb) + return NOTIFY_DONE; + + b = skb->tail; + + type |= NFNL_SUBSYS_CTNETLINK << 8; + nlh = NLMSG_PUT(skb, 0, 0, type, sizeof(struct nfgenmsg)); + nfmsg = NLMSG_DATA(nlh); + + nlh->nlmsg_flags = flags; + nfmsg->nfgen_family = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.l3num; + nfmsg->version = NFNETLINK_V0; + nfmsg->res_id = 0; + + nest_parms = NFA_NEST(skb, CTA_TUPLE_ORIG); + if (ctnetlink_dump_tuples(skb, tuple(ct, IP_CT_DIR_ORIGINAL)) < 0) + goto nfattr_failure; + NFA_NEST_END(skb, nest_parms); + + nest_parms = NFA_NEST(skb, CTA_TUPLE_REPLY); + if (ctnetlink_dump_tuples(skb, tuple(ct, IP_CT_DIR_REPLY)) < 0) + goto nfattr_failure; + NFA_NEST_END(skb, nest_parms); + + /* NAT stuff is now a status flag */ + if ((events & IPCT_STATUS || events & IPCT_NATINFO) + && ctnetlink_dump_status(skb, ct) < 0) + goto nfattr_failure; + if (events & IPCT_REFRESH + && ctnetlink_dump_timeout(skb, ct) < 0) + goto nfattr_failure; + if (events & IPCT_PROTOINFO + && ctnetlink_dump_protoinfo(skb, ct) < 0) + goto nfattr_failure; + if (events & IPCT_HELPINFO + && ctnetlink_dump_helpinfo(skb, ct) < 0) + goto nfattr_failure; + + if (ctnetlink_dump_counters(skb, ct, IP_CT_DIR_ORIGINAL) < 0 || + ctnetlink_dump_counters(skb, ct, IP_CT_DIR_REPLY) < 0) + goto nfattr_failure; + + nlh->nlmsg_len = skb->tail - b; + nfnetlink_send(skb, 0, group, 0); + return NOTIFY_DONE; + +nlmsg_failure: +nfattr_failure: + kfree_skb(skb); + return NOTIFY_DONE; +} +#endif /* CONFIG_NF_CONNTRACK_EVENTS */ + +static int ctnetlink_done(struct netlink_callback *cb) +{ + DEBUGP("entered %s\n", __FUNCTION__); + return 0; +} + +static int +ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb) +{ + struct nf_conn *ct = NULL; + struct nf_conntrack_tuple_hash *h; + struct list_head *i; + u_int32_t *id = (u_int32_t *) &cb->args[1]; + + DEBUGP("entered %s, last bucket=%lu id=%u\n", __FUNCTION__, + cb->args[0], *id); + + read_lock_bh(&nf_conntrack_lock); + for (; cb->args[0] < nf_conntrack_htable_size; cb->args[0]++, *id = 0) { + list_for_each_prev(i, &nf_conntrack_hash[cb->args[0]]) { + h = (struct nf_conntrack_tuple_hash *) i; + if (DIRECTION(h) != IP_CT_DIR_ORIGINAL) + continue; + ct = nf_ct_tuplehash_to_ctrack(h); + if (ct->id <= *id) + continue; + if (ctnetlink_fill_info(skb, NETLINK_CB(cb->skb).pid, + cb->nlh->nlmsg_seq, + IPCTNL_MSG_CT_NEW, + 1, ct) < 0) + goto out; + *id = ct->id; + } + } +out: + read_unlock_bh(&nf_conntrack_lock); + + DEBUGP("leaving, last bucket=%lu id=%u\n", cb->args[0], *id); + + return skb->len; +} + +#ifdef CONFIG_NF_CT_ACCT +static int +ctnetlink_dump_table_w(struct sk_buff *skb, struct netlink_callback *cb) +{ + struct nf_conn *ct = NULL; + struct nf_conntrack_tuple_hash *h; + struct list_head *i; + u_int32_t *id = (u_int32_t *) &cb->args[1]; + + DEBUGP("entered %s, last bucket=%u id=%u\n", __FUNCTION__, + cb->args[0], *id); + + write_lock_bh(&nf_conntrack_lock); + for (; cb->args[0] < nf_conntrack_htable_size; cb->args[0]++, *id = 0) { + list_for_each_prev(i, &nf_conntrack_hash[cb->args[0]]) { + h = (struct nf_conntrack_tuple_hash *) i; + if (DIRECTION(h) != IP_CT_DIR_ORIGINAL) + continue; + ct = nf_ct_tuplehash_to_ctrack(h); + if (ct->id <= *id) + continue; + if (ctnetlink_fill_info(skb, NETLINK_CB(cb->skb).pid, + cb->nlh->nlmsg_seq, + IPCTNL_MSG_CT_NEW, + 1, ct) < 0) + goto out; + *id = ct->id; + + memset(&ct->counters, 0, sizeof(ct->counters)); + } + } +out: + write_unlock_bh(&nf_conntrack_lock); + + DEBUGP("leaving, last bucket=%lu id=%u\n", cb->args[0], *id); + + return skb->len; +} +#endif + +static inline int +ctnetlink_parse_tuple_ip(struct nfattr *attr, struct nf_conntrack_tuple *tuple) +{ + struct nfattr *tb[CTA_IP_MAX]; + struct nf_conntrack_l3proto *l3proto; + int ret = 0; + + DEBUGP("entered %s\n", __FUNCTION__); + + nfattr_parse_nested(tb, CTA_IP_MAX, attr); + + l3proto = nf_ct_l3proto_find_get(tuple->src.l3num); + + if (likely(l3proto->nfattr_to_tuple)) + ret = l3proto->nfattr_to_tuple(tb, tuple); + + nf_ct_l3proto_put(l3proto); + + DEBUGP("leaving\n"); + + return ret; +} + +static const size_t cta_min_proto[CTA_PROTO_MAX] = { + [CTA_PROTO_NUM-1] = sizeof(u_int8_t), +}; + +static inline int +ctnetlink_parse_tuple_proto(struct nfattr *attr, + struct nf_conntrack_tuple *tuple) +{ + struct nfattr *tb[CTA_PROTO_MAX]; + struct nf_conntrack_protocol *proto; + int ret = 0; + + DEBUGP("entered %s\n", __FUNCTION__); + + nfattr_parse_nested(tb, CTA_PROTO_MAX, attr); + + if (nfattr_bad_size(tb, CTA_PROTO_MAX, cta_min_proto)) + return -EINVAL; + + if (!tb[CTA_PROTO_NUM-1]) + return -EINVAL; + tuple->dst.protonum = *(u_int8_t *)NFA_DATA(tb[CTA_PROTO_NUM-1]); + + proto = nf_ct_proto_find_get(tuple->src.l3num, tuple->dst.protonum); + + if (likely(proto->nfattr_to_tuple)) + ret = proto->nfattr_to_tuple(tb, tuple); + + nf_ct_proto_put(proto); + + return ret; +} + +static inline int +ctnetlink_parse_tuple(struct nfattr *cda[], struct nf_conntrack_tuple *tuple, + enum ctattr_tuple type, u_int8_t l3num) +{ + struct nfattr *tb[CTA_TUPLE_MAX]; + int err; + + DEBUGP("entered %s\n", __FUNCTION__); + + memset(tuple, 0, sizeof(*tuple)); + + nfattr_parse_nested(tb, CTA_TUPLE_MAX, cda[type-1]); + + if (!tb[CTA_TUPLE_IP-1]) + return -EINVAL; + + tuple->src.l3num = l3num; + + err = ctnetlink_parse_tuple_ip(tb[CTA_TUPLE_IP-1], tuple); + if (err < 0) + return err; + + if (!tb[CTA_TUPLE_PROTO-1]) + return -EINVAL; + + err = ctnetlink_parse_tuple_proto(tb[CTA_TUPLE_PROTO-1], tuple); + if (err < 0) + return err; + + /* orig and expect tuples get DIR_ORIGINAL */ + if (type == CTA_TUPLE_REPLY) + tuple->dst.dir = IP_CT_DIR_REPLY; + else + tuple->dst.dir = IP_CT_DIR_ORIGINAL; + + NF_CT_DUMP_TUPLE(tuple); + + DEBUGP("leaving\n"); + + return 0; +} + +#ifdef CONFIG_IP_NF_NAT_NEEDED +static const size_t cta_min_protonat[CTA_PROTONAT_MAX] = { + [CTA_PROTONAT_PORT_MIN-1] = sizeof(u_int16_t), + [CTA_PROTONAT_PORT_MAX-1] = sizeof(u_int16_t), +}; + +static int ctnetlink_parse_nat_proto(struct nfattr *attr, + const struct nf_conn *ct, + struct ip_nat_range *range) +{ + struct nfattr *tb[CTA_PROTONAT_MAX]; + struct ip_nat_protocol *npt; + + DEBUGP("entered %s\n", __FUNCTION__); + + nfattr_parse_nested(tb, CTA_PROTONAT_MAX, attr); + + if (nfattr_bad_size(tb, CTA_PROTONAT_MAX, cta_min_protonat)) + return -EINVAL; + + npt = ip_nat_proto_find_get(ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum); + + if (!npt->nfattr_to_range) { + ip_nat_proto_put(npt); + return 0; + } + + /* nfattr_to_range returns 1 if it parsed, 0 if not, neg. on error */ + if (npt->nfattr_to_range(tb, range) > 0) + range->flags |= IP_NAT_RANGE_PROTO_SPECIFIED; + + ip_nat_proto_put(npt); + + DEBUGP("leaving\n"); + return 0; +} + +static const size_t cta_min_nat[CTA_NAT_MAX] = { + [CTA_NAT_MINIP-1] = sizeof(u_int32_t), + [CTA_NAT_MAXIP-1] = sizeof(u_int32_t), +}; + +static inline int +ctnetlink_parse_nat(struct nfattr *cda[], + const struct nf_conn *ct, struct ip_nat_range *range) +{ + struct nfattr *tb[CTA_NAT_MAX]; + int err; + + DEBUGP("entered %s\n", __FUNCTION__); + + memset(range, 0, sizeof(*range)); + + nfattr_parse_nested(tb, CTA_NAT_MAX, cda[CTA_NAT-1]); + + if (nfattr_bad_size(tb, CTA_NAT_MAX, cta_min_nat)) + return -EINVAL; + + if (tb[CTA_NAT_MINIP-1]) + range->min_ip = *(u_int32_t *)NFA_DATA(tb[CTA_NAT_MINIP-1]); + + if (!tb[CTA_NAT_MAXIP-1]) + range->max_ip = range->min_ip; + else + range->max_ip = *(u_int32_t *)NFA_DATA(tb[CTA_NAT_MAXIP-1]); + + if (range->min_ip) + range->flags |= IP_NAT_RANGE_MAP_IPS; + + if (!tb[CTA_NAT_PROTO-1]) + return 0; + + err = ctnetlink_parse_nat_proto(tb[CTA_NAT_PROTO-1], ct, range); + if (err < 0) + return err; + + DEBUGP("leaving\n"); + return 0; +} +#endif + +static inline int +ctnetlink_parse_help(struct nfattr *attr, char **helper_name) +{ + struct nfattr *tb[CTA_HELP_MAX]; + + DEBUGP("entered %s\n", __FUNCTION__); + + nfattr_parse_nested(tb, CTA_HELP_MAX, attr); + + if (!tb[CTA_HELP_NAME-1]) + return -EINVAL; + + *helper_name = NFA_DATA(tb[CTA_HELP_NAME-1]); + + return 0; +} + +static const size_t cta_min[CTA_MAX] = { + [CTA_STATUS-1] = sizeof(u_int32_t), + [CTA_TIMEOUT-1] = sizeof(u_int32_t), + [CTA_MARK-1] = sizeof(u_int32_t), + [CTA_USE-1] = sizeof(u_int32_t), + [CTA_ID-1] = sizeof(u_int32_t) +}; + +static int +ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb, + struct nlmsghdr *nlh, struct nfattr *cda[], int *errp) +{ + struct nf_conntrack_tuple_hash *h; + struct nf_conntrack_tuple tuple; + struct nf_conn *ct; + struct nfgenmsg *nfmsg = NLMSG_DATA(nlh); + u_int8_t u3 = nfmsg->nfgen_family; + int err = 0; + + DEBUGP("entered %s\n", __FUNCTION__); + + if (nfattr_bad_size(cda, CTA_MAX, cta_min)) + return -EINVAL; + + if (cda[CTA_TUPLE_ORIG-1]) + err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_ORIG, u3); + else if (cda[CTA_TUPLE_REPLY-1]) + err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_REPLY, u3); + else { + /* Flush the whole table */ + nf_conntrack_flush(); + return 0; + } + + if (err < 0) + return err; + + h = nf_conntrack_find_get(&tuple, NULL); + if (!h) { + DEBUGP("tuple not found in conntrack hash\n"); + return -ENOENT; + } + + ct = nf_ct_tuplehash_to_ctrack(h); + + if (cda[CTA_ID-1]) { + u_int32_t id = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_ID-1])); + if (ct->id != id) { + nf_ct_put(ct); + return -ENOENT; + } + } + if (del_timer(&ct->timeout)) + ct->timeout.function((unsigned long)ct); + + nf_ct_put(ct); + DEBUGP("leaving\n"); + + return 0; +} + +static int +ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb, + struct nlmsghdr *nlh, struct nfattr *cda[], int *errp) +{ + struct nf_conntrack_tuple_hash *h; + struct nf_conntrack_tuple tuple; + struct nf_conn *ct; + struct sk_buff *skb2 = NULL; + struct nfgenmsg *nfmsg = NLMSG_DATA(nlh); + u_int8_t u3 = nfmsg->nfgen_family; + int err = 0; + + DEBUGP("entered %s\n", __FUNCTION__); + + if (nlh->nlmsg_flags & NLM_F_DUMP) { + u32 rlen; + + if (nfmsg->nfgen_family != AF_INET) + return -EAFNOSUPPORT; + + if (NFNL_MSG_TYPE(nlh->nlmsg_type) == + IPCTNL_MSG_CT_GET_CTRZERO) { +#ifdef CONFIG_NF_CT_ACCT + if ((*errp = netlink_dump_start(ctnl, skb, nlh, + ctnetlink_dump_table_w, + ctnetlink_done)) != 0) + return -EINVAL; +#else + return -ENOTSUPP; +#endif + } else { + if ((*errp = netlink_dump_start(ctnl, skb, nlh, + ctnetlink_dump_table, + ctnetlink_done)) != 0) + return -EINVAL; + } + + rlen = NLMSG_ALIGN(nlh->nlmsg_len); + if (rlen > skb->len) + rlen = skb->len; + skb_pull(skb, rlen); + return 0; + } + + if (nfattr_bad_size(cda, CTA_MAX, cta_min)) + return -EINVAL; + + if (cda[CTA_TUPLE_ORIG-1]) + err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_ORIG, u3); + else if (cda[CTA_TUPLE_REPLY-1]) + err = ctnetlink_parse_tuple(cda, &tuple, CTA_TUPLE_REPLY, u3); + else + return -EINVAL; + + if (err < 0) + return err; + + h = nf_conntrack_find_get(&tuple, NULL); + if (!h) { + DEBUGP("tuple not found in conntrack hash"); + return -ENOENT; + } + DEBUGP("tuple found\n"); + ct = nf_ct_tuplehash_to_ctrack(h); + + err = -ENOMEM; + skb2 = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL); + if (!skb2) { + nf_ct_put(ct); + return -ENOMEM; + } + NETLINK_CB(skb2).dst_pid = NETLINK_CB(skb).pid; + + err = ctnetlink_fill_info(skb2, NETLINK_CB(skb).pid, nlh->nlmsg_seq, + IPCTNL_MSG_CT_NEW, 1, ct); + nf_ct_put(ct); + if (err <= 0) + goto free; + + err = netlink_unicast(ctnl, skb2, NETLINK_CB(skb).pid, MSG_DONTWAIT); + if (err < 0) + goto out; + + DEBUGP("leaving\n"); + return 0; + +free: + kfree_skb(skb2); +out: + return err; +} + +static inline int +ctnetlink_change_status(struct nf_conn *ct, struct nfattr *cda[]) +{ + unsigned long d; + unsigned status = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_STATUS-1])); + d = ct->status ^ status; + + if (d & (IPS_EXPECTED|IPS_CONFIRMED|IPS_DYING)) + /* unchangeable */ + return -EINVAL; + + if (d & IPS_SEEN_REPLY && !(status & IPS_SEEN_REPLY)) + /* SEEN_REPLY bit can only be set */ + return -EINVAL; + + + if (d & IPS_ASSURED && !(status & IPS_ASSURED)) + /* ASSURED bit can only be set */ + return -EINVAL; + + if (cda[CTA_NAT-1]) { +#ifndef CONFIG_IP_NF_NAT_NEEDED + return -EINVAL; +#else + unsigned int hooknum; + struct ip_nat_range range; + + if (ctnetlink_parse_nat(cda, ct, &range) < 0) + return -EINVAL; + + DEBUGP("NAT: %u.%u.%u.%u-%u.%u.%u.%u:%u-%u\n", + NIPQUAD(range.min_ip), NIPQUAD(range.max_ip), + htons(range.min.all), htons(range.max.all)); + + /* This is tricky but it works. ip_nat_setup_info needs the + * hook number as parameter, so let's do the correct + * conversion and run away */ + if (status & IPS_SRC_NAT_DONE) + hooknum = NF_IP_POST_ROUTING; /* IP_NAT_MANIP_SRC */ + else if (status & IPS_DST_NAT_DONE) + hooknum = NF_IP_PRE_ROUTING; /* IP_NAT_MANIP_DST */ + else + return -EINVAL; /* Missing NAT flags */ + + DEBUGP("NAT status: %lu\n", + status & (IPS_NAT_MASK | IPS_NAT_DONE_MASK)); + + if (ip_nat_initialized(ct, HOOK2MANIP(hooknum))) + return -EEXIST; + ip_nat_setup_info(ct, &range, hooknum); + + DEBUGP("NAT status after setup_info: %lu\n", + ct->status & (IPS_NAT_MASK | IPS_NAT_DONE_MASK)); +#endif + } + + /* Be careful here, modifying NAT bits can screw up things, + * so don't let users modify them directly if they don't pass + * ip_nat_range. */ + ct->status |= status & ~(IPS_NAT_DONE_MASK | IPS_NAT_MASK); + return 0; +} + + +static inline int +ctnetlink_change_helper(struct nf_conn *ct, struct nfattr *cda[]) +{ + struct nf_conntrack_helper *helper; + char *helpname; + int err; + + DEBUGP("entered %s\n", __FUNCTION__); + + /* don't change helper of sibling connections */ + if (ct->master) + return -EINVAL; + + err = ctnetlink_parse_help(cda[CTA_HELP-1], &helpname); + if (err < 0) + return err; + + helper = __nf_conntrack_helper_find_byname(helpname); + if (!helper) { + if (!strcmp(helpname, "")) + helper = NULL; + else + return -EINVAL; + } + + if (ct->helper) { + if (!helper) { + /* we had a helper before ... */ + nf_ct_remove_expectations(ct); + ct->helper = NULL; + } else { + /* need to zero data of old helper */ + memset(&ct->help, 0, sizeof(ct->help)); + } + } + + ct->helper = helper; + + return 0; +} + +static inline int +ctnetlink_change_timeout(struct nf_conn *ct, struct nfattr *cda[]) +{ + u_int32_t timeout = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_TIMEOUT-1])); + + if (!del_timer(&ct->timeout)) + return -ETIME; + + ct->timeout.expires = jiffies + timeout * HZ; + add_timer(&ct->timeout); + + return 0; +} + +static inline int +ctnetlink_change_protoinfo(struct nf_conn *ct, struct nfattr *cda[]) +{ + struct nfattr *tb[CTA_PROTOINFO_MAX], *attr = cda[CTA_PROTOINFO-1]; + struct nf_conntrack_protocol *proto; + u_int16_t npt = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum; + u_int16_t l3num = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.l3num; + int err = 0; + + nfattr_parse_nested(tb, CTA_PROTOINFO_MAX, attr); + + proto = nf_ct_proto_find_get(l3num, npt); + + if (proto->from_nfattr) + err = proto->from_nfattr(tb, ct); + nf_ct_proto_put(proto); + + return err; +} + +static int +ctnetlink_change_conntrack(struct nf_conn *ct, struct nfattr *cda[]) +{ + int err; + + DEBUGP("entered %s\n", __FUNCTION__); + + if (cda[CTA_HELP-1]) { + err = ctnetlink_change_helper(ct, cda); + if (err < 0) + return err; + } + + if (cda[CTA_TIMEOUT-1]) { + err = ctnetlink_change_timeout(ct, cda); + if (err < 0) + return err; + } + + if (cda[CTA_STATUS-1]) { + err = ctnetlink_change_status(ct, cda); + if (err < 0) + return err; + } + + if (cda[CTA_PROTOINFO-1]) { + err = ctnetlink_change_protoinfo(ct, cda); + if (err < 0) + return err; + } + +#if defined(CONFIG_IP_NF_CONNTRACK_MARK) + if (cda[CTA_MARK-1]) + ct->mark = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_MARK-1])); +#endif + + DEBUGP("all done\n"); + return 0; +} + +static int +ctnetlink_create_conntrack(struct nfattr *cda[], + struct nf_conntrack_tuple *otuple, + struct nf_conntrack_tuple *rtuple) +{ + struct nf_conn *ct; + int err = -EINVAL; + + DEBUGP("entered %s\n", __FUNCTION__); + + ct = nf_conntrack_alloc(otuple, rtuple); + if (ct == NULL || IS_ERR(ct)) + return -ENOMEM; + + if (!cda[CTA_TIMEOUT-1]) + goto err; + ct->timeout.expires = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_TIMEOUT-1])); + + ct->timeout.expires = jiffies + ct->timeout.expires * HZ; + ct->status |= IPS_CONFIRMED; + + err = ctnetlink_change_status(ct, cda); + if (err < 0) + goto err; + + if (cda[CTA_PROTOINFO-1]) { + err = ctnetlink_change_protoinfo(ct, cda); + if (err < 0) + return err; + } + +#if defined(CONFIG_IP_NF_CONNTRACK_MARK) + if (cda[CTA_MARK-1]) + ct->mark = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_MARK-1])); +#endif + + ct->helper = nf_ct_helper_find_get(rtuple); + + add_timer(&ct->timeout); + nf_conntrack_hash_insert(ct); + + if (ct->helper) + nf_ct_helper_put(ct->helper); + + DEBUGP("conntrack with id %u inserted\n", ct->id); + return 0; + +err: + nf_conntrack_free(ct); + return err; +} + +static int +ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb, + struct nlmsghdr *nlh, struct nfattr *cda[], int *errp) +{ + struct nf_conntrack_tuple otuple, rtuple; + struct nf_conntrack_tuple_hash *h = NULL; + struct nfgenmsg *nfmsg = NLMSG_DATA(nlh); + u_int8_t u3 = nfmsg->nfgen_family; + int err = 0; + + DEBUGP("entered %s\n", __FUNCTION__); + + if (nfattr_bad_size(cda, CTA_MAX, cta_min)) + return -EINVAL; + + if (cda[CTA_TUPLE_ORIG-1]) { + err = ctnetlink_parse_tuple(cda, &otuple, CTA_TUPLE_ORIG, u3); + if (err < 0) + return err; + } + + if (cda[CTA_TUPLE_REPLY-1]) { + err = ctnetlink_parse_tuple(cda, &rtuple, CTA_TUPLE_REPLY, u3); + if (err < 0) + return err; + } + + write_lock_bh(&nf_conntrack_lock); + if (cda[CTA_TUPLE_ORIG-1]) + h = __nf_conntrack_find(&otuple, NULL); + else if (cda[CTA_TUPLE_REPLY-1]) + h = __nf_conntrack_find(&rtuple, NULL); + + if (h == NULL) { + write_unlock_bh(&nf_conntrack_lock); + DEBUGP("no such conntrack, create new\n"); + err = -ENOENT; + if (nlh->nlmsg_flags & NLM_F_CREATE) + err = ctnetlink_create_conntrack(cda, &otuple, &rtuple); + return err; + } + /* implicit 'else' */ + + /* we only allow nat config for new conntracks */ + if (cda[CTA_NAT-1]) { + err = -EINVAL; + goto out_unlock; + } + + /* We manipulate the conntrack inside the global conntrack table lock, + * so there's no need to increase the refcount */ + DEBUGP("conntrack found\n"); + err = -EEXIST; + if (!(nlh->nlmsg_flags & NLM_F_EXCL)) + err = ctnetlink_change_conntrack(nf_ct_tuplehash_to_ctrack(h), cda); + +out_unlock: + write_unlock_bh(&nf_conntrack_lock); + return err; +} + +/*********************************************************************** + * EXPECT + ***********************************************************************/ + +static inline int +ctnetlink_exp_dump_tuple(struct sk_buff *skb, + const struct nf_conntrack_tuple *tuple, + enum ctattr_expect type) +{ + struct nfattr *nest_parms = NFA_NEST(skb, type); + + if (ctnetlink_dump_tuples(skb, tuple) < 0) + goto nfattr_failure; + + NFA_NEST_END(skb, nest_parms); + + return 0; + +nfattr_failure: + return -1; +} + +static inline int +ctnetlink_exp_dump_expect(struct sk_buff *skb, + const struct nf_conntrack_expect *exp) +{ + struct nf_conn *master = exp->master; + u_int32_t timeout = htonl((exp->timeout.expires - jiffies) / HZ); + u_int32_t id = htonl(exp->id); + + if (ctnetlink_exp_dump_tuple(skb, &exp->tuple, CTA_EXPECT_TUPLE) < 0) + goto nfattr_failure; + if (ctnetlink_exp_dump_tuple(skb, &exp->mask, CTA_EXPECT_MASK) < 0) + goto nfattr_failure; + if (ctnetlink_exp_dump_tuple(skb, + &master->tuplehash[IP_CT_DIR_ORIGINAL].tuple, + CTA_EXPECT_MASTER) < 0) + goto nfattr_failure; + + NFA_PUT(skb, CTA_EXPECT_TIMEOUT, sizeof(timeout), &timeout); + NFA_PUT(skb, CTA_EXPECT_ID, sizeof(u_int32_t), &id); + + return 0; + +nfattr_failure: + return -1; +} + +static int +ctnetlink_exp_fill_info(struct sk_buff *skb, u32 pid, u32 seq, + int event, + int nowait, + const struct nf_conntrack_expect *exp) +{ + struct nlmsghdr *nlh; + struct nfgenmsg *nfmsg; + unsigned char *b; + + b = skb->tail; + + event |= NFNL_SUBSYS_CTNETLINK_EXP << 8; + nlh = NLMSG_PUT(skb, pid, seq, event, sizeof(struct nfgenmsg)); + nfmsg = NLMSG_DATA(nlh); + + nlh->nlmsg_flags = (nowait && pid) ? NLM_F_MULTI : 0; + nfmsg->nfgen_family = exp->tuple.src.l3num; + nfmsg->version = NFNETLINK_V0; + nfmsg->res_id = 0; + + if (ctnetlink_exp_dump_expect(skb, exp) < 0) + goto nfattr_failure; + + nlh->nlmsg_len = skb->tail - b; + return skb->len; + +nlmsg_failure: +nfattr_failure: + skb_trim(skb, b - skb->data); + return -1; +} + +#ifdef CONFIG_NF_CONNTRACK_EVENTS +static int ctnetlink_expect_event(struct notifier_block *this, + unsigned long events, void *ptr) +{ + struct nlmsghdr *nlh; + struct nfgenmsg *nfmsg; + struct nf_conntrack_expect *exp = (struct nf_conntrack_expect *)ptr; + struct sk_buff *skb; + unsigned int type; + unsigned char *b; + int flags = 0; + + if (events & IPEXP_NEW) { + type = IPCTNL_MSG_EXP_NEW; + flags = NLM_F_CREATE|NLM_F_EXCL; + } else + return NOTIFY_DONE; + + skb = alloc_skb(NLMSG_GOODSIZE, GFP_ATOMIC); + if (!skb) + return NOTIFY_DONE; + + b = skb->tail; + + type |= NFNL_SUBSYS_CTNETLINK << 8; + nlh = NLMSG_PUT(skb, 0, 0, type, sizeof(struct nfgenmsg)); + nfmsg = NLMSG_DATA(nlh); + + nlh->nlmsg_flags = flags; + nfmsg->nfgen_family = exp->tuple.src.l3num; + nfmsg->version = NFNETLINK_V0; + nfmsg->res_id = 0; + + if (ctnetlink_exp_dump_expect(skb, exp) < 0) + goto nfattr_failure; + + nlh->nlmsg_len = skb->tail - b; + nfnetlink_send(skb, 0, NFNLGRP_CONNTRACK_EXP_NEW, 0); + return NOTIFY_DONE; + +nlmsg_failure: +nfattr_failure: + kfree_skb(skb); + return NOTIFY_DONE; +} +#endif + +static int +ctnetlink_exp_dump_table(struct sk_buff *skb, struct netlink_callback *cb) +{ + struct nf_conntrack_expect *exp = NULL; + struct list_head *i; + u_int32_t *id = (u_int32_t *) &cb->args[0]; + + DEBUGP("entered %s, last id=%llu\n", __FUNCTION__, *id); + + read_lock_bh(&nf_conntrack_lock); + list_for_each_prev(i, &nf_conntrack_expect_list) { + exp = (struct nf_conntrack_expect *) i; + if (exp->id <= *id) + continue; + if (ctnetlink_exp_fill_info(skb, NETLINK_CB(cb->skb).pid, + cb->nlh->nlmsg_seq, + IPCTNL_MSG_EXP_NEW, + 1, exp) < 0) + goto out; + *id = exp->id; + } +out: + read_unlock_bh(&nf_conntrack_lock); + + DEBUGP("leaving, last id=%llu\n", *id); + + return skb->len; +} + +static const size_t cta_min_exp[CTA_EXPECT_MAX] = { + [CTA_EXPECT_TIMEOUT-1] = sizeof(u_int32_t), + [CTA_EXPECT_ID-1] = sizeof(u_int32_t) +}; + +static int +ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb, + struct nlmsghdr *nlh, struct nfattr *cda[], int *errp) +{ + struct nf_conntrack_tuple tuple; + struct nf_conntrack_expect *exp; + struct sk_buff *skb2; + struct nfgenmsg *nfmsg = NLMSG_DATA(nlh); + u_int8_t u3 = nfmsg->nfgen_family; + int err = 0; + + DEBUGP("entered %s\n", __FUNCTION__); + + if (nfattr_bad_size(cda, CTA_EXPECT_MAX, cta_min_exp)) + return -EINVAL; + + if (nlh->nlmsg_flags & NLM_F_DUMP) { + u32 rlen; + + if (nfmsg->nfgen_family != AF_INET) + return -EAFNOSUPPORT; + + if ((*errp = netlink_dump_start(ctnl, skb, nlh, + ctnetlink_exp_dump_table, + ctnetlink_done)) != 0) + return -EINVAL; + rlen = NLMSG_ALIGN(nlh->nlmsg_len); + if (rlen > skb->len) + rlen = skb->len; + skb_pull(skb, rlen); + return 0; + } + + if (cda[CTA_EXPECT_MASTER-1]) + err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_MASTER, u3); + else + return -EINVAL; + + if (err < 0) + return err; + + exp = nf_conntrack_expect_find(&tuple); + if (!exp) + return -ENOENT; + + if (cda[CTA_EXPECT_ID-1]) { + u_int32_t id = *(u_int32_t *)NFA_DATA(cda[CTA_EXPECT_ID-1]); + if (exp->id != ntohl(id)) { + nf_conntrack_expect_put(exp); + return -ENOENT; + } + } + + err = -ENOMEM; + skb2 = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL); + if (!skb2) + goto out; + NETLINK_CB(skb2).dst_pid = NETLINK_CB(skb).pid; + + err = ctnetlink_exp_fill_info(skb2, NETLINK_CB(skb).pid, + nlh->nlmsg_seq, IPCTNL_MSG_EXP_NEW, + 1, exp); + if (err <= 0) + goto free; + + nf_conntrack_expect_put(exp); + + return netlink_unicast(ctnl, skb2, NETLINK_CB(skb).pid, MSG_DONTWAIT); + +free: + kfree_skb(skb2); +out: + nf_conntrack_expect_put(exp); + return err; +} + +static int +ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb, + struct nlmsghdr *nlh, struct nfattr *cda[], int *errp) +{ + struct nf_conntrack_expect *exp, *tmp; + struct nf_conntrack_tuple tuple; + struct nf_conntrack_helper *h; + struct nfgenmsg *nfmsg = NLMSG_DATA(nlh); + u_int8_t u3 = nfmsg->nfgen_family; + int err; + + if (nfattr_bad_size(cda, CTA_EXPECT_MAX, cta_min_exp)) + return -EINVAL; + + if (cda[CTA_EXPECT_TUPLE-1]) { + /* delete a single expect by tuple */ + err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE, u3); + if (err < 0) + return err; + + /* bump usage count to 2 */ + exp = nf_conntrack_expect_find(&tuple); + if (!exp) + return -ENOENT; + + if (cda[CTA_EXPECT_ID-1]) { + u_int32_t id = + *(u_int32_t *)NFA_DATA(cda[CTA_EXPECT_ID-1]); + if (exp->id != ntohl(id)) { + nf_conntrack_expect_put(exp); + return -ENOENT; + } + } + + /* after list removal, usage count == 1 */ + nf_conntrack_unexpect_related(exp); + /* have to put what we 'get' above. + * after this line usage count == 0 */ + nf_conntrack_expect_put(exp); + } else if (cda[CTA_EXPECT_HELP_NAME-1]) { + char *name = NFA_DATA(cda[CTA_EXPECT_HELP_NAME-1]); + + /* delete all expectations for this helper */ + write_lock_bh(&nf_conntrack_lock); + h = __nf_conntrack_helper_find_byname(name); + if (!h) { + write_unlock_bh(&nf_conntrack_lock); + return -EINVAL; + } + list_for_each_entry_safe(exp, tmp, &nf_conntrack_expect_list, + list) { + if (exp->master->helper == h + && del_timer(&exp->timeout)) { + nf_ct_unlink_expect(exp); + nf_conntrack_expect_put(exp); + } + } + write_unlock_bh(&nf_conntrack_lock); + } else { + /* This basically means we have to flush everything*/ + write_lock_bh(&nf_conntrack_lock); + list_for_each_entry_safe(exp, tmp, &nf_conntrack_expect_list, + list) { + if (del_timer(&exp->timeout)) { + nf_ct_unlink_expect(exp); + nf_conntrack_expect_put(exp); + } + } + write_unlock_bh(&nf_conntrack_lock); + } + + return 0; +} +static int +ctnetlink_change_expect(struct nf_conntrack_expect *x, struct nfattr *cda[]) +{ + return -EOPNOTSUPP; +} + +static int +ctnetlink_create_expect(struct nfattr *cda[], u_int8_t u3) +{ + struct nf_conntrack_tuple tuple, mask, master_tuple; + struct nf_conntrack_tuple_hash *h = NULL; + struct nf_conntrack_expect *exp; + struct nf_conn *ct; + int err = 0; + + DEBUGP("entered %s\n", __FUNCTION__); + + /* caller guarantees that those three CTA_EXPECT_* exist */ + err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE, u3); + if (err < 0) + return err; + err = ctnetlink_parse_tuple(cda, &mask, CTA_EXPECT_MASK, u3); + if (err < 0) + return err; + err = ctnetlink_parse_tuple(cda, &master_tuple, CTA_EXPECT_MASTER, u3); + if (err < 0) + return err; + + /* Look for master conntrack of this expectation */ + h = nf_conntrack_find_get(&master_tuple, NULL); + if (!h) + return -ENOENT; + ct = nf_ct_tuplehash_to_ctrack(h); + + if (!ct->helper) { + /* such conntrack hasn't got any helper, abort */ + err = -EINVAL; + goto out; + } + + exp = nf_conntrack_expect_alloc(ct); + if (!exp) { + err = -ENOMEM; + goto out; + } + + exp->expectfn = NULL; + exp->flags = 0; + exp->master = ct; + memcpy(&exp->tuple, &tuple, sizeof(struct nf_conntrack_tuple)); + memcpy(&exp->mask, &mask, sizeof(struct nf_conntrack_tuple)); + + err = nf_conntrack_expect_related(exp); + nf_conntrack_expect_put(exp); + +out: + nf_ct_put(nf_ct_tuplehash_to_ctrack(h)); + return err; +} + +static int +ctnetlink_new_expect(struct sock *ctnl, struct sk_buff *skb, + struct nlmsghdr *nlh, struct nfattr *cda[], int *errp) +{ + struct nf_conntrack_tuple tuple; + struct nf_conntrack_expect *exp; + struct nfgenmsg *nfmsg = NLMSG_DATA(nlh); + u_int8_t u3 = nfmsg->nfgen_family; + int err = 0; + + DEBUGP("entered %s\n", __FUNCTION__); + + if (nfattr_bad_size(cda, CTA_EXPECT_MAX, cta_min_exp)) + return -EINVAL; + + if (!cda[CTA_EXPECT_TUPLE-1] + || !cda[CTA_EXPECT_MASK-1] + || !cda[CTA_EXPECT_MASTER-1]) + return -EINVAL; + + err = ctnetlink_parse_tuple(cda, &tuple, CTA_EXPECT_TUPLE, u3); + if (err < 0) + return err; + + write_lock_bh(&nf_conntrack_lock); + exp = __nf_conntrack_expect_find(&tuple); + + if (!exp) { + write_unlock_bh(&nf_conntrack_lock); + err = -ENOENT; + if (nlh->nlmsg_flags & NLM_F_CREATE) + err = ctnetlink_create_expect(cda, u3); + return err; + } + + err = -EEXIST; + if (!(nlh->nlmsg_flags & NLM_F_EXCL)) + err = ctnetlink_change_expect(exp, cda); + write_unlock_bh(&nf_conntrack_lock); + + DEBUGP("leaving\n"); + + return err; +} + +#ifdef CONFIG_NF_CONNTRACK_EVENTS +static struct notifier_block ctnl_notifier = { + .notifier_call = ctnetlink_conntrack_event, +}; + +static struct notifier_block ctnl_notifier_exp = { + .notifier_call = ctnetlink_expect_event, +}; +#endif + +static struct nfnl_callback ctnl_cb[IPCTNL_MSG_MAX] = { + [IPCTNL_MSG_CT_NEW] = { .call = ctnetlink_new_conntrack, + .attr_count = CTA_MAX, }, + [IPCTNL_MSG_CT_GET] = { .call = ctnetlink_get_conntrack, + .attr_count = CTA_MAX, }, + [IPCTNL_MSG_CT_DELETE] = { .call = ctnetlink_del_conntrack, + .attr_count = CTA_MAX, }, + [IPCTNL_MSG_CT_GET_CTRZERO] = { .call = ctnetlink_get_conntrack, + .attr_count = CTA_MAX, }, +}; + +static struct nfnl_callback ctnl_exp_cb[IPCTNL_MSG_EXP_MAX] = { + [IPCTNL_MSG_EXP_GET] = { .call = ctnetlink_get_expect, + .attr_count = CTA_EXPECT_MAX, }, + [IPCTNL_MSG_EXP_NEW] = { .call = ctnetlink_new_expect, + .attr_count = CTA_EXPECT_MAX, }, + [IPCTNL_MSG_EXP_DELETE] = { .call = ctnetlink_del_expect, + .attr_count = CTA_EXPECT_MAX, }, +}; + +static struct nfnetlink_subsystem ctnl_subsys = { + .name = "conntrack", + .subsys_id = NFNL_SUBSYS_CTNETLINK, + .cb_count = IPCTNL_MSG_MAX, + .cb = ctnl_cb, +}; + +static struct nfnetlink_subsystem ctnl_exp_subsys = { + .name = "conntrack_expect", + .subsys_id = NFNL_SUBSYS_CTNETLINK_EXP, + .cb_count = IPCTNL_MSG_EXP_MAX, + .cb = ctnl_exp_cb, +}; + +MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_CTNETLINK); + +static int __init ctnetlink_init(void) +{ + int ret; + + printk("ctnetlink v%s: registering with nfnetlink.\n", version); + ret = nfnetlink_subsys_register(&ctnl_subsys); + if (ret < 0) { + printk("ctnetlink_init: cannot register with nfnetlink.\n"); + goto err_out; + } + + ret = nfnetlink_subsys_register(&ctnl_exp_subsys); + if (ret < 0) { + printk("ctnetlink_init: cannot register exp with nfnetlink.\n"); + goto err_unreg_subsys; + } + +#ifdef CONFIG_NF_CONNTRACK_EVENTS + ret = nf_conntrack_register_notifier(&ctnl_notifier); + if (ret < 0) { + printk("ctnetlink_init: cannot register notifier.\n"); + goto err_unreg_exp_subsys; + } + + ret = nf_conntrack_expect_register_notifier(&ctnl_notifier_exp); + if (ret < 0) { + printk("ctnetlink_init: cannot expect register notifier.\n"); + goto err_unreg_notifier; + } +#endif + + return 0; + +#ifdef CONFIG_NF_CONNTRACK_EVENTS +err_unreg_notifier: + nf_conntrack_unregister_notifier(&ctnl_notifier); +err_unreg_exp_subsys: + nfnetlink_subsys_unregister(&ctnl_exp_subsys); +#endif +err_unreg_subsys: + nfnetlink_subsys_unregister(&ctnl_subsys); +err_out: + return ret; +} + +static void __exit ctnetlink_exit(void) +{ + printk("ctnetlink: unregistering from nfnetlink.\n"); + +#ifdef CONFIG_NF_CONNTRACK_EVENTS + nf_conntrack_unregister_notifier(&ctnl_notifier_exp); + nf_conntrack_unregister_notifier(&ctnl_notifier); +#endif + + nfnetlink_subsys_unregister(&ctnl_exp_subsys); + nfnetlink_subsys_unregister(&ctnl_subsys); + return; +} + +module_init(ctnetlink_init); +module_exit(ctnetlink_exit); diff --git a/net/netfilter/nf_conntrack_proto_tcp.c b/net/netfilter/nf_conntrack_proto_tcp.c index 6035633d8225..6167137a5cb5 100644 --- a/net/netfilter/nf_conntrack_proto_tcp.c +++ b/net/netfilter/nf_conntrack_proto_tcp.c @@ -1147,6 +1147,63 @@ static int tcp_new(struct nf_conn *conntrack, receiver->td_scale); return 1; } + +#if defined(CONFIG_NF_CT_NETLINK) || \ + defined(CONFIG_NF_CT_NETLINK_MODULE) + +#include +#include + +static int tcp_to_nfattr(struct sk_buff *skb, struct nfattr *nfa, + const struct nf_conn *ct) +{ + struct nfattr *nest_parms; + + read_lock_bh(&tcp_lock); + nest_parms = NFA_NEST(skb, CTA_PROTOINFO_TCP); + NFA_PUT(skb, CTA_PROTOINFO_TCP_STATE, sizeof(u_int8_t), + &ct->proto.tcp.state); + read_unlock_bh(&tcp_lock); + + NFA_NEST_END(skb, nest_parms); + + return 0; + +nfattr_failure: + read_unlock_bh(&tcp_lock); + return -1; +} + +static const size_t cta_min_tcp[CTA_PROTOINFO_TCP_MAX] = { + [CTA_PROTOINFO_TCP_STATE-1] = sizeof(u_int8_t), +}; + +static int nfattr_to_tcp(struct nfattr *cda[], struct nf_conn *ct) +{ + struct nfattr *attr = cda[CTA_PROTOINFO_TCP-1]; + struct nfattr *tb[CTA_PROTOINFO_TCP_MAX]; + + /* updates could not contain anything about the private + * protocol info, in that case skip the parsing */ + if (!attr) + return 0; + + nfattr_parse_nested(tb, CTA_PROTOINFO_TCP_MAX, attr); + + if (nfattr_bad_size(tb, CTA_PROTOINFO_TCP_MAX, cta_min_tcp)) + return -EINVAL; + + if (!tb[CTA_PROTOINFO_TCP_STATE-1]) + return -EINVAL; + + write_lock_bh(&tcp_lock); + ct->proto.tcp.state = + *(u_int8_t *)NFA_DATA(tb[CTA_PROTOINFO_TCP_STATE-1]); + write_unlock_bh(&tcp_lock); + + return 0; +} +#endif struct nf_conntrack_protocol nf_conntrack_protocol_tcp4 = { @@ -1160,6 +1217,13 @@ struct nf_conntrack_protocol nf_conntrack_protocol_tcp4 = .packet = tcp_packet, .new = tcp_new, .error = tcp_error4, +#if defined(CONFIG_NF_CT_NETLINK) || \ + defined(CONFIG_NF_CT_NETLINK_MODULE) + .to_nfattr = tcp_to_nfattr, + .from_nfattr = nfattr_to_tcp, + .tuple_to_nfattr = nf_ct_port_tuple_to_nfattr, + .nfattr_to_tuple = nf_ct_port_nfattr_to_tuple, +#endif }; struct nf_conntrack_protocol nf_conntrack_protocol_tcp6 = @@ -1174,6 +1238,13 @@ struct nf_conntrack_protocol nf_conntrack_protocol_tcp6 = .packet = tcp_packet, .new = tcp_new, .error = tcp_error6, +#if defined(CONFIG_NF_CT_NETLINK) || \ + defined(CONFIG_NF_CT_NETLINK_MODULE) + .to_nfattr = tcp_to_nfattr, + .from_nfattr = nfattr_to_tcp, + .tuple_to_nfattr = nf_ct_port_tuple_to_nfattr, + .nfattr_to_tuple = nf_ct_port_nfattr_to_tuple, +#endif }; EXPORT_SYMBOL(nf_conntrack_protocol_tcp4); diff --git a/net/netfilter/nf_conntrack_proto_udp.c b/net/netfilter/nf_conntrack_proto_udp.c index 3cae7ce420dd..1a592a556182 100644 --- a/net/netfilter/nf_conntrack_proto_udp.c +++ b/net/netfilter/nf_conntrack_proto_udp.c @@ -196,6 +196,11 @@ struct nf_conntrack_protocol nf_conntrack_protocol_udp4 = .packet = udp_packet, .new = udp_new, .error = udp_error4, +#if defined(CONFIG_NF_CT_NETLINK) || \ + defined(CONFIG_NF_CT_NETLINK_MODULE) + .tuple_to_nfattr = nf_ct_port_tuple_to_nfattr, + .nfattr_to_tuple = nf_ct_port_nfattr_to_tuple, +#endif }; struct nf_conntrack_protocol nf_conntrack_protocol_udp6 = @@ -210,6 +215,11 @@ struct nf_conntrack_protocol nf_conntrack_protocol_udp6 = .packet = udp_packet, .new = udp_new, .error = udp_error6, +#if defined(CONFIG_NF_CT_NETLINK) || \ + defined(CONFIG_NF_CT_NETLINK_MODULE) + .tuple_to_nfattr = nf_ct_port_tuple_to_nfattr, + .nfattr_to_tuple = nf_ct_port_nfattr_to_tuple, +#endif }; EXPORT_SYMBOL(nf_conntrack_protocol_udp4); diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c index 5af381f9fe3d..d17e42b28c79 100644 --- a/net/netfilter/nf_conntrack_standalone.c +++ b/net/netfilter/nf_conntrack_standalone.c @@ -161,14 +161,14 @@ static int ct_seq_show(struct seq_file *s, void *v) if (NF_CT_DIRECTION(hash)) return 0; - l3proto = nf_ct_find_l3proto(conntrack->tuplehash[IP_CT_DIR_ORIGINAL] - .tuple.src.l3num); + l3proto = __nf_ct_l3proto_find(conntrack->tuplehash[IP_CT_DIR_ORIGINAL] + .tuple.src.l3num); NF_CT_ASSERT(l3proto); - proto = nf_ct_find_proto(conntrack->tuplehash[IP_CT_DIR_ORIGINAL] - .tuple.src.l3num, - conntrack->tuplehash[IP_CT_DIR_ORIGINAL] - .tuple.dst.protonum); + proto = __nf_ct_proto_find(conntrack->tuplehash[IP_CT_DIR_ORIGINAL] + .tuple.src.l3num, + conntrack->tuplehash[IP_CT_DIR_ORIGINAL] + .tuple.dst.protonum); NF_CT_ASSERT(proto); if (seq_printf(s, "%-8s %u %-8s %u %ld ", @@ -307,9 +307,9 @@ static int exp_seq_show(struct seq_file *s, void *v) expect->tuple.src.l3num, expect->tuple.dst.protonum); print_tuple(s, &expect->tuple, - nf_ct_find_l3proto(expect->tuple.src.l3num), - nf_ct_find_proto(expect->tuple.src.l3num, - expect->tuple.dst.protonum)); + __nf_ct_l3proto_find(expect->tuple.src.l3num), + __nf_ct_proto_find(expect->tuple.src.l3num, + expect->tuple.dst.protonum)); return seq_putc(s, '\n'); } @@ -847,7 +847,11 @@ EXPORT_SYMBOL(nf_conntrack_helper_unregister); EXPORT_SYMBOL(nf_ct_iterate_cleanup); EXPORT_SYMBOL(__nf_ct_refresh_acct); EXPORT_SYMBOL(nf_ct_protos); -EXPORT_SYMBOL(nf_ct_find_proto); +EXPORT_SYMBOL(__nf_ct_proto_find); +EXPORT_SYMBOL(nf_ct_proto_find_get); +EXPORT_SYMBOL(nf_ct_proto_put); +EXPORT_SYMBOL(nf_ct_l3proto_find_get); +EXPORT_SYMBOL(nf_ct_l3proto_put); EXPORT_SYMBOL(nf_ct_l3protos); EXPORT_SYMBOL(nf_conntrack_expect_alloc); EXPORT_SYMBOL(nf_conntrack_expect_put); @@ -867,3 +871,21 @@ EXPORT_SYMBOL(nf_ct_get_tuple); EXPORT_SYMBOL(nf_ct_invert_tuple); EXPORT_SYMBOL(nf_conntrack_in); EXPORT_SYMBOL(__nf_conntrack_attach); +EXPORT_SYMBOL(nf_conntrack_alloc); +EXPORT_SYMBOL(nf_conntrack_free); +EXPORT_SYMBOL(nf_conntrack_flush); +EXPORT_SYMBOL(nf_ct_remove_expectations); +EXPORT_SYMBOL(nf_ct_helper_find_get); +EXPORT_SYMBOL(nf_ct_helper_put); +EXPORT_SYMBOL(__nf_conntrack_helper_find_byname); +EXPORT_SYMBOL(__nf_conntrack_find); +EXPORT_SYMBOL(nf_ct_unlink_expect); +EXPORT_SYMBOL(nf_conntrack_hash_insert); +EXPORT_SYMBOL(__nf_conntrack_expect_find); +EXPORT_SYMBOL(nf_conntrack_expect_find); +EXPORT_SYMBOL(nf_conntrack_expect_list); +#if defined(CONFIG_NF_CT_NETLINK) || \ + defined(CONFIG_NF_CT_NETLINK_MODULE) +EXPORT_SYMBOL(nf_ct_port_tuple_to_nfattr); +EXPORT_SYMBOL(nf_ct_port_nfattr_to_tuple); +#endif From 87711cb81c33e75fe8c95137fe62c8d462ff781c Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Thu, 5 Jan 2006 12:19:23 -0800 Subject: [PATCH 13/48] [NETFILTER]: Filter dumped entries based on the layer 3 protocol number Dump entries of a given Layer 3 protocol number. Signed-off-by: Pablo Neira Ayuso Signed-off-by: Patrick McHardy Signed-off-by: David S. Miller --- net/netfilter/nf_conntrack_netlink.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c index 4f2e50952a12..73ab16bc7d40 100644 --- a/net/netfilter/nf_conntrack_netlink.c +++ b/net/netfilter/nf_conntrack_netlink.c @@ -400,6 +400,8 @@ static int ctnetlink_done(struct netlink_callback *cb) return 0; } +#define L3PROTO(ct) ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.l3num + static int ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb) { @@ -407,6 +409,8 @@ ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb) struct nf_conntrack_tuple_hash *h; struct list_head *i; u_int32_t *id = (u_int32_t *) &cb->args[1]; + struct nfgenmsg *nfmsg = NLMSG_DATA(cb->nlh); + u_int8_t l3proto = nfmsg->nfgen_family; DEBUGP("entered %s, last bucket=%lu id=%u\n", __FUNCTION__, cb->args[0], *id); @@ -418,6 +422,11 @@ ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb) if (DIRECTION(h) != IP_CT_DIR_ORIGINAL) continue; ct = nf_ct_tuplehash_to_ctrack(h); + /* Dump entries of a given L3 protocol number. + * If it is not specified, ie. l3proto == 0, + * then dump everything. */ + if (l3proto && L3PROTO(ct) != l3proto) + continue; if (ct->id <= *id) continue; if (ctnetlink_fill_info(skb, NETLINK_CB(cb->skb).pid, @@ -444,6 +453,8 @@ ctnetlink_dump_table_w(struct sk_buff *skb, struct netlink_callback *cb) struct nf_conntrack_tuple_hash *h; struct list_head *i; u_int32_t *id = (u_int32_t *) &cb->args[1]; + struct nfgenmsg *nfmsg = NLMSG_DATA(cb->nlh); + u_int8_t l3proto = nfmsg->nfgen_family; DEBUGP("entered %s, last bucket=%u id=%u\n", __FUNCTION__, cb->args[0], *id); @@ -455,6 +466,8 @@ ctnetlink_dump_table_w(struct sk_buff *skb, struct netlink_callback *cb) if (DIRECTION(h) != IP_CT_DIR_ORIGINAL) continue; ct = nf_ct_tuplehash_to_ctrack(h); + if (l3proto && L3PROTO(ct) != l3proto) + continue; if (ct->id <= *id) continue; if (ctnetlink_fill_info(skb, NETLINK_CB(cb->skb).pid, @@ -750,9 +763,6 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb, if (nlh->nlmsg_flags & NLM_F_DUMP) { u32 rlen; - if (nfmsg->nfgen_family != AF_INET) - return -EAFNOSUPPORT; - if (NFNL_MSG_TYPE(nlh->nlmsg_type) == IPCTNL_MSG_CT_GET_CTRZERO) { #ifdef CONFIG_NF_CT_ACCT @@ -1251,12 +1261,16 @@ ctnetlink_exp_dump_table(struct sk_buff *skb, struct netlink_callback *cb) struct nf_conntrack_expect *exp = NULL; struct list_head *i; u_int32_t *id = (u_int32_t *) &cb->args[0]; + struct nfgenmsg *nfmsg = NLMSG_DATA(cb->nlh); + u_int8_t l3proto = nfmsg->nfgen_family; DEBUGP("entered %s, last id=%llu\n", __FUNCTION__, *id); read_lock_bh(&nf_conntrack_lock); list_for_each_prev(i, &nf_conntrack_expect_list) { exp = (struct nf_conntrack_expect *) i; + if (l3proto && exp->tuple.src.l3num != l3proto) + continue; if (exp->id <= *id) continue; if (ctnetlink_exp_fill_info(skb, NETLINK_CB(cb->skb).pid, @@ -1298,9 +1312,6 @@ ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb, if (nlh->nlmsg_flags & NLM_F_DUMP) { u32 rlen; - if (nfmsg->nfgen_family != AF_INET) - return -EAFNOSUPPORT; - if ((*errp = netlink_dump_start(ctnl, skb, nlh, ctnetlink_exp_dump_table, ctnetlink_done)) != 0) From e7be6994ec68c38d8e23e647eac649b280c4fe5a Mon Sep 17 00:00:00 2001 From: Patrick McHardy Date: Thu, 5 Jan 2006 12:19:46 -0800 Subject: [PATCH 14/48] [NETFILTER]: Fix module_param types and permissions Fix netfilter module_param types and permissions. Also fix an off-by-one in the ipt_ULOG nlbufsiz < 128k check. Signed-off-by: Patrick McHardy Signed-off-by: David S. Miller --- net/ipv4/netfilter/ip_conntrack_amanda.c | 2 +- net/ipv4/netfilter/ip_conntrack_ftp.c | 2 +- net/ipv4/netfilter/ip_conntrack_irc.c | 10 +++------- net/ipv4/netfilter/ip_conntrack_netbios_ns.c | 2 +- net/ipv4/netfilter/ipt_ULOG.c | 10 +++++----- net/ipv4/netfilter/ipt_recent.c | 20 ++++++++++---------- net/netfilter/nf_conntrack_ftp.c | 2 +- 7 files changed, 22 insertions(+), 26 deletions(-) diff --git a/net/ipv4/netfilter/ip_conntrack_amanda.c b/net/ipv4/netfilter/ip_conntrack_amanda.c index 0366eedb4d70..84e4f79b7ffa 100644 --- a/net/ipv4/netfilter/ip_conntrack_amanda.c +++ b/net/ipv4/netfilter/ip_conntrack_amanda.c @@ -36,7 +36,7 @@ static unsigned int master_timeout = 300; MODULE_AUTHOR("Brian J. Murrell "); MODULE_DESCRIPTION("Amanda connection tracking module"); MODULE_LICENSE("GPL"); -module_param(master_timeout, int, 0600); +module_param(master_timeout, uint, 0600); MODULE_PARM_DESC(master_timeout, "timeout for the master connection"); static const char *conns[] = { "DATA ", "MESG ", "INDEX " }; diff --git a/net/ipv4/netfilter/ip_conntrack_ftp.c b/net/ipv4/netfilter/ip_conntrack_ftp.c index 68b173bcda60..e627e5856172 100644 --- a/net/ipv4/netfilter/ip_conntrack_ftp.c +++ b/net/ipv4/netfilter/ip_conntrack_ftp.c @@ -34,7 +34,7 @@ static int ports_c; module_param_array(ports, ushort, &ports_c, 0400); static int loose; -module_param(loose, int, 0600); +module_param(loose, bool, 0600); unsigned int (*ip_nat_ftp_hook)(struct sk_buff **pskb, enum ip_conntrack_info ctinfo, diff --git a/net/ipv4/netfilter/ip_conntrack_irc.c b/net/ipv4/netfilter/ip_conntrack_irc.c index d7c40421d0d1..c51a2cf71b4b 100644 --- a/net/ipv4/netfilter/ip_conntrack_irc.c +++ b/net/ipv4/netfilter/ip_conntrack_irc.c @@ -36,7 +36,7 @@ #define MAX_PORTS 8 static unsigned short ports[MAX_PORTS]; static int ports_c; -static int max_dcc_channels = 8; +static unsigned int max_dcc_channels = 8; static unsigned int dcc_timeout = 300; /* This is slow, but it's simple. --RR */ static char *irc_buffer; @@ -54,9 +54,9 @@ MODULE_DESCRIPTION("IRC (DCC) connection tracking helper"); MODULE_LICENSE("GPL"); module_param_array(ports, ushort, &ports_c, 0400); MODULE_PARM_DESC(ports, "port numbers of IRC servers"); -module_param(max_dcc_channels, int, 0400); +module_param(max_dcc_channels, uint, 0400); MODULE_PARM_DESC(max_dcc_channels, "max number of expected DCC channels per IRC session"); -module_param(dcc_timeout, int, 0400); +module_param(dcc_timeout, uint, 0400); MODULE_PARM_DESC(dcc_timeout, "timeout on for unestablished DCC channels"); static const char *dccprotos[] = { "SEND ", "CHAT ", "MOVE ", "TSEND ", "SCHAT " }; @@ -254,10 +254,6 @@ static int __init init(void) printk("ip_conntrack_irc: max_dcc_channels must be a positive integer\n"); return -EBUSY; } - if (dcc_timeout < 0) { - printk("ip_conntrack_irc: dcc_timeout must be a positive integer\n"); - return -EBUSY; - } irc_buffer = kmalloc(65536, GFP_KERNEL); if (!irc_buffer) diff --git a/net/ipv4/netfilter/ip_conntrack_netbios_ns.c b/net/ipv4/netfilter/ip_conntrack_netbios_ns.c index 186646eb249f..4e68e16a2612 100644 --- a/net/ipv4/netfilter/ip_conntrack_netbios_ns.c +++ b/net/ipv4/netfilter/ip_conntrack_netbios_ns.c @@ -37,7 +37,7 @@ MODULE_DESCRIPTION("NetBIOS name service broadcast connection tracking helper"); MODULE_LICENSE("GPL"); static unsigned int timeout = 3; -module_param(timeout, int, 0600); +module_param(timeout, uint, 0400); MODULE_PARM_DESC(timeout, "timeout for master connection/replies in seconds"); static int help(struct sk_buff **pskb, diff --git a/net/ipv4/netfilter/ipt_ULOG.c b/net/ipv4/netfilter/ipt_ULOG.c index 2883ccd8a91d..38641cd06123 100644 --- a/net/ipv4/netfilter/ipt_ULOG.c +++ b/net/ipv4/netfilter/ipt_ULOG.c @@ -77,15 +77,15 @@ MODULE_ALIAS_NET_PF_PROTO(PF_NETLINK, NETLINK_NFLOG); #define PRINTR(format, args...) do { if (net_ratelimit()) printk(format , ## args); } while (0) static unsigned int nlbufsiz = 4096; -module_param(nlbufsiz, uint, 0600); /* FIXME: Check size < 128k --RR */ +module_param(nlbufsiz, uint, 0400); MODULE_PARM_DESC(nlbufsiz, "netlink buffer size"); static unsigned int flushtimeout = 10; -module_param(flushtimeout, int, 0600); +module_param(flushtimeout, uint, 0600); MODULE_PARM_DESC(flushtimeout, "buffer flush timeout (hundredths of a second)"); -static unsigned int nflog = 1; -module_param(nflog, int, 0400); +static int nflog = 1; +module_param(nflog, bool, 0400); MODULE_PARM_DESC(nflog, "register as internal netfilter logging module"); /* global data structures */ @@ -376,7 +376,7 @@ static int __init init(void) DEBUGP("ipt_ULOG: init module\n"); - if (nlbufsiz >= 128*1024) { + if (nlbufsiz > 128*1024) { printk("Netlink buffer has to be <= 128kB\n"); return -EINVAL; } diff --git a/net/ipv4/netfilter/ipt_recent.c b/net/ipv4/netfilter/ipt_recent.c index 261cbb4d4c49..5ddccb18c65e 100644 --- a/net/ipv4/netfilter/ipt_recent.c +++ b/net/ipv4/netfilter/ipt_recent.c @@ -24,10 +24,10 @@ #define HASH_LOG 9 /* Defaults, these can be overridden on the module command-line. */ -static int ip_list_tot = 100; -static int ip_pkt_list_tot = 20; -static int ip_list_hash_size = 0; -static int ip_list_perms = 0644; +static unsigned int ip_list_tot = 100; +static unsigned int ip_pkt_list_tot = 20; +static unsigned int ip_list_hash_size = 0; +static unsigned int ip_list_perms = 0644; #ifdef DEBUG static int debug = 1; #endif @@ -38,13 +38,13 @@ KERN_INFO RECENT_NAME " " RECENT_VER ": Stephen Frost . htt MODULE_AUTHOR("Stephen Frost "); MODULE_DESCRIPTION("IP tables recently seen matching module " RECENT_VER); MODULE_LICENSE("GPL"); -module_param(ip_list_tot, int, 0400); -module_param(ip_pkt_list_tot, int, 0400); -module_param(ip_list_hash_size, int, 0400); -module_param(ip_list_perms, int, 0400); +module_param(ip_list_tot, uint, 0400); +module_param(ip_pkt_list_tot, uint, 0400); +module_param(ip_list_hash_size, uint, 0400); +module_param(ip_list_perms, uint, 0400); #ifdef DEBUG -module_param(debug, int, 0600); -MODULE_PARM_DESC(debug,"debugging level, defaults to 1"); +module_param(debug, bool, 0600); +MODULE_PARM_DESC(debug,"enable debugging output"); #endif MODULE_PARM_DESC(ip_list_tot,"number of IPs to remember per list"); MODULE_PARM_DESC(ip_pkt_list_tot,"number of packets per IP to remember"); diff --git a/net/netfilter/nf_conntrack_ftp.c b/net/netfilter/nf_conntrack_ftp.c index 65080e269f27..d5a6eaf4a1de 100644 --- a/net/netfilter/nf_conntrack_ftp.c +++ b/net/netfilter/nf_conntrack_ftp.c @@ -44,7 +44,7 @@ static unsigned int ports_c; module_param_array(ports, ushort, &ports_c, 0400); static int loose; -module_param(loose, int, 0600); +module_param(loose, bool, 0600); unsigned int (*nf_nat_ftp_hook)(struct sk_buff **pskb, enum ip_conntrack_info ctinfo, From a9b305c4e56f97d6a2ae4f21691bc13797498caf Mon Sep 17 00:00:00 2001 From: Patrick McHardy Date: Thu, 5 Jan 2006 12:20:02 -0800 Subject: [PATCH 15/48] [NETFILTER]: ctnetlink: Fix dumping of helper name Properly dump the helper name instead of internal kernel data. Based on patch by Marcus Sundberg . Signed-off-by: Patrick McHardy Signed-off-by: David S. Miller --- include/linux/netfilter/nfnetlink_conntrack.h | 2 -- net/ipv4/netfilter/ip_conntrack_netlink.c | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/include/linux/netfilter/nfnetlink_conntrack.h b/include/linux/netfilter/nfnetlink_conntrack.h index b8e9a5b6fb1e..668ec946c8e2 100644 --- a/include/linux/netfilter/nfnetlink_conntrack.h +++ b/include/linux/netfilter/nfnetlink_conntrack.h @@ -131,6 +131,4 @@ enum ctattr_help { }; #define CTA_HELP_MAX (__CTA_HELP_MAX - 1) -#define CTA_HELP_MAXNAMESIZE 32 - #endif /* _IPCONNTRACK_NETLINK_H */ diff --git a/net/ipv4/netfilter/ip_conntrack_netlink.c b/net/ipv4/netfilter/ip_conntrack_netlink.c index 703f2d2e3464..c9ebbe0d2d9c 100644 --- a/net/ipv4/netfilter/ip_conntrack_netlink.c +++ b/net/ipv4/netfilter/ip_conntrack_netlink.c @@ -161,7 +161,7 @@ ctnetlink_dump_helpinfo(struct sk_buff *skb, const struct ip_conntrack *ct) return 0; nest_helper = NFA_NEST(skb, CTA_HELP); - NFA_PUT(skb, CTA_HELP_NAME, CTA_HELP_MAXNAMESIZE, &ct->helper->name); + NFA_PUT(skb, CTA_HELP_NAME, strlen(ct->helper->name), ct->helper->name); if (ct->helper->to_nfattr) ct->helper->to_nfattr(skb, ct); From abbcc73982445c1457901c7fc1d0d110e7a587e3 Mon Sep 17 00:00:00 2001 From: Patrick McHardy Date: Thu, 5 Jan 2006 12:20:40 -0800 Subject: [PATCH 16/48] [NETFILTER]: Remove okfn usage in ip_vs_core.c okfn should only be used from different contexts to avoid deep call chains, i.e. by nf_queue. Acked-by: Julian Anastasov Signed-off-by: Patrick McHardy Signed-off-by: David S. Miller --- net/ipv4/ipvs/ip_vs_core.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/net/ipv4/ipvs/ip_vs_core.c b/net/ipv4/ipvs/ip_vs_core.c index 1aca94a9fd8b..3f47ad8e1cad 100644 --- a/net/ipv4/ipvs/ip_vs_core.c +++ b/net/ipv4/ipvs/ip_vs_core.c @@ -532,11 +532,8 @@ static unsigned int ip_vs_post_routing(unsigned int hooknum, { if (!((*pskb)->ipvs_property)) return NF_ACCEPT; - /* The packet was sent from IPVS, exit this chain */ - (*okfn)(*pskb); - - return NF_STOLEN; + return NF_STOP; } u16 ip_vs_checksum_complete(struct sk_buff *skb, int offset) From 1bd9bef6f9fe06dd0c628ac877c85b6b36aca062 Mon Sep 17 00:00:00 2001 From: Patrick McHardy Date: Thu, 5 Jan 2006 12:20:59 -0800 Subject: [PATCH 17/48] [NETFILTER]: Call POST_ROUTING hook before fragmentation Call POST_ROUTING hook before fragmentation to get rid of the okfn use in ip_refrag and save the useless fragmentation/defragmentation step when NAT is used. The patch introduces one user-visible change, the POSTROUTING chain in the mangle table gets entire packets, not fragments, which should simplify use of the MARK and CLASSIFY targets for queueing as a nice side-effect. Signed-off-by: Patrick McHardy Signed-off-by: David S. Miller --- include/net/ip.h | 1 - net/ipv4/ip_output.c | 30 +++++++++---------- net/ipv4/netfilter/ip_conntrack_standalone.c | 26 +--------------- net/ipv4/netfilter/ip_nat_standalone.c | 17 ----------- .../netfilter/nf_conntrack_l3proto_ipv4.c | 26 +--------------- 5 files changed, 16 insertions(+), 84 deletions(-) diff --git a/include/net/ip.h b/include/net/ip.h index f7e7fd728b67..7bb5804847f2 100644 --- a/include/net/ip.h +++ b/include/net/ip.h @@ -317,7 +317,6 @@ enum ip_defrag_users IP_DEFRAG_CALL_RA_CHAIN, IP_DEFRAG_CONNTRACK_IN, IP_DEFRAG_CONNTRACK_OUT, - IP_DEFRAG_NAT_OUT, IP_DEFRAG_VS_IN, IP_DEFRAG_VS_OUT, IP_DEFRAG_VS_FWD diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index 2a830de3a699..71da31818cfc 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -202,13 +202,11 @@ static inline int ip_finish_output2(struct sk_buff *skb) static inline int ip_finish_output(struct sk_buff *skb) { - struct net_device *dev = skb->dst->dev; - - skb->dev = dev; - skb->protocol = htons(ETH_P_IP); - - return NF_HOOK(PF_INET, NF_IP_POST_ROUTING, skb, NULL, dev, - ip_finish_output2); + if (skb->len > dst_mtu(skb->dst) && + !(skb_shinfo(skb)->ufo_size || skb_shinfo(skb)->tso_size)) + return ip_fragment(skb, ip_finish_output2); + else + return ip_finish_output2(skb); } int ip_mc_output(struct sk_buff *skb) @@ -265,21 +263,21 @@ int ip_mc_output(struct sk_buff *skb) newskb->dev, ip_dev_loopback_xmit); } - if (skb->len > dst_mtu(&rt->u.dst)) - return ip_fragment(skb, ip_finish_output); - else - return ip_finish_output(skb); + return NF_HOOK(PF_INET, NF_IP_POST_ROUTING, skb, NULL, skb->dev, + ip_finish_output); } int ip_output(struct sk_buff *skb) { + struct net_device *dev = skb->dst->dev; + IP_INC_STATS(IPSTATS_MIB_OUTREQUESTS); - if (skb->len > dst_mtu(skb->dst) && - !(skb_shinfo(skb)->ufo_size || skb_shinfo(skb)->tso_size)) - return ip_fragment(skb, ip_finish_output); - else - return ip_finish_output(skb); + skb->dev = dev; + skb->protocol = htons(ETH_P_IP); + + return NF_HOOK(PF_INET, NF_IP_POST_ROUTING, skb, NULL, dev, + ip_finish_output); } int ip_queue_xmit(struct sk_buff *skb, int ipfragok) diff --git a/net/ipv4/netfilter/ip_conntrack_standalone.c b/net/ipv4/netfilter/ip_conntrack_standalone.c index a88bcc551244..7ba97783e741 100644 --- a/net/ipv4/netfilter/ip_conntrack_standalone.c +++ b/net/ipv4/netfilter/ip_conntrack_standalone.c @@ -451,30 +451,6 @@ static unsigned int ip_conntrack_defrag(unsigned int hooknum, return NF_ACCEPT; } -static unsigned int ip_refrag(unsigned int hooknum, - struct sk_buff **pskb, - const struct net_device *in, - const struct net_device *out, - int (*okfn)(struct sk_buff *)) -{ - struct rtable *rt = (struct rtable *)(*pskb)->dst; - - /* We've seen it coming out the other side: confirm */ - if (ip_confirm(hooknum, pskb, in, out, okfn) != NF_ACCEPT) - return NF_DROP; - - /* Local packets are never produced too large for their - interface. We degfragment them at LOCAL_OUT, however, - so we have to refragment them here. */ - if ((*pskb)->len > dst_mtu(&rt->u.dst) && - !skb_shinfo(*pskb)->tso_size) { - /* No hook can be after us, so this should be OK. */ - ip_fragment(*pskb, okfn); - return NF_STOLEN; - } - return NF_ACCEPT; -} - static unsigned int ip_conntrack_local(unsigned int hooknum, struct sk_buff **pskb, const struct net_device *in, @@ -544,7 +520,7 @@ static struct nf_hook_ops ip_conntrack_helper_in_ops = { /* Refragmenter; last chance. */ static struct nf_hook_ops ip_conntrack_out_ops = { - .hook = ip_refrag, + .hook = ip_confirm, .owner = THIS_MODULE, .pf = PF_INET, .hooknum = NF_IP_POST_ROUTING, diff --git a/net/ipv4/netfilter/ip_nat_standalone.c b/net/ipv4/netfilter/ip_nat_standalone.c index 30cd4e18c129..f04111f74e09 100644 --- a/net/ipv4/netfilter/ip_nat_standalone.c +++ b/net/ipv4/netfilter/ip_nat_standalone.c @@ -190,23 +190,6 @@ ip_nat_out(unsigned int hooknum, || (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr)) return NF_ACCEPT; - /* We can hit fragment here; forwarded packets get - defragmented by connection tracking coming in, then - fragmented (grr) by the forward code. - - In future: If we have nfct != NULL, AND we have NAT - initialized, AND there is no helper, then we can do full - NAPT on the head, and IP-address-only NAT on the rest. - - I'm starting to have nightmares about fragments. */ - - if ((*pskb)->nh.iph->frag_off & htons(IP_MF|IP_OFFSET)) { - *pskb = ip_ct_gather_frags(*pskb, IP_DEFRAG_NAT_OUT); - - if (!*pskb) - return NF_STOLEN; - } - return ip_nat_fn(hooknum, pskb, in, out, okfn); } diff --git a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c index 385867efd481..1d36e8effe4f 100644 --- a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c +++ b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c @@ -180,30 +180,6 @@ static unsigned int ipv4_conntrack_defrag(unsigned int hooknum, return NF_ACCEPT; } -static unsigned int ipv4_refrag(unsigned int hooknum, - struct sk_buff **pskb, - const struct net_device *in, - const struct net_device *out, - int (*okfn)(struct sk_buff *)) -{ - struct rtable *rt = (struct rtable *)(*pskb)->dst; - - /* We've seen it coming out the other side: confirm */ - if (ipv4_confirm(hooknum, pskb, in, out, okfn) != NF_ACCEPT) - return NF_DROP; - - /* Local packets are never produced too large for their - interface. We degfragment them at LOCAL_OUT, however, - so we have to refragment them here. */ - if ((*pskb)->len > dst_mtu(&rt->u.dst) && - !skb_shinfo(*pskb)->tso_size) { - /* No hook can be after us, so this should be OK. */ - ip_fragment(*pskb, okfn); - return NF_STOLEN; - } - return NF_ACCEPT; -} - static unsigned int ipv4_conntrack_in(unsigned int hooknum, struct sk_buff **pskb, const struct net_device *in, @@ -283,7 +259,7 @@ static struct nf_hook_ops ipv4_conntrack_helper_in_ops = { /* Refragmenter; last chance. */ static struct nf_hook_ops ipv4_conntrack_out_ops = { - .hook = ipv4_refrag, + .hook = ipv4_confirm, .owner = THIS_MODULE, .pf = PF_INET, .hooknum = NF_IP_POST_ROUTING, From b777e0ce7437a0e788e2aeb42aca9af2cce1f2e1 Mon Sep 17 00:00:00 2001 From: Patrick McHardy Date: Thu, 5 Jan 2006 12:21:16 -0800 Subject: [PATCH 18/48] [NETFILTER]: make ipv6_find_hdr() find transport protocol header The original ipv6_find_hdr() finds the specified header in IPv6 packets. This makes it possible to get transport header so that we can kill similar loop in ip6_match_packet(). Signed-off-by: Patrick McHardy Signed-off-by: David S. Miller --- include/linux/netfilter_ipv6/ip6_tables.h | 2 +- net/ipv6/netfilter/ip6_tables.c | 106 ++++++++-------------- net/ipv6/netfilter/ip6t_ah.c | 2 +- net/ipv6/netfilter/ip6t_dst.c | 4 +- net/ipv6/netfilter/ip6t_esp.c | 2 +- net/ipv6/netfilter/ip6t_frag.c | 2 +- net/ipv6/netfilter/ip6t_hbh.c | 4 +- net/ipv6/netfilter/ip6t_rt.c | 2 +- 8 files changed, 49 insertions(+), 75 deletions(-) diff --git a/include/linux/netfilter_ipv6/ip6_tables.h b/include/linux/netfilter_ipv6/ip6_tables.h index 2efc046d9e94..a291cb76ef18 100644 --- a/include/linux/netfilter_ipv6/ip6_tables.h +++ b/include/linux/netfilter_ipv6/ip6_tables.h @@ -474,7 +474,7 @@ extern unsigned int ip6t_do_table(struct sk_buff **pskb, extern int ip6t_ext_hdr(u8 nexthdr); /* find specified header and get offset to it */ extern int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset, - u8 target); + int target, unsigned short *fragoff); #define IP6T_ALIGN(s) (((s) + (__alignof__(struct ip6t_entry)-1)) & ~(__alignof__(struct ip6t_entry)-1)) diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c index ea43ef1d94a7..13b1a525b92c 100644 --- a/net/ipv6/netfilter/ip6_tables.c +++ b/net/ipv6/netfilter/ip6_tables.c @@ -205,69 +205,21 @@ ip6_packet_match(const struct sk_buff *skb, /* look for the desired protocol header */ if((ip6info->flags & IP6T_F_PROTO)) { - u_int8_t currenthdr = ipv6->nexthdr; - struct ipv6_opt_hdr _hdr, *hp; - u_int16_t ptr; /* Header offset in skb */ - u_int16_t hdrlen; /* Header */ - u_int16_t _fragoff = 0, *fp = NULL; + int protohdr; + unsigned short _frag_off; - ptr = IPV6_HDR_LEN; + protohdr = ipv6_find_hdr(skb, protoff, -1, &_frag_off); + if (protohdr < 0) + return 0; - while (ip6t_ext_hdr(currenthdr)) { - /* Is there enough space for the next ext header? */ - if (skb->len - ptr < IPV6_OPTHDR_LEN) - return 0; - - /* NONE or ESP: there isn't protocol part */ - /* If we want to count these packets in '-p all', - * we will change the return 0 to 1*/ - if ((currenthdr == IPPROTO_NONE) || - (currenthdr == IPPROTO_ESP)) - break; - - hp = skb_header_pointer(skb, ptr, sizeof(_hdr), &_hdr); - BUG_ON(hp == NULL); - - /* Size calculation */ - if (currenthdr == IPPROTO_FRAGMENT) { - fp = skb_header_pointer(skb, - ptr+offsetof(struct frag_hdr, - frag_off), - sizeof(_fragoff), - &_fragoff); - if (fp == NULL) - return 0; - - _fragoff = ntohs(*fp) & ~0x7; - hdrlen = 8; - } else if (currenthdr == IPPROTO_AH) - hdrlen = (hp->hdrlen+2)<<2; - else - hdrlen = ipv6_optlen(hp); - - currenthdr = hp->nexthdr; - ptr += hdrlen; - /* ptr is too large */ - if ( ptr > skb->len ) - return 0; - if (_fragoff) { - if (ip6t_ext_hdr(currenthdr)) - return 0; - break; - } - } - - *protoff = ptr; - *fragoff = _fragoff; - - /* currenthdr contains the protocol header */ + *fragoff = _frag_off; dprintf("Packet protocol %hi ?= %s%hi.\n", - currenthdr, + protohdr, ip6info->invflags & IP6T_INV_PROTO ? "!":"", ip6info->proto); - if (ip6info->proto == currenthdr) { + if (ip6info->proto == protohdr) { if(ip6info->invflags & IP6T_INV_PROTO) { return 0; } @@ -2098,26 +2050,39 @@ static void __exit fini(void) } /* - * find specified header up to transport protocol header. - * If found target header, the offset to the header is set to *offset - * and return 0. otherwise, return -1. + * find the offset to specified header or the protocol number of last header + * if target < 0. "last header" is transport protocol header, ESP, or + * "No next header". + * + * If target header is found, its offset is set in *offset and return protocol + * number. Otherwise, return -1. + * + * Note that non-1st fragment is special case that "the protocol number + * of last header" is "next header" field in Fragment header. In this case, + * *offset is meaningless and fragment offset is stored in *fragoff if fragoff + * isn't NULL. * - * Notes: - non-1st Fragment Header isn't skipped. - * - ESP header isn't skipped. - * - The target header may be trancated. */ -int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset, u8 target) +int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset, + int target, unsigned short *fragoff) { unsigned int start = (u8*)(skb->nh.ipv6h + 1) - skb->data; u8 nexthdr = skb->nh.ipv6h->nexthdr; unsigned int len = skb->len - start; + if (fragoff) + *fragoff = 0; + while (nexthdr != target) { struct ipv6_opt_hdr _hdr, *hp; unsigned int hdrlen; - if ((!ipv6_ext_hdr(nexthdr)) || nexthdr == NEXTHDR_NONE) + if ((!ipv6_ext_hdr(nexthdr)) || nexthdr == NEXTHDR_NONE) { + if (target < 0) + break; return -1; + } + hp = skb_header_pointer(skb, start, sizeof(_hdr), &_hdr); if (hp == NULL) return -1; @@ -2131,8 +2096,17 @@ int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset, u8 target) if (fp == NULL) return -1; - if (ntohs(*fp) & ~0x7) + _frag_off = ntohs(*fp) & ~0x7; + if (_frag_off) { + if (target < 0 && + ((!ipv6_ext_hdr(hp->nexthdr)) || + nexthdr == NEXTHDR_NONE)) { + if (fragoff) + *fragoff = _frag_off; + return hp->nexthdr; + } return -1; + } hdrlen = 8; } else if (nexthdr == NEXTHDR_AUTH) hdrlen = (hp->hdrlen + 2) << 2; @@ -2145,7 +2119,7 @@ int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset, u8 target) } *offset = start; - return 0; + return nexthdr; } EXPORT_SYMBOL(ip6t_register_table); diff --git a/net/ipv6/netfilter/ip6t_ah.c b/net/ipv6/netfilter/ip6t_ah.c index 268918d5deea..f5c1a7ff4a1f 100644 --- a/net/ipv6/netfilter/ip6t_ah.c +++ b/net/ipv6/netfilter/ip6t_ah.c @@ -54,7 +54,7 @@ match(const struct sk_buff *skb, unsigned int ptr; unsigned int hdrlen = 0; - if (ipv6_find_hdr(skb, &ptr, NEXTHDR_AUTH) < 0) + if (ipv6_find_hdr(skb, &ptr, NEXTHDR_AUTH, NULL) < 0) return 0; ah = skb_header_pointer(skb, ptr, sizeof(_ah), &_ah); diff --git a/net/ipv6/netfilter/ip6t_dst.c b/net/ipv6/netfilter/ip6t_dst.c index c450a635e54b..48cf5f9efc95 100644 --- a/net/ipv6/netfilter/ip6t_dst.c +++ b/net/ipv6/netfilter/ip6t_dst.c @@ -71,9 +71,9 @@ match(const struct sk_buff *skb, unsigned int optlen; #if HOPBYHOP - if (ipv6_find_hdr(skb, &ptr, NEXTHDR_HOP) < 0) + if (ipv6_find_hdr(skb, &ptr, NEXTHDR_HOP, NULL) < 0) #else - if (ipv6_find_hdr(skb, &ptr, NEXTHDR_DEST) < 0) + if (ipv6_find_hdr(skb, &ptr, NEXTHDR_DEST, NULL) < 0) #endif return 0; diff --git a/net/ipv6/netfilter/ip6t_esp.c b/net/ipv6/netfilter/ip6t_esp.c index 65937de1b58c..e1828f6d0a40 100644 --- a/net/ipv6/netfilter/ip6t_esp.c +++ b/net/ipv6/netfilter/ip6t_esp.c @@ -56,7 +56,7 @@ match(const struct sk_buff *skb, /* Make sure this isn't an evil packet */ /*DEBUGP("ipv6_esp entered \n");*/ - if (ipv6_find_hdr(skb, &ptr, NEXTHDR_ESP) < 0) + if (ipv6_find_hdr(skb, &ptr, NEXTHDR_ESP, NULL) < 0) return 0; eh = skb_header_pointer(skb, ptr, sizeof(_esp), &_esp); diff --git a/net/ipv6/netfilter/ip6t_frag.c b/net/ipv6/netfilter/ip6t_frag.c index 085d5f8eea29..d1549b268669 100644 --- a/net/ipv6/netfilter/ip6t_frag.c +++ b/net/ipv6/netfilter/ip6t_frag.c @@ -52,7 +52,7 @@ match(const struct sk_buff *skb, const struct ip6t_frag *fraginfo = matchinfo; unsigned int ptr; - if (ipv6_find_hdr(skb, &ptr, NEXTHDR_FRAGMENT) < 0) + if (ipv6_find_hdr(skb, &ptr, NEXTHDR_FRAGMENT, NULL) < 0) return 0; fh = skb_header_pointer(skb, ptr, sizeof(_frag), &_frag); diff --git a/net/ipv6/netfilter/ip6t_hbh.c b/net/ipv6/netfilter/ip6t_hbh.c index 1d09485111d0..e3bc8e2700e7 100644 --- a/net/ipv6/netfilter/ip6t_hbh.c +++ b/net/ipv6/netfilter/ip6t_hbh.c @@ -71,9 +71,9 @@ match(const struct sk_buff *skb, unsigned int optlen; #if HOPBYHOP - if (ipv6_find_hdr(skb, &ptr, NEXTHDR_HOP) < 0) + if (ipv6_find_hdr(skb, &ptr, NEXTHDR_HOP, NULL) < 0) #else - if (ipv6_find_hdr(skb, &ptr, NEXTHDR_DEST) < 0) + if (ipv6_find_hdr(skb, &ptr, NEXTHDR_DEST, NULL) < 0) #endif return 0; diff --git a/net/ipv6/netfilter/ip6t_rt.c b/net/ipv6/netfilter/ip6t_rt.c index beb2fd5cebbb..c1e770e45543 100644 --- a/net/ipv6/netfilter/ip6t_rt.c +++ b/net/ipv6/netfilter/ip6t_rt.c @@ -58,7 +58,7 @@ match(const struct sk_buff *skb, unsigned int ret = 0; struct in6_addr *ap, _addr; - if (ipv6_find_hdr(skb, &ptr, NEXTHDR_ROUTING) < 0) + if (ipv6_find_hdr(skb, &ptr, NEXTHDR_ROUTING, NULL) < 0) return 0; rh = skb_header_pointer(skb, ptr, sizeof(_route), &_route); From 22dea562bb56dbc3430c8f23f60ccd38527b1f5a Mon Sep 17 00:00:00 2001 From: Patrick McHardy Date: Thu, 5 Jan 2006 12:21:34 -0800 Subject: [PATCH 19/48] [NETFILTER]: Export ip6_masked_addrcmp, don't pass IPv6 addresses on stack Signed-off-by: Patrick McHardy Signed-off-by: David S. Miller --- include/linux/netfilter_ipv6/ip6_tables.h | 4 ++++ net/ipv6/netfilter/ip6_tables.c | 18 ++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/include/linux/netfilter_ipv6/ip6_tables.h b/include/linux/netfilter_ipv6/ip6_tables.h index a291cb76ef18..c163ba31aab7 100644 --- a/include/linux/netfilter_ipv6/ip6_tables.h +++ b/include/linux/netfilter_ipv6/ip6_tables.h @@ -476,6 +476,10 @@ extern int ip6t_ext_hdr(u8 nexthdr); extern int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset, int target, unsigned short *fragoff); +extern int ip6_masked_addrcmp(const struct in6_addr *addr1, + const struct in6_addr *mask, + const struct in6_addr *addr2); + #define IP6T_ALIGN(s) (((s) + (__alignof__(struct ip6t_entry)-1)) & ~(__alignof__(struct ip6t_entry)-1)) #endif /*__KERNEL__*/ diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c index 13b1a525b92c..925b42d48347 100644 --- a/net/ipv6/netfilter/ip6_tables.c +++ b/net/ipv6/netfilter/ip6_tables.c @@ -119,13 +119,14 @@ static LIST_HEAD(ip6t_tables); #define up(x) do { printk("UP:%u:" #x "\n", __LINE__); up(x); } while(0) #endif -static int ip6_masked_addrcmp(struct in6_addr addr1, struct in6_addr mask, - struct in6_addr addr2) +int +ip6_masked_addrcmp(const struct in6_addr *addr1, const struct in6_addr *mask, + const struct in6_addr *addr2) { int i; for( i = 0; i < 16; i++){ - if((addr1.s6_addr[i] & mask.s6_addr[i]) != - (addr2.s6_addr[i] & mask.s6_addr[i])) + if((addr1->s6_addr[i] & mask->s6_addr[i]) != + (addr2->s6_addr[i] & mask->s6_addr[i])) return 1; } return 0; @@ -159,10 +160,10 @@ ip6_packet_match(const struct sk_buff *skb, #define FWINV(bool,invflg) ((bool) ^ !!(ip6info->invflags & invflg)) - if (FWINV(ip6_masked_addrcmp(ipv6->saddr,ip6info->smsk,ip6info->src), - IP6T_INV_SRCIP) - || FWINV(ip6_masked_addrcmp(ipv6->daddr,ip6info->dmsk,ip6info->dst), - IP6T_INV_DSTIP)) { + if (FWINV(ip6_masked_addrcmp(&ipv6->saddr, &ip6info->smsk, + &ip6info->src), IP6T_INV_SRCIP) + || FWINV(ip6_masked_addrcmp(&ipv6->daddr, &ip6info->dmsk, + &ip6info->dst), IP6T_INV_DSTIP)) { dprintf("Source or dest mismatch.\n"); /* dprintf("SRC: %u. Mask: %u. Target: %u.%s\n", ip->saddr, @@ -2131,6 +2132,7 @@ EXPORT_SYMBOL(ip6t_register_target); EXPORT_SYMBOL(ip6t_unregister_target); EXPORT_SYMBOL(ip6t_ext_hdr); EXPORT_SYMBOL(ipv6_find_hdr); +EXPORT_SYMBOL(ip6_masked_addrcmp); module_init(init); module_exit(fini); From 0ae2cfe7f3d88f061aa2656c7e881d3a0697d622 Mon Sep 17 00:00:00 2001 From: Patrick McHardy Date: Thu, 5 Jan 2006 12:21:52 -0800 Subject: [PATCH 20/48] [NETFILTER]: nf_conntrack_l3proto_ipv4.c needs net/route.h CC [M] net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.o net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c: In function 'ipv4_refrag': net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c:198: error: dereferencing pointer to incomplete type make[3]: *** [net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.o] Error 1 Signed-off-by: Patrick McHardy Signed-off-by: David S. Miller --- net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c index 1d36e8effe4f..9bdbb7793971 100644 --- a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c +++ b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include From e8eaedf2f8b368c26aa31a5a5a623b6867ef7f2b Mon Sep 17 00:00:00 2001 From: Yasuyuki Kozakai Date: Thu, 5 Jan 2006 12:28:57 -0800 Subject: [PATCH 21/48] [NETFILTER]: Use HOPLIMIT metric as TTL of TCP reset sent by REJECT HOPLIMIT metric is appropriate to TCP reset sent by REJECT target than hard-coded max TTL. Thanks to David S. Miller for hint. Signed-off-by: Yasuyuki Kozakai Signed-off-by: David S. Miller --- net/ipv4/netfilter/ipt_REJECT.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/netfilter/ipt_REJECT.c b/net/ipv4/netfilter/ipt_REJECT.c index f057025a719e..6693526ae128 100644 --- a/net/ipv4/netfilter/ipt_REJECT.c +++ b/net/ipv4/netfilter/ipt_REJECT.c @@ -203,7 +203,7 @@ static void send_reset(struct sk_buff *oldskb, int hook) sizeof(struct tcphdr), 0)); /* Adjust IP TTL, DF */ - nskb->nh.iph->ttl = MAXTTL; + nskb->nh.iph->ttl = dst_metric(nskb->dst, RTAX_HOPLIMIT); /* Set DF, id = 0 */ nskb->nh.iph->frag_off = htons(IP_DF); nskb->nh.iph->id = 0; From 5b373e10aeadc2599c085a3357b7fad8b8e760b8 Mon Sep 17 00:00:00 2001 From: "Luis F. Ortiz" Date: Thu, 5 Jan 2006 13:12:41 -0800 Subject: [PATCH 22/48] [ATYFB]: Fix onboard video on SPARC Blade 100 for 2.6.{13,14,15} I have recently been switching from using 2.4.32 on my trusty old Sparc Blade 100 to using 2.6.15 . Some of the problems I ran into were distorted video when the console was active (missing first character, skipped dots) and when running X windows (colored snow, stripes, missing pixels). A quick examination of the 2.6 versus 2.4 source for the ATY driver revealed alot of changes. A closer look at the code/data for the 64GR/XL chip revealed two minor "typos" that the rewriter(s) of the code made. The first is a incorrect clock value (230 .vs. 235) and the second is a missing flag (M64F_SDRAM_MAGIC_PLL). Making both these changes seems to have fixed my problem. I tend to think the 235 value is the correct one, as there is a 29.4 Mhz clock crystal close to the video chip and 235.2 (29.4*8) is too close to 235 to make it a coincidence. The flag for M64F_SDRAM_MAGIC_PLL was dropped during the changes made by adaplas in file revision 1.72 on the old bitkeeper repository. The change relating to the clock rate has been there forever, at least in the 2.6 tree. I'm not sure where to look for the old 2.5 tree or if anyone cares when it happened. On SPARC Blades 100's, which use the ATY MACH64GR video chipset, the clock crystal frequency is 235.2 Mhz, not 230 Mhz. The chipset also requires the use of M64F_SDRAM_MAGIC_PLL in order to setup the PLL properly for the DRAM. Signed-off-by: Luis F. Ortiz Signed-off-by: David S. Miller --- drivers/video/aty/atyfb_base.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c index 08edbfcfca58..3fefdb0cbf07 100644 --- a/drivers/video/aty/atyfb_base.c +++ b/drivers/video/aty/atyfb_base.c @@ -403,7 +403,7 @@ static struct { { PCI_CHIP_MACH64GM, "3D RAGE XL (Mach64 GM, AGP)", 230, 83, 63, ATI_CHIP_264XL }, { PCI_CHIP_MACH64GN, "3D RAGE XL (Mach64 GN, AGP)", 230, 83, 63, ATI_CHIP_264XL }, { PCI_CHIP_MACH64GO, "3D RAGE XL (Mach64 GO, PCI-66/BGA)", 230, 83, 63, ATI_CHIP_264XL }, - { PCI_CHIP_MACH64GR, "3D RAGE XL (Mach64 GR, PCI-33MHz)", 230, 83, 63, ATI_CHIP_264XL }, + { PCI_CHIP_MACH64GR, "3D RAGE XL (Mach64 GR, PCI-33MHz)", 235, 83, 63, ATI_CHIP_264XL | M64F_SDRAM_MAGIC_PLL }, { PCI_CHIP_MACH64GL, "3D RAGE XL (Mach64 GL, PCI)", 230, 83, 63, ATI_CHIP_264XL }, { PCI_CHIP_MACH64GS, "3D RAGE XL (Mach64 GS, PCI)", 230, 83, 63, ATI_CHIP_264XL }, From 38c0b2c2aaab5595a140ade4410e01d407fff751 Mon Sep 17 00:00:00 2001 From: Tony Luck Date: Thu, 5 Jan 2006 13:30:52 -0800 Subject: [PATCH 23/48] [IA64] Fix compile warnings in setup.c arch/ia64/kernel/setup.c: In function `show_cpuinfo': arch/ia64/kernel/setup.c:576: warning: long unsigned int format, different type arg (arg 12) arch/ia64/kernel/setup.c:576: warning: long unsigned int format, different type arg (arg 13) Introduced by 95235ca2c20ac0b31a8eb39e2d599bcc3e9c9a10 Signed-off-by: Tony Luck --- arch/ia64/kernel/setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/ia64/kernel/setup.c b/arch/ia64/kernel/setup.c index 088e5dded8dc..c33305d8e5eb 100644 --- a/arch/ia64/kernel/setup.c +++ b/arch/ia64/kernel/setup.c @@ -518,7 +518,7 @@ show_cpuinfo (struct seq_file *m, void *v) char family[32], features[128], *cp, sep; struct cpuinfo_ia64 *c = v; unsigned long mask; - unsigned int proc_freq; + unsigned long proc_freq; int i; mask = c->features; From 37f779554404ddca981ac4b4cc6692fc09b71e96 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Wed, 7 Sep 2005 16:00:26 -0700 Subject: [PATCH 24/48] [PATCH] pcmcia: avoid macro usage in cistpl Fix macro abuse in pcmcia. Signed-off-by: Pavel Machek Signed-off-by: Dominik Brodowski --- drivers/pcmcia/cistpl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c index 2dc3e611a9a3..55d7247b58e7 100644 --- a/drivers/pcmcia/cistpl.c +++ b/drivers/pcmcia/cistpl.c @@ -60,9 +60,9 @@ static const u_int exponent[] = { /* Parameters that can be set with 'insmod' */ -#define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0444) - -INT_MODULE_PARM(cis_width, 0); /* 16-bit CIS? */ +/* 16-bit CIS? */ +static int cis_width; +module_param(cis_width, int, 0444); void release_cis_mem(struct pcmcia_socket *s) { From e4115805cf2020da94e8bd1296243605cda487ff Mon Sep 17 00:00:00 2001 From: Daniel Ritz Date: Tue, 20 Sep 2005 14:17:37 -0700 Subject: [PATCH 25/48] [PATCH] yenta: optimize interrupt handler Don't waste cpu time in yenta interrupt handler when the interrupt was for another device. Signed-off-by: Daniel Ritz Signed-off-by: Dominik Brodowski --- drivers/pcmcia/yenta_socket.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/pcmcia/yenta_socket.c b/drivers/pcmcia/yenta_socket.c index ec6ab65f0872..8bfe72b71302 100644 --- a/drivers/pcmcia/yenta_socket.c +++ b/drivers/pcmcia/yenta_socket.c @@ -531,6 +531,9 @@ static irqreturn_t yenta_interrupt(int irq, void *dev_id, struct pt_regs *regs) csc = exca_readb(socket, I365_CSC); + if (!(cb_event || csc)) + return IRQ_NONE; + events = (cb_event & (CB_CD1EVENT | CB_CD2EVENT)) ? SS_DETECT : 0 ; events |= (csc & I365_CSC_DETECT) ? SS_DETECT : 0; if (exca_readb(socket, I365_INTCTL) & I365_PC_IOCARD) { @@ -544,10 +547,7 @@ static irqreturn_t yenta_interrupt(int irq, void *dev_id, struct pt_regs *regs) if (events) pcmcia_parse_events(&socket->socket, events); - if (cb_event || csc) - return IRQ_HANDLED; - - return IRQ_NONE; + return IRQ_HANDLED; } static void yenta_interrupt_wrapper(unsigned long data) From 7f316b033b36adfbdf56bfb15c13de49798ab0b2 Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Wed, 28 Sep 2005 19:41:55 +0200 Subject: [PATCH 26/48] [PATCH] pcmcia: remove socket register_callback Remove the register_callback declaration in struct pccard_operations as it is unused. Signed-off-by: Dominik Brodowski --- include/pcmcia/ss.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/pcmcia/ss.h b/include/pcmcia/ss.h index e788bbc5657d..25e6bf05e25c 100644 --- a/include/pcmcia/ss.h +++ b/include/pcmcia/ss.h @@ -118,7 +118,6 @@ struct pcmcia_socket; struct pccard_operations { int (*init)(struct pcmcia_socket *sock); int (*suspend)(struct pcmcia_socket *sock); - int (*register_callback)(struct pcmcia_socket *sock, void (*handler)(void *, unsigned int), void * info); int (*get_status)(struct pcmcia_socket *sock, u_int *value); int (*get_socket)(struct pcmcia_socket *sock, socket_state_t *state); int (*set_socket)(struct pcmcia_socket *sock, socket_state_t *state); From 9da4bc6d6a38c1c3d850c046d0aee324c1a2e52a Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sat, 12 Nov 2005 23:56:33 +0100 Subject: [PATCH 27/48] [PATCH] pcmcia: remove get_socket callback The .get_socket callback is never used by the PCMCIA core, therefore remove it. Signed-off-by: Dominik Brodowski --- drivers/pcmcia/au1000_generic.c | 18 ------- drivers/pcmcia/hd64465_ss.c | 13 ----- drivers/pcmcia/i82092.c | 73 -------------------------- drivers/pcmcia/i82092aa.h | 1 - drivers/pcmcia/i82365.c | 83 ------------------------------ drivers/pcmcia/m32r_cfc.c | 32 ------------ drivers/pcmcia/m32r_pcc.c | 20 -------- drivers/pcmcia/m8xx_pcmcia.c | 12 ----- drivers/pcmcia/pd6729.c | 70 ------------------------- drivers/pcmcia/soc_common.c | 20 -------- drivers/pcmcia/tcic.c | 61 ---------------------- drivers/pcmcia/vrc4171_card.c | 70 ------------------------- drivers/pcmcia/vrc4173_cardu.c | 43 ---------------- drivers/pcmcia/yenta_socket.c | 90 --------------------------------- include/pcmcia/ss.h | 1 - 15 files changed, 607 deletions(-) diff --git a/drivers/pcmcia/au1000_generic.c b/drivers/pcmcia/au1000_generic.c index 87302c548c24..0868b72c3996 100644 --- a/drivers/pcmcia/au1000_generic.c +++ b/drivers/pcmcia/au1000_generic.c @@ -241,23 +241,6 @@ au1x00_pcmcia_get_status(struct pcmcia_socket *sock, unsigned int *status) return 0; } -/* au1x00_pcmcia_get_socket() - * Implements the get_socket() operation for the in-kernel PCMCIA - * service (formerly SS_GetSocket in Card Services). Not a very - * exciting routine. - * - * Returns: 0 - */ -static int -au1x00_pcmcia_get_socket(struct pcmcia_socket *sock, socket_state_t *state) -{ - struct au1000_pcmcia_socket *skt = to_au1000_socket(sock); - - debug("for sock %u\n", skt->nr); - *state = skt->cs_state; - return 0; -} - /* au1x00_pcmcia_set_socket() * Implements the set_socket() operation for the in-kernel PCMCIA * service (formerly SS_SetSocket in Card Services). We more or @@ -352,7 +335,6 @@ static struct pccard_operations au1x00_pcmcia_operations = { .init = au1x00_pcmcia_sock_init, .suspend = au1x00_pcmcia_suspend, .get_status = au1x00_pcmcia_get_status, - .get_socket = au1x00_pcmcia_get_socket, .set_socket = au1x00_pcmcia_set_socket, .set_io_map = au1x00_pcmcia_set_io_map, .set_mem_map = au1x00_pcmcia_set_mem_map, diff --git a/drivers/pcmcia/hd64465_ss.c b/drivers/pcmcia/hd64465_ss.c index 561706ba4499..b39435bbfaeb 100644 --- a/drivers/pcmcia/hd64465_ss.c +++ b/drivers/pcmcia/hd64465_ss.c @@ -417,18 +417,6 @@ static int hs_get_status(struct pcmcia_socket *s, u_int *value) /*============================================================*/ -static int hs_get_socket(struct pcmcia_socket *s, socket_state_t *state) -{ - hs_socket_t *sp = container_of(s, struct hs_socket_t, socket); - - DPRINTK("hs_get_socket(%d)\n", sock); - - *state = sp->state; - return 0; -} - -/*============================================================*/ - static int hs_set_socket(struct pcmcia_socket *s, socket_state_t *state) { hs_socket_t *sp = container_of(s, struct hs_socket_t, socket); @@ -749,7 +737,6 @@ static irqreturn_t hs_interrupt(int irq, void *dev, struct pt_regs *regs) static struct pccard_operations hs_operations = { .init = hs_init, .get_status = hs_get_status, - .get_socket = hs_get_socket, .set_socket = hs_set_socket, .set_io_map = hs_set_io_map, .set_mem_map = hs_set_mem_map, diff --git a/drivers/pcmcia/i82092.c b/drivers/pcmcia/i82092.c index f3fdc748659d..7979c85df3dc 100644 --- a/drivers/pcmcia/i82092.c +++ b/drivers/pcmcia/i82092.c @@ -66,7 +66,6 @@ static struct pci_driver i82092aa_pci_drv = { static struct pccard_operations i82092aa_operations = { .init = i82092aa_init, .get_status = i82092aa_get_status, - .get_socket = i82092aa_get_socket, .set_socket = i82092aa_set_socket, .set_io_map = i82092aa_set_io_map, .set_mem_map = i82092aa_set_mem_map, @@ -482,78 +481,6 @@ static int i82092aa_get_status(struct pcmcia_socket *socket, u_int *value) } -static int i82092aa_get_socket(struct pcmcia_socket *socket, socket_state_t *state) -{ - unsigned int sock = container_of(socket, struct socket_info, socket)->number; - unsigned char reg,vcc,vpp; - - enter("i82092aa_get_socket"); - state->flags = 0; - state->Vcc = 0; - state->Vpp = 0; - state->io_irq = 0; - state->csc_mask = 0; - - /* First the power status of the socket */ - reg = indirect_read(sock,I365_POWER); /* PCTRL - Power Control Register */ - - if (reg & I365_PWR_AUTO) - state->flags |= SS_PWR_AUTO; /* Automatic Power Switch */ - - if (reg & I365_PWR_OUT) - state->flags |= SS_OUTPUT_ENA; /* Output signals are enabled */ - - vcc = reg & I365_VCC_MASK; vpp = reg & I365_VPP1_MASK; - - if (reg & I365_VCC_5V) { /* Can still be 3.3V, in this case the Vcc value will be overwritten later */ - state->Vcc = 50; - - if (vpp == I365_VPP1_5V) - state->Vpp = 50; - if (vpp == I365_VPP1_12V) - state->Vpp = 120; - - } - - if ((reg & I365_VCC_3V)==I365_VCC_3V) - state->Vcc = 33; - - - /* Now the IO card, RESET flags and IO interrupt */ - - reg = indirect_read(sock, I365_INTCTL); /* IGENC, Interrupt and General Control */ - - if ((reg & I365_PC_RESET)==0) - state->flags |= SS_RESET; - if (reg & I365_PC_IOCARD) - state->flags |= SS_IOCARD; /* This is an IO card */ - - /* Set the IRQ number */ - if (sockets[sock].dev!=NULL) - state->io_irq = sockets[sock].dev->irq; - - /* Card status change */ - reg = indirect_read(sock, I365_CSCINT); /* CSCICR, Card Status Change Interrupt Configuration */ - - if (reg & I365_CSC_DETECT) - state->csc_mask |= SS_DETECT; /* Card detect is enabled */ - - if (state->flags & SS_IOCARD) {/* IO Cards behave different */ - if (reg & I365_CSC_STSCHG) - state->csc_mask |= SS_STSCHG; - } else { - if (reg & I365_CSC_BVD1) - state->csc_mask |= SS_BATDEAD; - if (reg & I365_CSC_BVD2) - state->csc_mask |= SS_BATWARN; - if (reg & I365_CSC_READY) - state->csc_mask |= SS_READY; - } - - leave("i82092aa_get_socket"); - return 0; -} - static int i82092aa_set_socket(struct pcmcia_socket *socket, socket_state_t *state) { unsigned int sock = container_of(socket, struct socket_info, socket)->number; diff --git a/drivers/pcmcia/i82092aa.h b/drivers/pcmcia/i82092aa.h index b98cac7bda9f..9c14599d0673 100644 --- a/drivers/pcmcia/i82092aa.h +++ b/drivers/pcmcia/i82092aa.h @@ -29,7 +29,6 @@ static irqreturn_t i82092aa_interrupt(int irq, void *dev, struct pt_regs *regs); static int i82092aa_get_status(struct pcmcia_socket *socket, u_int *value); -static int i82092aa_get_socket(struct pcmcia_socket *socket, socket_state_t *state); static int i82092aa_set_socket(struct pcmcia_socket *socket, socket_state_t *state); static int i82092aa_set_io_map(struct pcmcia_socket *socket, struct pccard_io_map *io); static int i82092aa_set_mem_map(struct pcmcia_socket *socket, struct pccard_mem_map *mem); diff --git a/drivers/pcmcia/i82365.c b/drivers/pcmcia/i82365.c index 4d56bc9926d6..35a92d1e4945 100644 --- a/drivers/pcmcia/i82365.c +++ b/drivers/pcmcia/i82365.c @@ -940,78 +940,6 @@ static int i365_get_status(u_short sock, u_int *value) /*====================================================================*/ -static int i365_get_socket(u_short sock, socket_state_t *state) -{ - struct i82365_socket *t = &socket[sock]; - u_char reg, vcc, vpp; - - reg = i365_get(sock, I365_POWER); - state->flags = (reg & I365_PWR_AUTO) ? SS_PWR_AUTO : 0; - state->flags |= (reg & I365_PWR_OUT) ? SS_OUTPUT_ENA : 0; - vcc = reg & I365_VCC_MASK; vpp = reg & I365_VPP1_MASK; - state->Vcc = state->Vpp = 0; - if (t->flags & IS_CIRRUS) { - if (i365_get(sock, PD67_MISC_CTL_1) & PD67_MC1_VCC_3V) { - if (reg & I365_VCC_5V) state->Vcc = 33; - if (vpp == I365_VPP1_5V) state->Vpp = 33; - } else { - if (reg & I365_VCC_5V) state->Vcc = 50; - if (vpp == I365_VPP1_5V) state->Vpp = 50; - } - if (vpp == I365_VPP1_12V) state->Vpp = 120; - } else if (t->flags & IS_VG_PWR) { - if (i365_get(sock, VG469_VSELECT) & VG469_VSEL_VCC) { - if (reg & I365_VCC_5V) state->Vcc = 33; - if (vpp == I365_VPP1_5V) state->Vpp = 33; - } else { - if (reg & I365_VCC_5V) state->Vcc = 50; - if (vpp == I365_VPP1_5V) state->Vpp = 50; - } - if (vpp == I365_VPP1_12V) state->Vpp = 120; - } else if (t->flags & IS_DF_PWR) { - if (vcc == I365_VCC_3V) state->Vcc = 33; - if (vcc == I365_VCC_5V) state->Vcc = 50; - if (vpp == I365_VPP1_5V) state->Vpp = 50; - if (vpp == I365_VPP1_12V) state->Vpp = 120; - } else { - if (reg & I365_VCC_5V) { - state->Vcc = 50; - if (vpp == I365_VPP1_5V) state->Vpp = 50; - if (vpp == I365_VPP1_12V) state->Vpp = 120; - } - } - - /* IO card, RESET flags, IO interrupt */ - reg = i365_get(sock, I365_INTCTL); - state->flags |= (reg & I365_PC_RESET) ? 0 : SS_RESET; - if (reg & I365_PC_IOCARD) state->flags |= SS_IOCARD; - state->io_irq = reg & I365_IRQ_MASK; - - /* speaker control */ - if (t->flags & IS_CIRRUS) { - if (i365_get(sock, PD67_MISC_CTL_1) & PD67_MC1_SPKR_ENA) - state->flags |= SS_SPKR_ENA; - } - - /* Card status change mask */ - reg = i365_get(sock, I365_CSCINT); - state->csc_mask = (reg & I365_CSC_DETECT) ? SS_DETECT : 0; - if (state->flags & SS_IOCARD) - state->csc_mask |= (reg & I365_CSC_STSCHG) ? SS_STSCHG : 0; - else { - state->csc_mask |= (reg & I365_CSC_BVD1) ? SS_BATDEAD : 0; - state->csc_mask |= (reg & I365_CSC_BVD2) ? SS_BATWARN : 0; - state->csc_mask |= (reg & I365_CSC_READY) ? SS_READY : 0; - } - - debug(1, "GetSocket(%d) = flags %#3.3x, Vcc %d, Vpp %d, " - "io_irq %d, csc_mask %#2.2x\n", sock, state->flags, - state->Vcc, state->Vpp, state->io_irq, state->csc_mask); - return 0; -} /* i365_get_socket */ - -/*====================================================================*/ - static int i365_set_socket(u_short sock, socket_state_t *state) { struct i82365_socket *t = &socket[sock]; @@ -1265,16 +1193,6 @@ static int pcic_get_status(struct pcmcia_socket *s, u_int *value) LOCKED(i365_get_status(sock, value)); } -static int pcic_get_socket(struct pcmcia_socket *s, socket_state_t *state) -{ - unsigned int sock = container_of(s, struct i82365_socket, socket)->number; - - if (socket[sock].flags & IS_ALIVE) - return -EINVAL; - - LOCKED(i365_get_socket(sock, state)); -} - static int pcic_set_socket(struct pcmcia_socket *s, socket_state_t *state) { unsigned int sock = container_of(s, struct i82365_socket, socket)->number; @@ -1324,7 +1242,6 @@ static int pcic_init(struct pcmcia_socket *s) static struct pccard_operations pcic_operations = { .init = pcic_init, .get_status = pcic_get_status, - .get_socket = pcic_get_socket, .set_socket = pcic_set_socket, .set_io_map = pcic_set_io_map, .set_mem_map = pcic_set_mem_map, diff --git a/drivers/pcmcia/m32r_cfc.c b/drivers/pcmcia/m32r_cfc.c index 078579ae6359..071cf485e1a3 100644 --- a/drivers/pcmcia/m32r_cfc.c +++ b/drivers/pcmcia/m32r_cfc.c @@ -480,25 +480,6 @@ static int _pcc_get_status(u_short sock, u_int *value) /*====================================================================*/ -static int _pcc_get_socket(u_short sock, socket_state_t *state) -{ -// pcc_socket_t *t = &socket[sock]; - - state->flags = 0; - state->csc_mask = SS_DETECT; - state->csc_mask |= SS_READY; - state->io_irq = 0; - state->Vcc = 33; /* 3.3V fixed */ - state->Vpp = 33; - - debug(3, "m32r_cfc: GetSocket(%d) = flags %#3.3x, Vcc %d, Vpp %d, " - "io_irq %d, csc_mask %#2.2x\n", sock, state->flags, - state->Vcc, state->Vpp, state->io_irq, state->csc_mask); - return 0; -} /* _get_socket */ - -/*====================================================================*/ - static int _pcc_set_socket(u_short sock, socket_state_t *state) { debug(3, "m32r_cfc: SetSocket(%d, flags %#3.3x, Vcc %d, Vpp %d, " @@ -667,18 +648,6 @@ static int pcc_get_status(struct pcmcia_socket *s, u_int *value) LOCKED(_pcc_get_status(sock, value)); } -static int pcc_get_socket(struct pcmcia_socket *s, socket_state_t *state) -{ - unsigned int sock = container_of(s, struct pcc_socket, socket)->number; - - if (socket[sock].flags & IS_ALIVE) { - debug(3, "m32r_cfc: pcc_get_socket: sock(%d) -EINVAL\n", sock); - return -EINVAL; - } - debug(3, "m32r_cfc: pcc_get_socket: sock(%d)\n", sock); - LOCKED(_pcc_get_socket(sock, state)); -} - static int pcc_set_socket(struct pcmcia_socket *s, socket_state_t *state) { unsigned int sock = container_of(s, struct pcc_socket, socket)->number; @@ -724,7 +693,6 @@ static int pcc_init(struct pcmcia_socket *s) static struct pccard_operations pcc_operations = { .init = pcc_init, .get_status = pcc_get_status, - .get_socket = pcc_get_socket, .set_socket = pcc_set_socket, .set_io_map = pcc_set_io_map, .set_mem_map = pcc_set_mem_map, diff --git a/drivers/pcmcia/m32r_pcc.c b/drivers/pcmcia/m32r_pcc.c index 356a6fb416a1..70d5f0748d55 100644 --- a/drivers/pcmcia/m32r_pcc.c +++ b/drivers/pcmcia/m32r_pcc.c @@ -429,16 +429,6 @@ static int _pcc_get_status(u_short sock, u_int *value) /*====================================================================*/ -static int _pcc_get_socket(u_short sock, socket_state_t *state) -{ - debug(3, "m32r-pcc: GetSocket(%d) = flags %#3.3x, Vcc %d, Vpp %d, " - "io_irq %d, csc_mask %#2.2x\n", sock, state->flags, - state->Vcc, state->Vpp, state->io_irq, state->csc_mask); - return 0; -} /* _get_socket */ - -/*====================================================================*/ - static int _pcc_set_socket(u_short sock, socket_state_t *state) { u_long reg = 0; @@ -641,15 +631,6 @@ static int pcc_get_status(struct pcmcia_socket *s, u_int *value) LOCKED(_pcc_get_status(sock, value)); } -static int pcc_get_socket(struct pcmcia_socket *s, socket_state_t *state) -{ - unsigned int sock = container_of(s, struct pcc_socket, socket)->number; - - if (socket[sock].flags & IS_ALIVE) - return -EINVAL; - LOCKED(_pcc_get_socket(sock, state)); -} - static int pcc_set_socket(struct pcmcia_socket *s, socket_state_t *state) { unsigned int sock = container_of(s, struct pcc_socket, socket)->number; @@ -687,7 +668,6 @@ static int pcc_init(struct pcmcia_socket *s) static struct pccard_operations pcc_operations = { .init = pcc_init, .get_status = pcc_get_status, - .get_socket = pcc_get_socket, .set_socket = pcc_set_socket, .set_io_map = pcc_set_io_map, .set_mem_map = pcc_set_mem_map, diff --git a/drivers/pcmcia/m8xx_pcmcia.c b/drivers/pcmcia/m8xx_pcmcia.c index 6d9f71cfcb34..a7f27c3dfc24 100644 --- a/drivers/pcmcia/m8xx_pcmcia.c +++ b/drivers/pcmcia/m8xx_pcmcia.c @@ -823,17 +823,6 @@ static int m8xx_get_status(struct pcmcia_socket *sock, unsigned int *value) return 0; } -static int m8xx_get_socket(struct pcmcia_socket *sock, socket_state_t *state) -{ - int lsock = container_of(sock, struct socket_info, socket)->slot; - *state = socket[lsock].state; /* copy the whole structure */ - - dprintk("GetSocket(%d) = flags %#3.3x, Vcc %d, Vpp %d, " - "io_irq %d, csc_mask %#2.2x\n", lsock, state->flags, - state->Vcc, state->Vpp, state->io_irq, state->csc_mask); - return 0; -} - static int m8xx_set_socket(struct pcmcia_socket *sock, socket_state_t *state) { int lsock = container_of(sock, struct socket_info, socket)->slot; @@ -1169,7 +1158,6 @@ static struct pccard_operations m8xx_services = { .init = m8xx_sock_init, .suspend = m8xx_suspend, .get_status = m8xx_get_status, - .get_socket = m8xx_get_socket, .set_socket = m8xx_set_socket, .set_io_map = m8xx_set_io_map, .set_mem_map = m8xx_set_mem_map, diff --git a/drivers/pcmcia/pd6729.c b/drivers/pcmcia/pd6729.c index 20642f0e7bfe..e7a6d9ac5ed8 100644 --- a/drivers/pcmcia/pd6729.c +++ b/drivers/pcmcia/pd6729.c @@ -304,75 +304,6 @@ static int pd6729_get_status(struct pcmcia_socket *sock, u_int *value) } -static int pd6729_get_socket(struct pcmcia_socket *sock, socket_state_t *state) -{ - struct pd6729_socket *socket - = container_of(sock, struct pd6729_socket, socket); - unsigned char reg, vcc, vpp; - - state->flags = 0; - state->Vcc = 0; - state->Vpp = 0; - state->io_irq = 0; - state->csc_mask = 0; - - /* First the power status of the socket */ - reg = indirect_read(socket, I365_POWER); - - if (reg & I365_PWR_AUTO) - state->flags |= SS_PWR_AUTO; /* Automatic Power Switch */ - - if (reg & I365_PWR_OUT) - state->flags |= SS_OUTPUT_ENA; /* Output signals are enabled */ - - vcc = reg & I365_VCC_MASK; vpp = reg & I365_VPP1_MASK; - - if (reg & I365_VCC_5V) { - state->Vcc = (indirect_read(socket, PD67_MISC_CTL_1) & - PD67_MC1_VCC_3V) ? 33 : 50; - - if (vpp == I365_VPP1_5V) { - if (state->Vcc == 50) - state->Vpp = 50; - else - state->Vpp = 33; - } - if (vpp == I365_VPP1_12V) - state->Vpp = 120; - } - - /* Now the IO card, RESET flags and IO interrupt */ - reg = indirect_read(socket, I365_INTCTL); - - if ((reg & I365_PC_RESET) == 0) - state->flags |= SS_RESET; - if (reg & I365_PC_IOCARD) - state->flags |= SS_IOCARD; /* This is an IO card */ - - /* Set the IRQ number */ - state->io_irq = socket->card_irq; - - /* Card status change */ - reg = indirect_read(socket, I365_CSCINT); - - if (reg & I365_CSC_DETECT) - state->csc_mask |= SS_DETECT; /* Card detect is enabled */ - - if (state->flags & SS_IOCARD) {/* IO Cards behave different */ - if (reg & I365_CSC_STSCHG) - state->csc_mask |= SS_STSCHG; - } else { - if (reg & I365_CSC_BVD1) - state->csc_mask |= SS_BATDEAD; - if (reg & I365_CSC_BVD2) - state->csc_mask |= SS_BATWARN; - if (reg & I365_CSC_READY) - state->csc_mask |= SS_READY; - } - - return 0; -} - static int pd6729_set_socket(struct pcmcia_socket *sock, socket_state_t *state) { struct pd6729_socket *socket @@ -640,7 +571,6 @@ static int pd6729_init(struct pcmcia_socket *sock) static struct pccard_operations pd6729_operations = { .init = pd6729_init, .get_status = pd6729_get_status, - .get_socket = pd6729_get_socket, .set_socket = pd6729_set_socket, .set_io_map = pd6729_set_io_map, .set_mem_map = pd6729_set_mem_map, diff --git a/drivers/pcmcia/soc_common.c b/drivers/pcmcia/soc_common.c index 9e7ccd8a4321..a563bd9a8898 100644 --- a/drivers/pcmcia/soc_common.c +++ b/drivers/pcmcia/soc_common.c @@ -296,25 +296,6 @@ soc_common_pcmcia_get_status(struct pcmcia_socket *sock, unsigned int *status) } -/* - * Implements the get_socket() operation for the in-kernel PCMCIA - * service (formerly SS_GetSocket in Card Services). Not a very - * exciting routine. - * - * Returns: 0 - */ -static int -soc_common_pcmcia_get_socket(struct pcmcia_socket *sock, socket_state_t *state) -{ - struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock); - - debug(skt, 2, "\n"); - - *state = skt->cs_state; - - return 0; -} - /* * Implements the set_socket() operation for the in-kernel PCMCIA * service (formerly SS_SetSocket in Card Services). We more or @@ -528,7 +509,6 @@ static struct pccard_operations soc_common_pcmcia_operations = { .init = soc_common_pcmcia_sock_init, .suspend = soc_common_pcmcia_suspend, .get_status = soc_common_pcmcia_get_status, - .get_socket = soc_common_pcmcia_get_socket, .set_socket = soc_common_pcmcia_set_socket, .set_io_map = soc_common_pcmcia_set_io_map, .set_mem_map = soc_common_pcmcia_set_mem_map, diff --git a/drivers/pcmcia/tcic.c b/drivers/pcmcia/tcic.c index e31263864377..73bad1d5cb23 100644 --- a/drivers/pcmcia/tcic.c +++ b/drivers/pcmcia/tcic.c @@ -181,13 +181,6 @@ static void tcic_setl(u_char reg, u_int data) outw(data >> 16, tcic_base+reg+2); } -static u_char tcic_aux_getb(u_short reg) -{ - u_char mode = (tcic_getb(TCIC_MODE) & TCIC_MODE_PGMMASK) | reg; - tcic_setb(TCIC_MODE, mode); - return tcic_getb(TCIC_AUX); -} - static void tcic_aux_setb(u_short reg, u_char data) { u_char mode = (tcic_getb(TCIC_MODE) & TCIC_MODE_PGMMASK) | reg; @@ -641,59 +634,6 @@ static int tcic_get_status(struct pcmcia_socket *sock, u_int *value) debug(1, "GetStatus(%d) = %#2.2x\n", psock, *value); return 0; } /* tcic_get_status */ - -/*====================================================================*/ - -static int tcic_get_socket(struct pcmcia_socket *sock, socket_state_t *state) -{ - u_short psock = container_of(sock, struct tcic_socket, socket)->psock; - u_char reg; - u_short scf1, scf2; - - tcic_setl(TCIC_ADDR, (psock << TCIC_ADDR_SS_SHFT) - | TCIC_ADDR_INDREG | TCIC_SCF1(psock)); - scf1 = tcic_getw(TCIC_DATA); - state->flags = (scf1 & TCIC_SCF1_IOSTS) ? SS_IOCARD : 0; - state->flags |= (scf1 & TCIC_SCF1_DMA_MASK) ? SS_DMA_MODE : 0; - state->flags |= (scf1 & TCIC_SCF1_SPKR) ? SS_SPKR_ENA : 0; - if (tcic_getb(TCIC_SCTRL) & TCIC_SCTRL_ENA) - state->flags |= SS_OUTPUT_ENA; - state->io_irq = scf1 & TCIC_SCF1_IRQ_MASK; - if (state->io_irq == 1) state->io_irq = 11; - - reg = tcic_getb(TCIC_PWR); - state->Vcc = state->Vpp = 0; - if (reg & TCIC_PWR_VCC(psock)) { - if (reg & TCIC_PWR_VPP(psock)) - state->Vcc = 50; - else - state->Vcc = state->Vpp = 50; - } else { - if (reg & TCIC_PWR_VPP(psock)) { - state->Vcc = 50; - state->Vpp = 120; - } - } - reg = tcic_aux_getb(TCIC_AUX_ILOCK); - state->flags |= (reg & TCIC_ILOCK_CRESET) ? SS_RESET : 0; - - /* Card status change interrupt mask */ - tcic_setw(TCIC_ADDR, TCIC_SCF2(psock)); - scf2 = tcic_getw(TCIC_DATA); - state->csc_mask = (scf2 & TCIC_SCF2_MCD) ? 0 : SS_DETECT; - if (state->flags & SS_IOCARD) { - state->csc_mask |= (scf2 & TCIC_SCF2_MLBAT1) ? 0 : SS_STSCHG; - } else { - state->csc_mask |= (scf2 & TCIC_SCF2_MLBAT1) ? 0 : SS_BATDEAD; - state->csc_mask |= (scf2 & TCIC_SCF2_MLBAT2) ? 0 : SS_BATWARN; - state->csc_mask |= (scf2 & TCIC_SCF2_MRDY) ? 0 : SS_READY; - } - - debug(1, "GetSocket(%d) = flags %#3.3x, Vcc %d, Vpp %d, " - "io_irq %d, csc_mask %#2.2x\n", psock, state->flags, - state->Vcc, state->Vpp, state->io_irq, state->csc_mask); - return 0; -} /* tcic_get_socket */ /*====================================================================*/ @@ -874,7 +814,6 @@ static int tcic_init(struct pcmcia_socket *s) static struct pccard_operations tcic_operations = { .init = tcic_init, .get_status = tcic_get_status, - .get_socket = tcic_get_socket, .set_socket = tcic_set_socket, .set_io_map = tcic_set_io_map, .set_mem_map = tcic_set_mem_map, diff --git a/drivers/pcmcia/vrc4171_card.c b/drivers/pcmcia/vrc4171_card.c index 38a028c725d4..24c547ef512b 100644 --- a/drivers/pcmcia/vrc4171_card.c +++ b/drivers/pcmcia/vrc4171_card.c @@ -301,75 +301,6 @@ static int pccard_get_status(struct pcmcia_socket *sock, u_int *value) return 0; } -static inline u_char get_Vcc_value(uint8_t voltage) -{ - switch (voltage) { - case VCC_STATUS_3V: - return 33; - case VCC_STATUS_5V: - return 50; - default: - break; - } - - return 0; -} - -static inline u_char get_Vpp_value(uint8_t power, u_char Vcc) -{ - if ((power & 0x03) == 0x01 || (power & 0x03) == 0x02) - return Vcc; - - return 0; -} - -static int pccard_get_socket(struct pcmcia_socket *sock, socket_state_t *state) -{ - unsigned int slot; - uint8_t power, voltage, control, cscint; - - if (sock == NULL || sock->sock >= CARD_MAX_SLOTS || state == NULL) - return -EINVAL; - - slot = sock->sock; - - power = exca_read_byte(slot, I365_POWER); - voltage = exca_read_byte(slot, CARD_VOLTAGE_SELECT); - - state->Vcc = get_Vcc_value(voltage); - state->Vpp = get_Vpp_value(power, state->Vcc); - - state->flags = 0; - if (power & POWER_ENABLE) - state->flags |= SS_PWR_AUTO; - if (power & I365_PWR_OUT) - state->flags |= SS_OUTPUT_ENA; - - control = exca_read_byte(slot, I365_INTCTL); - if (control & I365_PC_IOCARD) - state->flags |= SS_IOCARD; - if (!(control & I365_PC_RESET)) - state->flags |= SS_RESET; - - cscint = exca_read_byte(slot, I365_CSCINT); - state->csc_mask = 0; - if (state->flags & SS_IOCARD) { - if (cscint & I365_CSC_STSCHG) - state->flags |= SS_STSCHG; - } else { - if (cscint & I365_CSC_BVD1) - state->csc_mask |= SS_BATDEAD; - if (cscint & I365_CSC_BVD2) - state->csc_mask |= SS_BATWARN; - } - if (cscint & I365_CSC_READY) - state->csc_mask |= SS_READY; - if (cscint & I365_CSC_DETECT) - state->csc_mask |= SS_DETECT; - - return 0; -} - static inline uint8_t set_Vcc_value(u_char Vcc) { switch (Vcc) { @@ -551,7 +482,6 @@ static int pccard_set_mem_map(struct pcmcia_socket *sock, struct pccard_mem_map static struct pccard_operations vrc4171_pccard_operations = { .init = pccard_init, .get_status = pccard_get_status, - .get_socket = pccard_get_socket, .set_socket = pccard_set_socket, .set_io_map = pccard_set_io_map, .set_mem_map = pccard_set_mem_map, diff --git a/drivers/pcmcia/vrc4173_cardu.c b/drivers/pcmcia/vrc4173_cardu.c index db91259dc50e..1b277d2c1c96 100644 --- a/drivers/pcmcia/vrc4173_cardu.c +++ b/drivers/pcmcia/vrc4173_cardu.c @@ -198,48 +198,6 @@ static int cardu_get_status(unsigned int sock, u_int *value) return 0; } -static inline u_char get_Vcc_value(uint8_t val) -{ - switch (val & VCC_MASK) { - case VCC_3V: - return 33; - case VCC_5V: - return 50; - } - - return 0; -} - -static inline u_char get_Vpp_value(uint8_t val) -{ - switch (val & VPP_MASK) { - case VPP_12V: - return 120; - case VPP_VCC: - return get_Vcc_value(val); - } - - return 0; -} - -static int cardu_get_socket(unsigned int sock, socket_state_t *state) -{ - vrc4173_socket_t *socket = &cardu_sockets[sock]; - uint8_t val; - - val = exca_readb(socket, PWR_CNT); - state->Vcc = get_Vcc_value(val); - state->Vpp = get_Vpp_value(val); - state->flags = 0; - if (val & CARD_OUT_EN) state->flags |= SS_OUTPUT_ENA; - - val = exca_readb(socket, INT_GEN_CNT); - if (!(val & CARD_REST0)) state->flags |= SS_RESET; - if (val & CARD_TYPE_IO) state->flags |= SS_IOCARD; - - return 0; -} - static inline uint8_t set_Vcc_value(u_char Vcc) { switch (Vcc) { @@ -431,7 +389,6 @@ static struct pccard_operations cardu_operations = { .register_callback = cardu_register_callback, .inquire_socket = cardu_inquire_socket, .get_status = cardu_get_status, - .get_socket = cardu_get_socket, .set_socket = cardu_set_socket, .get_io_map = cardu_get_io_map, .set_io_map = cardu_set_io_map, diff --git a/drivers/pcmcia/yenta_socket.c b/drivers/pcmcia/yenta_socket.c index 8bfe72b71302..fa0625c438dc 100644 --- a/drivers/pcmcia/yenta_socket.c +++ b/drivers/pcmcia/yenta_socket.c @@ -224,95 +224,6 @@ static int yenta_get_status(struct pcmcia_socket *sock, unsigned int *value) return 0; } -static void yenta_get_power(struct yenta_socket *socket, socket_state_t *state) -{ - if (!(cb_readl(socket, CB_SOCKET_STATE) & CB_CBCARD) && - (socket->flags & YENTA_16BIT_POWER_EXCA)) { - u8 reg, vcc, vpp; - - reg = exca_readb(socket, I365_POWER); - vcc = reg & I365_VCC_MASK; - vpp = reg & I365_VPP1_MASK; - state->Vcc = state->Vpp = 0; - - if (socket->flags & YENTA_16BIT_POWER_DF) { - if (vcc == I365_VCC_3V) - state->Vcc = 33; - if (vcc == I365_VCC_5V) - state->Vcc = 50; - if (vpp == I365_VPP1_5V) - state->Vpp = state->Vcc; - if (vpp == I365_VPP1_12V) - state->Vpp = 120; - } else { - if (reg & I365_VCC_5V) { - state->Vcc = 50; - if (vpp == I365_VPP1_5V) - state->Vpp = 50; - if (vpp == I365_VPP1_12V) - state->Vpp = 120; - } - } - } else { - u32 control; - - control = cb_readl(socket, CB_SOCKET_CONTROL); - - switch (control & CB_SC_VCC_MASK) { - case CB_SC_VCC_5V: state->Vcc = 50; break; - case CB_SC_VCC_3V: state->Vcc = 33; break; - default: state->Vcc = 0; - } - - switch (control & CB_SC_VPP_MASK) { - case CB_SC_VPP_12V: state->Vpp = 120; break; - case CB_SC_VPP_5V: state->Vpp = 50; break; - case CB_SC_VPP_3V: state->Vpp = 33; break; - default: state->Vpp = 0; - } - } -} - -static int yenta_get_socket(struct pcmcia_socket *sock, socket_state_t *state) -{ - struct yenta_socket *socket = container_of(sock, struct yenta_socket, socket); - u8 reg; - u32 control; - - control = cb_readl(socket, CB_SOCKET_CONTROL); - - yenta_get_power(socket, state); - state->io_irq = socket->io_irq; - - if (cb_readl(socket, CB_SOCKET_STATE) & CB_CBCARD) { - u16 bridge = config_readw(socket, CB_BRIDGE_CONTROL); - if (bridge & CB_BRIDGE_CRST) - state->flags |= SS_RESET; - return 0; - } - - /* 16-bit card state.. */ - reg = exca_readb(socket, I365_POWER); - state->flags = (reg & I365_PWR_AUTO) ? SS_PWR_AUTO : 0; - state->flags |= (reg & I365_PWR_OUT) ? SS_OUTPUT_ENA : 0; - - reg = exca_readb(socket, I365_INTCTL); - state->flags |= (reg & I365_PC_RESET) ? 0 : SS_RESET; - state->flags |= (reg & I365_PC_IOCARD) ? SS_IOCARD : 0; - - reg = exca_readb(socket, I365_CSCINT); - state->csc_mask = (reg & I365_CSC_DETECT) ? SS_DETECT : 0; - if (state->flags & SS_IOCARD) { - state->csc_mask |= (reg & I365_CSC_STSCHG) ? SS_STSCHG : 0; - } else { - state->csc_mask |= (reg & I365_CSC_BVD1) ? SS_BATDEAD : 0; - state->csc_mask |= (reg & I365_CSC_BVD2) ? SS_BATWARN : 0; - state->csc_mask |= (reg & I365_CSC_READY) ? SS_READY : 0; - } - - return 0; -} - static void yenta_set_power(struct yenta_socket *socket, socket_state_t *state) { /* some birdges require to use the ExCA registers to power 16bit cards */ @@ -828,7 +739,6 @@ static struct pccard_operations yenta_socket_operations = { .init = yenta_sock_init, .suspend = yenta_sock_suspend, .get_status = yenta_get_status, - .get_socket = yenta_get_socket, .set_socket = yenta_set_socket, .set_io_map = yenta_set_io_map, .set_mem_map = yenta_set_mem_map, diff --git a/include/pcmcia/ss.h b/include/pcmcia/ss.h index 25e6bf05e25c..9f7dab8db984 100644 --- a/include/pcmcia/ss.h +++ b/include/pcmcia/ss.h @@ -119,7 +119,6 @@ struct pccard_operations { int (*init)(struct pcmcia_socket *sock); int (*suspend)(struct pcmcia_socket *sock); int (*get_status)(struct pcmcia_socket *sock, u_int *value); - int (*get_socket)(struct pcmcia_socket *sock, socket_state_t *state); int (*set_socket)(struct pcmcia_socket *sock, socket_state_t *state); int (*set_io_map)(struct pcmcia_socket *sock, struct pccard_io_map *io); int (*set_mem_map)(struct pcmcia_socket *sock, struct pccard_mem_map *mem); From de75914ee103a30d82ad21b39b7e04f70e4fa1f0 Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Wed, 28 Sep 2005 19:41:56 +0200 Subject: [PATCH 28/48] [PATCH] pcmcia: validate_mem shouldn't be void Add a return value to pcmcia_validate_mem. Only if we have enough memory available to map the CIS, we should proceed in trying to determine information about the device. Signed-off-by: Dominik Brodowski --- drivers/pcmcia/cs_internal.h | 2 +- drivers/pcmcia/ds.c | 4 +- drivers/pcmcia/rsrc_mgr.c | 6 +- drivers/pcmcia/rsrc_nonstatic.c | 125 +++++++++++++++++--------------- include/pcmcia/ss.h | 2 +- 5 files changed, 76 insertions(+), 63 deletions(-) diff --git a/drivers/pcmcia/cs_internal.h b/drivers/pcmcia/cs_internal.h index 55867bc7f199..634426b78f2c 100644 --- a/drivers/pcmcia/cs_internal.h +++ b/drivers/pcmcia/cs_internal.h @@ -117,7 +117,7 @@ int verify_cis_cache(struct pcmcia_socket *s); int pccard_read_tuple(struct pcmcia_socket *s, unsigned int function, cisdata_t code, void *parse); /* In rsrc_mgr */ -void pcmcia_validate_mem(struct pcmcia_socket *s); +int pcmcia_validate_mem(struct pcmcia_socket *s); struct resource *pcmcia_find_io_region(unsigned long base, int num, unsigned long align, struct pcmcia_socket *s); int pcmcia_adjust_io_region(struct resource *res, unsigned long r_start, diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index 6fb76399547e..b120794c03a9 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -583,7 +583,9 @@ static int pcmcia_card_add(struct pcmcia_socket *s) if (!(s->resource_setup_done)) return -EAGAIN; /* try again, but later... */ - pcmcia_validate_mem(s); + if (pcmcia_validate_mem(s)) + return -EAGAIN; /* try again, but later... */ + ret = pccard_validate_cis(s, BIND_FN_ALL, &cisinfo); if (ret || !cisinfo.Chains) { ds_dbg(0, "invalid CIS or invalid resources\n"); diff --git a/drivers/pcmcia/rsrc_mgr.c b/drivers/pcmcia/rsrc_mgr.c index 0668384ebc8b..b02598a5a912 100644 --- a/drivers/pcmcia/rsrc_mgr.c +++ b/drivers/pcmcia/rsrc_mgr.c @@ -98,10 +98,12 @@ int pcmcia_adjust_resource_info(adjust_t *adj) } EXPORT_SYMBOL(pcmcia_adjust_resource_info); -void pcmcia_validate_mem(struct pcmcia_socket *s) +int pcmcia_validate_mem(struct pcmcia_socket *s) { if (s->resource_ops->validate_mem) - s->resource_ops->validate_mem(s); + return s->resource_ops->validate_mem(s); + /* if there is no callback, we can assume that everything is OK */ + return 0; } EXPORT_SYMBOL(pcmcia_validate_mem); diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c index 00960a379b9c..ebfcab5df9ea 100644 --- a/drivers/pcmcia/rsrc_nonstatic.c +++ b/drivers/pcmcia/rsrc_nonstatic.c @@ -407,56 +407,62 @@ static int do_mem_probe(u_long base, u_long num, struct pcmcia_socket *s) static u_long inv_probe(struct resource_map *m, struct pcmcia_socket *s) { - struct socket_data *s_data = s->resource_data; - u_long ok; - if (m == &s_data->mem_db) - return 0; - ok = inv_probe(m->next, s); - if (ok) { - if (m->base >= 0x100000) - sub_interval(&s_data->mem_db, m->base, m->num); - return ok; - } - if (m->base < 0x100000) - return 0; - return do_mem_probe(m->base, m->num, s); + struct socket_data *s_data = s->resource_data; + u_long ok; + if (m == &s_data->mem_db) + return 0; + ok = inv_probe(m->next, s); + if (ok) { + if (m->base >= 0x100000) + sub_interval(&s_data->mem_db, m->base, m->num); + return ok; + } + if (m->base < 0x100000) + return 0; + return do_mem_probe(m->base, m->num, s); } -static void validate_mem(struct pcmcia_socket *s, unsigned int probe_mask) +static int validate_mem(struct pcmcia_socket *s, unsigned int probe_mask) { - struct resource_map *m, mm; - static u_char order[] = { 0xd0, 0xe0, 0xc0, 0xf0 }; - u_long b, i, ok = 0; - struct socket_data *s_data = s->resource_data; + struct resource_map *m, mm; + static unsigned char order[] = { 0xd0, 0xe0, 0xc0, 0xf0 }; + unsigned long b, i, ok = 0; + struct socket_data *s_data = s->resource_data; - /* We do up to four passes through the list */ - if (probe_mask & MEM_PROBE_HIGH) { - if (inv_probe(s_data->mem_db.next, s) > 0) - return; - printk(KERN_NOTICE "cs: warning: no high memory space " - "available!\n"); - } - if ((probe_mask & MEM_PROBE_LOW) == 0) - return; - for (m = s_data->mem_db.next; m != &s_data->mem_db; m = mm.next) { - mm = *m; - /* Only probe < 1 MB */ - if (mm.base >= 0x100000) continue; - if ((mm.base | mm.num) & 0xffff) { - ok += do_mem_probe(mm.base, mm.num, s); - continue; + /* We do up to four passes through the list */ + if (probe_mask & MEM_PROBE_HIGH) { + if (inv_probe(s_data->mem_db.next, s) > 0) + return 0; + printk(KERN_NOTICE "cs: warning: no high memory space " + "available!\n"); + return -ENODEV; } - /* Special probe for 64K-aligned block */ - for (i = 0; i < 4; i++) { - b = order[i] << 12; - if ((b >= mm.base) && (b+0x10000 <= mm.base+mm.num)) { - if (ok >= mem_limit) - sub_interval(&s_data->mem_db, b, 0x10000); - else - ok += do_mem_probe(b, 0x10000, s); - } + + for (m = s_data->mem_db.next; m != &s_data->mem_db; m = mm.next) { + mm = *m; + /* Only probe < 1 MB */ + if (mm.base >= 0x100000) + continue; + if ((mm.base | mm.num) & 0xffff) { + ok += do_mem_probe(mm.base, mm.num, s); + continue; + } + /* Special probe for 64K-aligned block */ + for (i = 0; i < 4; i++) { + b = order[i] << 12; + if ((b >= mm.base) && (b+0x10000 <= mm.base+mm.num)) { + if (ok >= mem_limit) + sub_interval(&s_data->mem_db, b, 0x10000); + else + ok += do_mem_probe(b, 0x10000, s); + } + } } - } + + if (ok > 0) + return 0; + + return -ENODEV; } #else /* CONFIG_PCMCIA_PROBE */ @@ -478,27 +484,30 @@ static void validate_mem(struct pcmcia_socket *s, unsigned int probe_mask) /* * Locking note: Must be called with skt_sem held! */ -static void pcmcia_nonstatic_validate_mem(struct pcmcia_socket *s) +static int pcmcia_nonstatic_validate_mem(struct pcmcia_socket *s) { struct socket_data *s_data = s->resource_data; - if (probe_mem) { - unsigned int probe_mask; + unsigned int probe_mask = MEM_PROBE_LOW; + int ret = 0; - down(&rsrc_sem); + if (!probe_mem) + return 0; - probe_mask = MEM_PROBE_LOW; - if (s->features & SS_CAP_PAGE_REGS) - probe_mask = MEM_PROBE_HIGH; + down(&rsrc_sem); - if (probe_mask & ~s_data->rsrc_mem_probe) { + if (s->features & SS_CAP_PAGE_REGS) + probe_mask = MEM_PROBE_HIGH; + + if (probe_mask & ~s_data->rsrc_mem_probe) { + if (s->state & SOCKET_PRESENT) + ret = validate_mem(s, probe_mask); + if (!ret) s_data->rsrc_mem_probe |= probe_mask; - - if (s->state & SOCKET_PRESENT) - validate_mem(s, probe_mask); - } - - up(&rsrc_sem); } + + up(&rsrc_sem); + + return ret; } struct pcmcia_align_data { diff --git a/include/pcmcia/ss.h b/include/pcmcia/ss.h index 9f7dab8db984..2889a69a7a8f 100644 --- a/include/pcmcia/ss.h +++ b/include/pcmcia/ss.h @@ -125,7 +125,7 @@ struct pccard_operations { }; struct pccard_resource_ops { - void (*validate_mem) (struct pcmcia_socket *s); + int (*validate_mem) (struct pcmcia_socket *s); int (*adjust_io_region) (struct resource *res, unsigned long r_start, unsigned long r_end, From 2cff944720332535a24b7eae16cff32055a43048 Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Wed, 16 Nov 2005 21:29:26 -0800 Subject: [PATCH 29/48] [PATCH] pcmcia: validate_mem fix Also return a value if CONFIG_PCMCIA_PROBE is not set. Signed-off-by: Andrew Morton Signed-off-by: Dominik Brodowski --- drivers/pcmcia/rsrc_nonstatic.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c index ebfcab5df9ea..6b18092205b1 100644 --- a/drivers/pcmcia/rsrc_nonstatic.c +++ b/drivers/pcmcia/rsrc_nonstatic.c @@ -467,15 +467,19 @@ static int validate_mem(struct pcmcia_socket *s, unsigned int probe_mask) #else /* CONFIG_PCMCIA_PROBE */ -static void validate_mem(struct pcmcia_socket *s, unsigned int probe_mask) +static int validate_mem(struct pcmcia_socket *s, unsigned int probe_mask) { struct resource_map *m, mm; struct socket_data *s_data = s->resource_data; + unsigned long ok = 0; for (m = s_data->mem_db.next; m != &s_data->mem_db; m = mm.next) { mm = *m; - do_mem_probe(mm.base, mm.num, s); + ok += do_mem_probe(mm.base, mm.num, s); } + if (ok > 0) + return 0; + return -ENODEV; } #endif /* CONFIG_PCMCIA_PROBE */ From 63e7ebd06402951bc8863ba5b7bc9b9f42044849 Mon Sep 17 00:00:00 2001 From: Daniel Ritz Date: Thu, 3 Nov 2005 21:12:14 +0100 Subject: [PATCH 30/48] [PATCH] yenta: make bridge specific init code configurable Make the bridge specific initialization code config options depending on CONFIG_EMBEDDED. Config options for TI/EnE, Toshiba, Ricoh and O2Micro are available. Disabling all of the specific tweaks cuts off more than half of yenta_socket.ko. Signed-off-by: Daniel Ritz Signed-off-by: Dominik Brodowski --- drivers/pcmcia/Kconfig | 25 ++++++++++++++++++++++ drivers/pcmcia/ti113x.h | 4 ++-- drivers/pcmcia/yenta_socket.c | 39 +++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 2 deletions(-) diff --git a/drivers/pcmcia/Kconfig b/drivers/pcmcia/Kconfig index 309eb557f9a3..ea00b1f3cb44 100644 --- a/drivers/pcmcia/Kconfig +++ b/drivers/pcmcia/Kconfig @@ -116,6 +116,31 @@ config YENTA If unsure, say Y. +config YENTA_O2 + default y + bool "Special initialization for O2Micro bridges" if EMBEDDED + depends on YENTA + +config YENTA_RICOH + default y + bool "Special initialization for Ricoh bridges" if EMBEDDED + depends on YENTA + +config YENTA_TI + default y + bool "Special initialization for TI and EnE bridges" if EMBEDDED + depends on YENTA + +config YENTA_ENE_TUNE + default y + bool "Auto-tune EnE bridges for CB cards" if EMBEDDED + depends on YENTA_TI && CARDBUS + +config YENTA_TOSHIBA + default y + bool "Special initialization for Toshiba ToPIC bridges" if EMBEDDED + depends on YENTA + config PD6729 tristate "Cirrus PD6729 compatible bridge support" depends on PCMCIA && PCI diff --git a/drivers/pcmcia/ti113x.h b/drivers/pcmcia/ti113x.h index 539b5cd1a598..d5b4ff74462e 100644 --- a/drivers/pcmcia/ti113x.h +++ b/drivers/pcmcia/ti113x.h @@ -873,7 +873,7 @@ static int ti1250_override(struct yenta_socket *socket) * Some fixup code to make everybody happy (TM). */ -#ifdef CONFIG_CARDBUS +#ifdef CONFIG_YENTA_ENE_TUNE /** * set/clear various test bits: * Defaults to clear the bit. @@ -937,7 +937,7 @@ static int ene_override(struct yenta_socket *socket) } #else # define ene_override ti1250_override -#endif +#endif /* !CONFIG_YENTA_ENE_TUNE */ #endif /* _LINUX_TI113X_H */ diff --git a/drivers/pcmcia/yenta_socket.c b/drivers/pcmcia/yenta_socket.c index fa0625c438dc..826e7e133269 100644 --- a/drivers/pcmcia/yenta_socket.c +++ b/drivers/pcmcia/yenta_socket.c @@ -49,7 +49,13 @@ MODULE_PARM_DESC(pwr_irqs_off, "Force IRQs off during power-on of slot. Use only #define to_cycles(ns) ((ns)/120) #define to_ns(cycles) ((cycles)*120) +/** + * yenta PCI irq probing. + * currently only used in the TI/EnE initialization code + */ +#ifdef CONFIG_YENTA_TI static int yenta_probe_cb_irq(struct yenta_socket *socket); +#endif static unsigned int override_bios; @@ -745,10 +751,18 @@ static struct pccard_operations yenta_socket_operations = { }; +#ifdef CONFIG_YENTA_TI #include "ti113x.h" +#endif +#ifdef CONFIG_YENTA_RICOH #include "ricoh.h" +#endif +#ifdef CONFIG_YENTA_TOSHIBA #include "topic.h" +#endif +#ifdef CONFIG_YENTA_O2 #include "o2micro.h" +#endif enum { CARDBUS_TYPE_DEFAULT = -1, @@ -768,6 +782,7 @@ enum { * initialization sequences etc details. List them here.. */ static struct cardbus_type cardbus_type[] = { +#ifdef CONFIG_YENTA_TI [CARDBUS_TYPE_TI] = { .override = ti_override, .save_state = ti_save_state, @@ -792,27 +807,36 @@ static struct cardbus_type cardbus_type[] = { .restore_state = ti_restore_state, .sock_init = ti_init, }, +#endif +#ifdef CONFIG_YENTA_RICOH [CARDBUS_TYPE_RICOH] = { .override = ricoh_override, .save_state = ricoh_save_state, .restore_state = ricoh_restore_state, }, +#endif +#ifdef CONFIG_YENTA_TOSHIBA [CARDBUS_TYPE_TOPIC95] = { .override = topic95_override, }, [CARDBUS_TYPE_TOPIC97] = { .override = topic97_override, }, +#endif +#ifdef CONFIG_YENTA_O2 [CARDBUS_TYPE_O2MICRO] = { .override = o2micro_override, .restore_state = o2micro_restore_state, }, +#endif +#ifdef CONFIG_YENTA_TI [CARDBUS_TYPE_ENE] = { .override = ene_override, .save_state = ti_save_state, .restore_state = ti_restore_state, .sock_init = ti_init, }, +#endif }; @@ -858,6 +882,12 @@ static unsigned int yenta_probe_irq(struct yenta_socket *socket, u32 isa_irq_mas } +/** + * yenta PCI irq probing. + * currently only used in the TI/EnE initialization code + */ +#ifdef CONFIG_YENTA_TI + /* interrupt handler, only used during probing */ static irqreturn_t yenta_probe_handler(int irq, void *dev_id, struct pt_regs *regs) { @@ -910,6 +940,7 @@ static int yenta_probe_cb_irq(struct yenta_socket *socket) return (int) socket->probe_status; } +#endif /* CONFIG_YENTA_TI */ /* @@ -1173,6 +1204,7 @@ static struct pci_device_id yenta_table [] = { * advanced overrides instead. (I can't get the * data sheets for these devices. --rmk) */ +#ifdef CONFIG_YENTA_TI CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1210, TI), CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1130, TI113X), @@ -1215,18 +1247,25 @@ static struct pci_device_id yenta_table [] = { CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_1225, ENE), CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_1410, ENE), CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_1420, ENE), +#endif /* CONFIG_YENTA_TI */ +#ifdef CONFIG_YENTA_RICOH CB_ID(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C465, RICOH), CB_ID(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C466, RICOH), CB_ID(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C475, RICOH), CB_ID(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C476, RICOH), CB_ID(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C478, RICOH), +#endif +#ifdef CONFIG_YENTA_TOSHIBA CB_ID(PCI_VENDOR_ID_TOSHIBA, PCI_DEVICE_ID_TOSHIBA_TOPIC95, TOPIC95), CB_ID(PCI_VENDOR_ID_TOSHIBA, PCI_DEVICE_ID_TOSHIBA_TOPIC97, TOPIC97), CB_ID(PCI_VENDOR_ID_TOSHIBA, PCI_DEVICE_ID_TOSHIBA_TOPIC100, TOPIC97), +#endif +#ifdef CONFIG_YENTA_O2 CB_ID(PCI_VENDOR_ID_O2, PCI_ANY_ID, O2MICRO), +#endif /* match any cardbus bridge */ CB_ID(PCI_ANY_ID, PCI_ANY_ID, DEFAULT), From 98e4c28b7ec390c2dad6a4c69d69629c0f7e8b10 Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Mon, 14 Nov 2005 21:21:18 +0100 Subject: [PATCH 31/48] [PATCH] pcmcia: new suspend core Move the suspend and resume methods out of the event handler, and into special functions. Also use these functions for pre- and post-reset, as almost all drivers already do, and the remaining ones can easily be converted. Bugfix to include/pcmcia/ds.c Signed-off-by: Andrew Morton Signed-off-by: Dominik Brodowski --- Documentation/pcmcia/driver-changes.txt | 6 + drivers/bluetooth/bluecard_cs.c | 37 +++--- drivers/bluetooth/bt3c_cs.c | 37 +++--- drivers/bluetooth/btuart_cs.c | 38 ++++--- drivers/bluetooth/dtl1_cs.c | 37 +++--- drivers/char/pcmcia/cm4000_cs.c | 61 +++++----- drivers/char/pcmcia/cm4040_cs.c | 48 ++++---- drivers/char/pcmcia/synclink_cs.c | 47 +++++--- drivers/ide/legacy/ide-cs.c | 38 ++++--- drivers/isdn/hardware/avm/avm_cs.c | 38 ++++--- drivers/isdn/hisax/avma1_cs.c | 38 ++++--- drivers/isdn/hisax/elsa_cs.c | 46 +++++--- drivers/isdn/hisax/sedlbauer_cs.c | 50 ++++---- drivers/isdn/hisax/teles_cs.c | 46 +++++--- drivers/mtd/maps/pcmciamtd.c | 36 +++--- drivers/net/pcmcia/3c574_cs.c | 56 +++++---- drivers/net/pcmcia/3c589_cs.c | 56 +++++---- drivers/net/pcmcia/axnet_cs.c | 59 ++++++---- drivers/net/pcmcia/com20020_cs.c | 62 ++++++---- drivers/net/pcmcia/fmvj18x_cs.c | 57 ++++++---- drivers/net/pcmcia/ibmtr_cs.c | 59 ++++++---- drivers/net/pcmcia/nmclan_cs.c | 57 ++++++---- drivers/net/pcmcia/pcnet_cs.c | 58 ++++++---- drivers/net/pcmcia/smc91c92_cs.c | 109 ++++++++++-------- drivers/net/pcmcia/xirc2ps_cs.c | 61 ++++++---- drivers/net/wireless/airo_cs.c | 50 ++++---- drivers/net/wireless/atmel_cs.c | 50 ++++---- drivers/net/wireless/hostap/hostap_cs.c | 96 +++++++++------- drivers/net/wireless/netwave_cs.c | 57 ++++++---- drivers/net/wireless/orinoco_cs.c | 145 +++++++++++++----------- drivers/net/wireless/ray_cs.c | 59 ++++++---- drivers/net/wireless/spectrum_cs.c | 96 +++++++++------- drivers/net/wireless/wavelan_cs.c | 92 ++++++++------- drivers/net/wireless/wl3501_cs.c | 61 ++++++---- drivers/parport/parport_cs.c | 39 ++++--- drivers/pcmcia/ds.c | 10 ++ drivers/scsi/pcmcia/aha152x_stub.c | 48 ++++---- drivers/scsi/pcmcia/fdomain_stub.c | 42 ++++--- drivers/scsi/pcmcia/nsp_cs.c | 102 +++++++++-------- drivers/scsi/pcmcia/qlogic_stub.c | 59 ++++++---- drivers/scsi/pcmcia/sym53c500_cs.c | 69 ++++++----- drivers/serial/serial_cs.c | 31 ++--- drivers/telephony/ixj_pcmcia.c | 38 ++++--- drivers/usb/host/sl811_cs.c | 41 ++++--- include/pcmcia/ds.h | 6 + 45 files changed, 1434 insertions(+), 994 deletions(-) diff --git a/Documentation/pcmcia/driver-changes.txt b/Documentation/pcmcia/driver-changes.txt index 403e7b4dcdd4..5c822f54d46c 100644 --- a/Documentation/pcmcia/driver-changes.txt +++ b/Documentation/pcmcia/driver-changes.txt @@ -1,5 +1,11 @@ This file details changes in 2.6 which affect PCMCIA card driver authors: +* Move suspend, resume and reset out of event handler (as of 2.6.16) + int (*suspend) (struct pcmcia_device *dev); + int (*resume) (struct pcmcia_device *dev); + should be initialized in struct pcmcia_driver, and handle + (SUSPEND == RESET_PHYSICAL) and (RESUME == CARD_RESET) events + * event handler initialization in struct pcmcia_driver (as of 2.6.13) The event handler is notified of all events, and must be initialized as the event() callback in the driver's struct pcmcia_driver. diff --git a/drivers/bluetooth/bluecard_cs.c b/drivers/bluetooth/bluecard_cs.c index f36c563d72c4..5b24131e5430 100644 --- a/drivers/bluetooth/bluecard_cs.c +++ b/drivers/bluetooth/bluecard_cs.c @@ -1045,6 +1045,27 @@ static void bluecard_release(dev_link_t *link) link->state &= ~DEV_CONFIG; } +static int bluecard_suspend(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_release_configuration(link->handle); + + return 0; +} + +static int bluecard_resume(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + + link->state &= ~DEV_SUSPEND; + if (DEV_OK(link)) + pcmcia_request_configuration(link->handle, &link->conf); + + return 0; +} static int bluecard_event(event_t event, int priority, event_callback_args_t *args) { @@ -1063,20 +1084,6 @@ static int bluecard_event(event_t event, int priority, event_callback_args_t *ar link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; bluecard_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - if (link->state & DEV_CONFIG) - pcmcia_release_configuration(link->handle); - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (DEV_OK(link)) - pcmcia_request_configuration(link->handle, &link->conf); - break; } return 0; @@ -1099,6 +1106,8 @@ static struct pcmcia_driver bluecard_driver = { .event = bluecard_event, .detach = bluecard_detach, .id_table = bluecard_ids, + .suspend = bluecard_suspend, + .resume = bluecard_resume, }; static int __init init_bluecard_cs(void) diff --git a/drivers/bluetooth/bt3c_cs.c b/drivers/bluetooth/bt3c_cs.c index d2a0add19cc8..1d524baa24a0 100644 --- a/drivers/bluetooth/bt3c_cs.c +++ b/drivers/bluetooth/bt3c_cs.c @@ -891,6 +891,27 @@ static void bt3c_release(dev_link_t *link) link->state &= ~DEV_CONFIG; } +static int bt3c_suspend(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_release_configuration(link->handle); + + return 0; +} + +static int bt3c_resume(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + + link->state &= ~DEV_SUSPEND; + if (DEV_OK(link)) + pcmcia_request_configuration(link->handle, &link->conf); + + return 0; +} static int bt3c_event(event_t event, int priority, event_callback_args_t *args) { @@ -909,20 +930,6 @@ static int bt3c_event(event_t event, int priority, event_callback_args_t *args) link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; bt3c_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - if (link->state & DEV_CONFIG) - pcmcia_release_configuration(link->handle); - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (DEV_OK(link)) - pcmcia_request_configuration(link->handle, &link->conf); - break; } return 0; @@ -943,6 +950,8 @@ static struct pcmcia_driver bt3c_driver = { .event = bt3c_event, .detach = bt3c_detach, .id_table = bt3c_ids, + .suspend = bt3c_suspend, + .resume = bt3c_resume, }; static int __init init_bt3c_cs(void) diff --git a/drivers/bluetooth/btuart_cs.c b/drivers/bluetooth/btuart_cs.c index 529a28a3209d..1828ba6ca25e 100644 --- a/drivers/bluetooth/btuart_cs.c +++ b/drivers/bluetooth/btuart_cs.c @@ -811,6 +811,28 @@ static void btuart_release(dev_link_t *link) link->state &= ~DEV_CONFIG; } +static int btuart_suspend(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_release_configuration(link->handle); + + return 0; +} + +static int btuart_resume(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + + link->state &= ~DEV_SUSPEND; + if (DEV_OK(link)) + pcmcia_request_configuration(link->handle, &link->conf); + + return 0; +} + static int btuart_event(event_t event, int priority, event_callback_args_t *args) { @@ -829,20 +851,6 @@ static int btuart_event(event_t event, int priority, event_callback_args_t *args link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; btuart_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - if (link->state & DEV_CONFIG) - pcmcia_release_configuration(link->handle); - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (DEV_OK(link)) - pcmcia_request_configuration(link->handle, &link->conf); - break; } return 0; @@ -863,6 +871,8 @@ static struct pcmcia_driver btuart_driver = { .event = btuart_event, .detach = btuart_detach, .id_table = btuart_ids, + .suspend = btuart_suspend, + .resume = btuart_resume, }; static int __init init_btuart_cs(void) diff --git a/drivers/bluetooth/dtl1_cs.c b/drivers/bluetooth/dtl1_cs.c index dec5980a1cd6..9f9d3f91f455 100644 --- a/drivers/bluetooth/dtl1_cs.c +++ b/drivers/bluetooth/dtl1_cs.c @@ -763,6 +763,27 @@ static void dtl1_release(dev_link_t *link) link->state &= ~DEV_CONFIG; } +static int dtl1_suspend(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_release_configuration(link->handle); + + return 0; +} + +static int dtl1_resume(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + + link->state &= ~DEV_SUSPEND; + if (DEV_OK(link)) + pcmcia_request_configuration(link->handle, &link->conf); + + return 0; +} static int dtl1_event(event_t event, int priority, event_callback_args_t *args) { @@ -781,20 +802,6 @@ static int dtl1_event(event_t event, int priority, event_callback_args_t *args) link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; dtl1_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - if (link->state & DEV_CONFIG) - pcmcia_release_configuration(link->handle); - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (DEV_OK(link)) - pcmcia_request_configuration(link->handle, &link->conf); - break; } return 0; @@ -816,6 +823,8 @@ static struct pcmcia_driver dtl1_driver = { .event = dtl1_event, .detach = dtl1_detach, .id_table = dtl1_ids, + .suspend = dtl1_suspend, + .resume = dtl1_resume, }; static int __init init_dtl1_cs(void) diff --git a/drivers/char/pcmcia/cm4000_cs.c b/drivers/char/pcmcia/cm4000_cs.c index 61681c9f3f72..05e93054c98c 100644 --- a/drivers/char/pcmcia/cm4000_cs.c +++ b/drivers/char/pcmcia/cm4000_cs.c @@ -1893,33 +1893,6 @@ static int cm4000_event(event_t event, int priority, link->state &= ~DEV_PRESENT; stop_monitor(dev); break; - case CS_EVENT_PM_SUSPEND: - DEBUGP(5, dev, "CS_EVENT_PM_SUSPEND " - "(fall-through to CS_EVENT_RESET_PHYSICAL)\n"); - link->state |= DEV_SUSPEND; - /* fall-through */ - case CS_EVENT_RESET_PHYSICAL: - DEBUGP(5, dev, "CS_EVENT_RESET_PHYSICAL\n"); - if (link->state & DEV_CONFIG) { - DEBUGP(5, dev, "ReleaseConfiguration\n"); - pcmcia_release_configuration(link->handle); - } - stop_monitor(dev); - break; - case CS_EVENT_PM_RESUME: - DEBUGP(5, dev, "CS_EVENT_PM_RESUME " - "(fall-through to CS_EVENT_CARD_RESET)\n"); - link->state &= ~DEV_SUSPEND; - /* fall-through */ - case CS_EVENT_CARD_RESET: - DEBUGP(5, dev, "CS_EVENT_CARD_RESET\n"); - if ((link->state & DEV_CONFIG)) { - DEBUGP(5, dev, "RequestConfiguration\n"); - pcmcia_request_configuration(link->handle, &link->conf); - } - if (link->open) - start_monitor(dev); - break; default: DEBUGP(5, dev, "unknown event %.2x\n", event); break; @@ -1928,6 +1901,38 @@ static int cm4000_event(event_t event, int priority, return CS_SUCCESS; } +static int cm4000_suspend(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct cm4000_dev *dev; + + dev = link->priv; + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_release_configuration(link->handle); + stop_monitor(dev); + + return 0; +} + +static int cm4000_resume(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct cm4000_dev *dev; + + dev = link->priv; + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_request_configuration(link->handle, &link->conf); + + if (link->open) + start_monitor(dev); + + return 0; +} + static void cm4000_release(dev_link_t *link) { cmm_cm4000_release(link->priv); /* delay release until device closed */ @@ -2044,6 +2049,8 @@ static struct pcmcia_driver cm4000_driver = { }, .attach = cm4000_attach, .detach = cm4000_detach, + .suspend = cm4000_suspend, + .resume = cm4000_resume, .event = cm4000_event, .id_table = cm4000_ids, }; diff --git a/drivers/char/pcmcia/cm4040_cs.c b/drivers/char/pcmcia/cm4040_cs.c index 4c698d908ffa..3622fd39c47b 100644 --- a/drivers/char/pcmcia/cm4040_cs.c +++ b/drivers/char/pcmcia/cm4040_cs.c @@ -656,31 +656,7 @@ static int reader_event(event_t event, int priority, DEBUGP(5, dev, "CS_EVENT_CARD_REMOVAL\n"); link->state &= ~DEV_PRESENT; break; - case CS_EVENT_PM_SUSPEND: - DEBUGP(5, dev, "CS_EVENT_PM_SUSPEND " - "(fall-through to CS_EVENT_RESET_PHYSICAL)\n"); - link->state |= DEV_SUSPEND; - case CS_EVENT_RESET_PHYSICAL: - DEBUGP(5, dev, "CS_EVENT_RESET_PHYSICAL\n"); - if (link->state & DEV_CONFIG) { - DEBUGP(5, dev, "ReleaseConfiguration\n"); - pcmcia_release_configuration(link->handle); - } - break; - case CS_EVENT_PM_RESUME: - DEBUGP(5, dev, "CS_EVENT_PM_RESUME " - "(fall-through to CS_EVENT_CARD_RESET)\n"); - link->state &= ~DEV_SUSPEND; - - case CS_EVENT_CARD_RESET: - DEBUGP(5, dev, "CS_EVENT_CARD_RESET\n"); - if ((link->state & DEV_CONFIG)) { - DEBUGP(5, dev, "RequestConfiguration\n"); - pcmcia_request_configuration(link->handle, - &link->conf); - } - break; default: DEBUGP(5, dev, "reader_event: unknown event %.2x\n", event); @@ -690,6 +666,28 @@ static int reader_event(event_t event, int priority, return CS_SUCCESS; } +static int reader_suspend(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_release_configuration(link->handle); + + return 0; +} + +static int reader_resume(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_request_configuration(link->handle, &link->conf); + + return 0; +} + static void reader_release(dev_link_t *link) { cm4040_reader_release(link->priv); @@ -806,6 +804,8 @@ static struct pcmcia_driver reader_driver = { }, .attach = reader_attach, .detach = reader_detach, + .suspend = reader_suspend, + .resume = reader_resume, .event = reader_event, .id_table = cm4040_ids, }; diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c index 2c326ea53421..776103e56042 100644 --- a/drivers/char/pcmcia/synclink_cs.c +++ b/drivers/char/pcmcia/synclink_cs.c @@ -773,11 +773,37 @@ static void mgslpc_detach(dev_link_t *link) mgslpc_remove_device((MGSLPC_INFO *)link->priv); } +static int mgslpc_suspend(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + MGSLPC_INFO *info = link->priv; + + link->state |= DEV_SUSPEND; + info->stop = 1; + if (link->state & DEV_CONFIG) + pcmcia_release_configuration(link->handle); + + return 0; +} + +static int mgslpc_resume(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + MGSLPC_INFO *info = link->priv; + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_request_configuration(link->handle, &link->conf); + info->stop = 0; + + return 0; +} + + static int mgslpc_event(event_t event, int priority, event_callback_args_t *args) { dev_link_t *link = args->client_data; - MGSLPC_INFO *info = link->priv; if (debug_level >= DEBUG_LEVEL_INFO) printk("mgslpc_event(0x%06x)\n", event); @@ -794,23 +820,6 @@ static int mgslpc_event(event_t event, int priority, link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; mgslpc_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - /* Mark the device as stopped, to block IO until later */ - info->stop = 1; - if (link->state & DEV_CONFIG) - pcmcia_release_configuration(link->handle); - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (link->state & DEV_CONFIG) - pcmcia_request_configuration(link->handle, &link->conf); - info->stop = 0; - break; } return 0; } @@ -3095,6 +3104,8 @@ static struct pcmcia_driver mgslpc_driver = { .event = mgslpc_event, .detach = mgslpc_detach, .id_table = mgslpc_ids, + .suspend = mgslpc_suspend, + .resume = mgslpc_resume, }; static struct tty_operations mgslpc_ops = { diff --git a/drivers/ide/legacy/ide-cs.c b/drivers/ide/legacy/ide-cs.c index ef79805218e4..982b74af8c29 100644 --- a/drivers/ide/legacy/ide-cs.c +++ b/drivers/ide/legacy/ide-cs.c @@ -406,6 +406,28 @@ void ide_release(dev_link_t *link) } /* ide_release */ +static int ide_suspend(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_release_configuration(link->handle); + + return 0; +} + +static int ide_resume(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + + link->state &= ~DEV_SUSPEND; + if (DEV_OK(link)) + pcmcia_request_configuration(link->handle, &link->conf); + + return 0; +} + /*====================================================================== The card status event handler. Mostly, this schedules other @@ -432,20 +454,6 @@ int ide_event(event_t event, int priority, link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; ide_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - if (link->state & DEV_CONFIG) - pcmcia_release_configuration(link->handle); - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (DEV_OK(link)) - pcmcia_request_configuration(link->handle, &link->conf); - break; } return 0; } /* ide_event */ @@ -498,6 +506,8 @@ static struct pcmcia_driver ide_cs_driver = { .event = ide_event, .detach = ide_detach, .id_table = ide_ids, + .suspend = ide_suspend, + .resume = ide_resume, }; static int __init init_ide_cs(void) diff --git a/drivers/isdn/hardware/avm/avm_cs.c b/drivers/isdn/hardware/avm/avm_cs.c index 27391c32f3eb..6d9816e10ecb 100644 --- a/drivers/isdn/hardware/avm/avm_cs.c +++ b/drivers/isdn/hardware/avm/avm_cs.c @@ -430,6 +430,28 @@ static void avmcs_release(dev_link_t *link) } /* avmcs_release */ +static int avmcs_suspend(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_release_configuration(link->handle); + + return 0; +} + +static int avmcs_resume(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_request_configuration(link->handle, &link->conf); + + return 0; +} + /*====================================================================== The card status event handler. Mostly, this schedules other @@ -459,20 +481,6 @@ static int avmcs_event(event_t event, int priority, link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; avmcs_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - if (link->state & DEV_CONFIG) - pcmcia_release_configuration(link->handle); - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (link->state & DEV_CONFIG) - pcmcia_request_configuration(link->handle, &link->conf); - break; } return 0; } /* avmcs_event */ @@ -494,6 +502,8 @@ static struct pcmcia_driver avmcs_driver = { .event = avmcs_event, .detach = avmcs_detach, .id_table = avmcs_ids, + .suspend= avmcs_suspend, + .resume = avmcs_resume, }; static int __init avmcs_init(void) diff --git a/drivers/isdn/hisax/avma1_cs.c b/drivers/isdn/hisax/avma1_cs.c index 5f5a5ae740d2..433cec4269a3 100644 --- a/drivers/isdn/hisax/avma1_cs.c +++ b/drivers/isdn/hisax/avma1_cs.c @@ -445,6 +445,28 @@ static void avma1cs_release(dev_link_t *link) avma1cs_detach(link); } /* avma1cs_release */ +static int avma1cs_suspend(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_release_configuration(link->handle); + + return 0; +} + +static int avma1cs_resume(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_request_configuration(link->handle, &link->conf); + + return 0; +} + /*====================================================================== The card status event handler. Mostly, this schedules other @@ -475,20 +497,6 @@ static int avma1cs_event(event_t event, int priority, link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; avma1cs_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - if (link->state & DEV_CONFIG) - pcmcia_release_configuration(link->handle); - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (link->state & DEV_CONFIG) - pcmcia_request_configuration(link->handle, &link->conf); - break; } return 0; } /* avma1cs_event */ @@ -509,6 +517,8 @@ static struct pcmcia_driver avma1cs_driver = { .event = avma1cs_event, .detach = avma1cs_detach, .id_table = avma1cs_ids, + .suspend = avma1cs_suspend, + .resume = avma1cs_resume, }; /*====================================================================*/ diff --git a/drivers/isdn/hisax/elsa_cs.c b/drivers/isdn/hisax/elsa_cs.c index 6fc6868de0b0..0cbe04593d87 100644 --- a/drivers/isdn/hisax/elsa_cs.c +++ b/drivers/isdn/hisax/elsa_cs.c @@ -447,6 +447,32 @@ static void elsa_cs_release(dev_link_t *link) link->state &= ~DEV_CONFIG; } /* elsa_cs_release */ +static int elsa_suspend(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + local_info_t *dev = link->priv; + + link->state |= DEV_SUSPEND; + dev->busy = 1; + if (link->state & DEV_CONFIG) + pcmcia_release_configuration(link->handle); + + return 0; +} + +static int elsa_resume(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + local_info_t *dev = link->priv; + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_request_configuration(link->handle, &link->conf); + dev->busy = 0; + + return 0; +} + /*====================================================================== The card status event handler. Mostly, this schedules other @@ -465,7 +491,6 @@ static int elsa_cs_event(event_t event, int priority, event_callback_args_t *args) { dev_link_t *link = args->client_data; - local_info_t *dev = link->priv; DEBUG(1, "elsa_cs_event(%d)\n", event); @@ -481,23 +506,6 @@ static int elsa_cs_event(event_t event, int priority, link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; elsa_cs_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - /* Mark the device as stopped, to block IO until later */ - dev->busy = 1; - if (link->state & DEV_CONFIG) - pcmcia_release_configuration(link->handle); - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (link->state & DEV_CONFIG) - pcmcia_request_configuration(link->handle, &link->conf); - dev->busy = 0; - break; } return 0; } /* elsa_cs_event */ @@ -518,6 +526,8 @@ static struct pcmcia_driver elsa_cs_driver = { .event = elsa_cs_event, .detach = elsa_cs_detach, .id_table = elsa_ids, + .suspend = elsa_suspend, + .resume = elsa_resume, }; static int __init init_elsa_cs(void) diff --git a/drivers/isdn/hisax/sedlbauer_cs.c b/drivers/isdn/hisax/sedlbauer_cs.c index dc334aab433e..27dce7c7b760 100644 --- a/drivers/isdn/hisax/sedlbauer_cs.c +++ b/drivers/isdn/hisax/sedlbauer_cs.c @@ -553,6 +553,32 @@ static void sedlbauer_release(dev_link_t *link) } /* sedlbauer_release */ +static int sedlbauer_suspend(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + local_info_t *dev = link->priv; + + link->state |= DEV_SUSPEND; + dev->stop = 1; + if (link->state & DEV_CONFIG) + pcmcia_release_configuration(link->handle); + + return 0; +} + +static int sedlbauer_resume(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + local_info_t *dev = link->priv; + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_request_configuration(link->handle, &link->conf); + dev->stop = 0; + + return 0; +} + /*====================================================================== The card status event handler. Mostly, this schedules other @@ -569,7 +595,6 @@ static int sedlbauer_event(event_t event, int priority, event_callback_args_t *args) { dev_link_t *link = args->client_data; - local_info_t *dev = link->priv; DEBUG(1, "sedlbauer_event(0x%06x)\n", event); @@ -585,27 +610,6 @@ static int sedlbauer_event(event_t event, int priority, link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; sedlbauer_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - /* Mark the device as stopped, to block IO until later */ - dev->stop = 1; - if (link->state & DEV_CONFIG) - pcmcia_release_configuration(link->handle); - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (link->state & DEV_CONFIG) - pcmcia_request_configuration(link->handle, &link->conf); - dev->stop = 0; - /* - In a normal driver, additional code may go here to restore - the device state and restart IO. - */ - break; } return 0; } /* sedlbauer_event */ @@ -631,6 +635,8 @@ static struct pcmcia_driver sedlbauer_driver = { .event = sedlbauer_event, .detach = sedlbauer_detach, .id_table = sedlbauer_ids, + .suspend = sedlbauer_suspend, + .resume = sedlbauer_resume, }; static int __init init_sedlbauer_cs(void) diff --git a/drivers/isdn/hisax/teles_cs.c b/drivers/isdn/hisax/teles_cs.c index 0ddef1bf778b..70213bc1d30c 100644 --- a/drivers/isdn/hisax/teles_cs.c +++ b/drivers/isdn/hisax/teles_cs.c @@ -428,6 +428,32 @@ static void teles_cs_release(dev_link_t *link) link->state &= ~DEV_CONFIG; } /* teles_cs_release */ +static int teles_suspend(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + local_info_t *dev = link->priv; + + link->state |= DEV_SUSPEND; + dev->busy = 1; + if (link->state & DEV_CONFIG) + pcmcia_release_configuration(link->handle); + + return 0; +} + +static int teles_resume(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + local_info_t *dev = link->priv; + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_request_configuration(link->handle, &link->conf); + dev->busy = 0; + + return 0; +} + /*====================================================================== The card status event handler. Mostly, this schedules other @@ -446,7 +472,6 @@ static int teles_cs_event(event_t event, int priority, event_callback_args_t *args) { dev_link_t *link = args->client_data; - local_info_t *dev = link->priv; DEBUG(1, "teles_cs_event(%d)\n", event); @@ -462,23 +487,6 @@ static int teles_cs_event(event_t event, int priority, link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; teles_cs_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - /* Mark the device as stopped, to block IO until later */ - dev->busy = 1; - if (link->state & DEV_CONFIG) - pcmcia_release_configuration(link->handle); - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (link->state & DEV_CONFIG) - pcmcia_request_configuration(link->handle, &link->conf); - dev->busy = 0; - break; } return 0; } /* teles_cs_event */ @@ -498,6 +506,8 @@ static struct pcmcia_driver teles_cs_driver = { .event = teles_cs_event, .detach = teles_detach, .id_table = teles_ids, + .suspend = teles_suspend, + .resume = teles_resume, }; static int __init init_teles_cs(void) diff --git a/drivers/mtd/maps/pcmciamtd.c b/drivers/mtd/maps/pcmciamtd.c index af24216a0626..86443cf44dc6 100644 --- a/drivers/mtd/maps/pcmciamtd.c +++ b/drivers/mtd/maps/pcmciamtd.c @@ -691,6 +691,24 @@ static void pcmciamtd_config(dev_link_t *link) } +static int pcmciamtd_suspend(struct pcmcia_device *dev) +{ + DEBUG(2, "EVENT_PM_RESUME"); + + /* get_lock(link); */ + + return 0; +} + +static int pcmciamtd_resume(struct pcmcia_device *dev) +{ + DEBUG(2, "EVENT_PM_SUSPEND"); + + /* free_lock(link); */ + + return 0; +} + /* 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 driver from trying @@ -721,22 +739,6 @@ static int pcmciamtd_event(event_t event, int priority, link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; pcmciamtd_config(link); break; - case CS_EVENT_PM_SUSPEND: - DEBUG(2, "EVENT_PM_SUSPEND"); - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - DEBUG(2, "EVENT_RESET_PHYSICAL"); - /* get_lock(link); */ - break; - case CS_EVENT_PM_RESUME: - DEBUG(2, "EVENT_PM_RESUME"); - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - DEBUG(2, "EVENT_CARD_RESET"); - /* free_lock(link); */ - break; default: DEBUG(2, "Unknown event %d", event); } @@ -848,6 +850,8 @@ static struct pcmcia_driver pcmciamtd_driver = { .detach = pcmciamtd_detach, .owner = THIS_MODULE, .id_table = pcmciamtd_ids, + .suspend = pcmciamtd_suspend, + .resume = pcmciamtd_resume, }; diff --git a/drivers/net/pcmcia/3c574_cs.c b/drivers/net/pcmcia/3c574_cs.c index 71fd41122c91..80414a77fe75 100644 --- a/drivers/net/pcmcia/3c574_cs.c +++ b/drivers/net/pcmcia/3c574_cs.c @@ -547,6 +547,38 @@ static void tc574_release(dev_link_t *link) link->state &= ~DEV_CONFIG; } +static int tc574_suspend(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct net_device *dev = link->priv; + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + if (link->open) + netif_device_detach(dev); + pcmcia_release_configuration(link->handle); + } + + return 0; +} + +static int tc574_resume(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct net_device *dev = link->priv; + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + pcmcia_request_configuration(link->handle, &link->conf); + if (link->open) { + tc574_reset(dev); + netif_device_attach(dev); + } + } + + return 0; +} + /* The card status event handler. Mostly, this schedules other stuff to run after an event is received. A CARD_REMOVAL event @@ -572,28 +604,6 @@ static int tc574_event(event_t event, int priority, link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; tc574_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - if (link->state & DEV_CONFIG) { - if (link->open) - netif_device_detach(dev); - pcmcia_release_configuration(link->handle); - } - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (link->state & DEV_CONFIG) { - pcmcia_request_configuration(link->handle, &link->conf); - if (link->open) { - tc574_reset(dev); - netif_device_attach(dev); - } - } - break; } return 0; } /* tc574_event */ @@ -1296,6 +1306,8 @@ static struct pcmcia_driver tc574_driver = { .event = tc574_event, .detach = tc574_detach, .id_table = tc574_ids, + .suspend = tc574_suspend, + .resume = tc574_resume, }; static int __init init_tc574(void) diff --git a/drivers/net/pcmcia/3c589_cs.c b/drivers/net/pcmcia/3c589_cs.c index d83fdd8c1943..bbda681ac102 100644 --- a/drivers/net/pcmcia/3c589_cs.c +++ b/drivers/net/pcmcia/3c589_cs.c @@ -421,6 +421,38 @@ static void tc589_release(dev_link_t *link) link->state &= ~DEV_CONFIG; } +static int tc589_suspend(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct net_device *dev = link->priv; + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + if (link->open) + netif_device_detach(dev); + pcmcia_release_configuration(link->handle); + } + + return 0; +} + +static int tc589_resume(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct net_device *dev = link->priv; + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + pcmcia_request_configuration(link->handle, &link->conf); + if (link->open) { + tc589_reset(dev); + netif_device_attach(dev); + } + } + + return 0; +} + /*====================================================================== The card status event handler. Mostly, this schedules other @@ -448,28 +480,6 @@ static int tc589_event(event_t event, int priority, link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; tc589_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - if (link->state & DEV_CONFIG) { - if (link->open) - netif_device_detach(dev); - pcmcia_release_configuration(link->handle); - } - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (link->state & DEV_CONFIG) { - pcmcia_request_configuration(link->handle, &link->conf); - if (link->open) { - tc589_reset(dev); - netif_device_attach(dev); - } - } - break; } return 0; } /* tc589_event */ @@ -1071,6 +1081,8 @@ static struct pcmcia_driver tc589_driver = { .event = tc589_event, .detach = tc589_detach, .id_table = tc589_ids, + .suspend = tc589_suspend, + .resume = tc589_resume, }; static int __init init_tc589(void) diff --git a/drivers/net/pcmcia/axnet_cs.c b/drivers/net/pcmcia/axnet_cs.c index 8bb4e85689ea..6c6b25265659 100644 --- a/drivers/net/pcmcia/axnet_cs.c +++ b/drivers/net/pcmcia/axnet_cs.c @@ -490,6 +490,40 @@ static void axnet_release(dev_link_t *link) link->state &= ~DEV_CONFIG; } +static int axnet_suspend(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct net_device *dev = link->priv; + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + if (link->open) + netif_device_detach(dev); + pcmcia_release_configuration(link->handle); + } + + return 0; +} + +static int axnet_resume(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct net_device *dev = link->priv; + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + pcmcia_request_configuration(link->handle, &link->conf); + if (link->open) { + axnet_reset_8390(dev); + AX88190_init(dev, 1); + netif_device_attach(dev); + } + } + + return 0; +} + + /*====================================================================== The card status event handler. Mostly, this schedules other @@ -517,29 +551,6 @@ static int axnet_event(event_t event, int priority, link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; axnet_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - if (link->state & DEV_CONFIG) { - if (link->open) - netif_device_detach(dev); - pcmcia_release_configuration(link->handle); - } - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (link->state & DEV_CONFIG) { - pcmcia_request_configuration(link->handle, &link->conf); - if (link->open) { - axnet_reset_8390(dev); - AX88190_init(dev, 1); - netif_device_attach(dev); - } - } - break; } return 0; } /* axnet_event */ @@ -881,6 +892,8 @@ static struct pcmcia_driver axnet_cs_driver = { .event = axnet_event, .detach = axnet_detach, .id_table = axnet_ids, + .suspend = axnet_suspend, + .resume = axnet_resume, }; static int __init init_axnet_cs(void) diff --git a/drivers/net/pcmcia/com20020_cs.c b/drivers/net/pcmcia/com20020_cs.c index b9355d9498a3..68612222de6e 100644 --- a/drivers/net/pcmcia/com20020_cs.c +++ b/drivers/net/pcmcia/com20020_cs.c @@ -421,6 +421,42 @@ static void com20020_release(dev_link_t *link) link->state &= ~(DEV_CONFIG | DEV_RELEASE_PENDING); } +static int com20020_suspend(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + com20020_dev_t *info = link->priv; + struct net_device *dev = info->dev; + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + if (link->open) { + netif_device_detach(dev); + } + pcmcia_release_configuration(link->handle); + } + + return 0; +} + +static int com20020_resume(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + com20020_dev_t *info = link->priv; + struct net_device *dev = info->dev; + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + pcmcia_request_configuration(link->handle, &link->conf); + if (link->open) { + int ioaddr = dev->base_addr; + struct arcnet_local *lp = dev->priv; + ARCRESET; + } + } + + return 0; +} + /*====================================================================== The card status event handler. Mostly, this schedules other @@ -449,30 +485,6 @@ static int com20020_event(event_t event, int priority, link->state |= DEV_PRESENT; com20020_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - if (link->state & DEV_CONFIG) { - if (link->open) { - netif_device_detach(dev); - } - pcmcia_release_configuration(link->handle); - } - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (link->state & DEV_CONFIG) { - pcmcia_request_configuration(link->handle, &link->conf); - if (link->open) { - int ioaddr = dev->base_addr; - struct arcnet_local *lp = dev->priv; - ARCRESET; - } - } - break; } return 0; } /* com20020_event */ @@ -492,6 +504,8 @@ static struct pcmcia_driver com20020_cs_driver = { .event = com20020_event, .detach = com20020_detach, .id_table = com20020_ids, + .suspend = com20020_suspend, + .resume = com20020_resume, }; static int __init init_com20020_cs(void) diff --git a/drivers/net/pcmcia/fmvj18x_cs.c b/drivers/net/pcmcia/fmvj18x_cs.c index 356f50909222..388ecade13de 100644 --- a/drivers/net/pcmcia/fmvj18x_cs.c +++ b/drivers/net/pcmcia/fmvj18x_cs.c @@ -713,6 +713,39 @@ static void fmvj18x_release(dev_link_t *link) link->state &= ~DEV_CONFIG; } +static int fmvj18x_suspend(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct net_device *dev = link->priv; + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + if (link->open) + netif_device_detach(dev); + pcmcia_release_configuration(link->handle); + } + + + return 0; +} + +static int fmvj18x_resume(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct net_device *dev = link->priv; + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + pcmcia_request_configuration(link->handle, &link->conf); + if (link->open) { + fjn_reset(dev); + netif_device_attach(dev); + } + } + + return 0; +} + /*====================================================================*/ static int fmvj18x_event(event_t event, int priority, @@ -733,28 +766,6 @@ static int fmvj18x_event(event_t event, int priority, link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; fmvj18x_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - if (link->state & DEV_CONFIG) { - if (link->open) - netif_device_detach(dev); - pcmcia_release_configuration(link->handle); - } - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (link->state & DEV_CONFIG) { - pcmcia_request_configuration(link->handle, &link->conf); - if (link->open) { - fjn_reset(dev); - netif_device_attach(dev); - } - } - break; } return 0; } /* fmvj18x_event */ @@ -793,6 +804,8 @@ static struct pcmcia_driver fmvj18x_cs_driver = { .event = fmvj18x_event, .detach = fmvj18x_detach, .id_table = fmvj18x_ids, + .suspend = fmvj18x_suspend, + .resume = fmvj18x_resume, }; static int __init init_fmvj18x_cs(void) diff --git a/drivers/net/pcmcia/ibmtr_cs.c b/drivers/net/pcmcia/ibmtr_cs.c index b6c140eb9799..3a7218e51b73 100644 --- a/drivers/net/pcmcia/ibmtr_cs.c +++ b/drivers/net/pcmcia/ibmtr_cs.c @@ -401,6 +401,41 @@ static void ibmtr_release(dev_link_t *link) link->state &= ~DEV_CONFIG; } +static int ibmtr_suspend(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + ibmtr_dev_t *info = link->priv; + struct net_device *dev = info->dev; + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + if (link->open) + netif_device_detach(dev); + pcmcia_release_configuration(link->handle); + } + + return 0; +} + +static int ibmtr_resume(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + ibmtr_dev_t *info = link->priv; + struct net_device *dev = info->dev; + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + pcmcia_request_configuration(link->handle, &link->conf); + if (link->open) { + ibmtr_probe(dev); /* really? */ + netif_device_attach(dev); + } + } + + return 0; +} + + /*====================================================================== The card status event handler. Mostly, this schedules other @@ -433,28 +468,6 @@ static int ibmtr_event(event_t event, int priority, link->state |= DEV_PRESENT; ibmtr_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - if (link->state & DEV_CONFIG) { - if (link->open) - netif_device_detach(dev); - pcmcia_release_configuration(link->handle); - } - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (link->state & DEV_CONFIG) { - pcmcia_request_configuration(link->handle, &link->conf); - if (link->open) { - ibmtr_probe(dev); /* really? */ - netif_device_attach(dev); - } - } - break; } return 0; } /* ibmtr_event */ @@ -518,6 +531,8 @@ static struct pcmcia_driver ibmtr_cs_driver = { .event = ibmtr_event, .detach = ibmtr_detach, .id_table = ibmtr_ids, + .suspend = ibmtr_suspend, + .resume = ibmtr_resume, }; static int __init init_ibmtr_cs(void) diff --git a/drivers/net/pcmcia/nmclan_cs.c b/drivers/net/pcmcia/nmclan_cs.c index 980d7e5d66cb..fa4921f8b9fc 100644 --- a/drivers/net/pcmcia/nmclan_cs.c +++ b/drivers/net/pcmcia/nmclan_cs.c @@ -801,6 +801,39 @@ static void nmclan_release(dev_link_t *link) link->state &= ~DEV_CONFIG; } +static int nmclan_suspend(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct net_device *dev = link->priv; + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + if (link->open) + netif_device_detach(dev); + pcmcia_release_configuration(link->handle); + } + + + return 0; +} + +static int nmclan_resume(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct net_device *dev = link->priv; + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + pcmcia_request_configuration(link->handle, &link->conf); + if (link->open) { + nmclan_reset(dev); + netif_device_attach(dev); + } + } + + return 0; +} + /* ---------------------------------------------------------------------------- nmclan_event The card status event handler. Mostly, this schedules other @@ -826,28 +859,6 @@ static int nmclan_event(event_t event, int priority, link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; nmclan_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - if (link->state & DEV_CONFIG) { - if (link->open) - netif_device_detach(dev); - pcmcia_release_configuration(link->handle); - } - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (link->state & DEV_CONFIG) { - pcmcia_request_configuration(link->handle, &link->conf); - if (link->open) { - nmclan_reset(dev); - netif_device_attach(dev); - } - } - break; case CS_EVENT_RESET_REQUEST: return 1; break; @@ -1685,6 +1696,8 @@ static struct pcmcia_driver nmclan_cs_driver = { .event = nmclan_event, .detach = nmclan_detach, .id_table = nmclan_ids, + .suspend = nmclan_suspend, + .resume = nmclan_resume, }; static int __init init_nmclan_cs(void) diff --git a/drivers/net/pcmcia/pcnet_cs.c b/drivers/net/pcmcia/pcnet_cs.c index 818c185d6438..7db4d6f3db45 100644 --- a/drivers/net/pcmcia/pcnet_cs.c +++ b/drivers/net/pcmcia/pcnet_cs.c @@ -780,6 +780,39 @@ static void pcnet_release(dev_link_t *link) ======================================================================*/ +static int pcnet_suspend(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct net_device *dev = link->priv; + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + if (link->open) + netif_device_detach(dev); + pcmcia_release_configuration(link->handle); + } + + return 0; +} + +static int pcnet_resume(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct net_device *dev = link->priv; + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + pcmcia_request_configuration(link->handle, &link->conf); + if (link->open) { + pcnet_reset_8390(dev); + NS8390_init(dev, 1); + netif_device_attach(dev); + } + } + + return 0; +} + static int pcnet_event(event_t event, int priority, event_callback_args_t *args) { @@ -798,29 +831,6 @@ static int pcnet_event(event_t event, int priority, link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; pcnet_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - if (link->state & DEV_CONFIG) { - if (link->open) - netif_device_detach(dev); - pcmcia_release_configuration(link->handle); - } - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (link->state & DEV_CONFIG) { - pcmcia_request_configuration(link->handle, &link->conf); - if (link->open) { - pcnet_reset_8390(dev); - NS8390_init(dev, 1); - netif_device_attach(dev); - } - } - break; } return 0; } /* pcnet_event */ @@ -1849,6 +1859,8 @@ static struct pcmcia_driver pcnet_driver = { .detach = pcnet_detach, .owner = THIS_MODULE, .id_table = pcnet_ids, + .suspend = pcnet_suspend, + .resume = pcnet_resume, }; static int __init init_pcnet_cs(void) diff --git a/drivers/net/pcmcia/smc91c92_cs.c b/drivers/net/pcmcia/smc91c92_cs.c index c7cca842e5ee..7c61ec90c2c3 100644 --- a/drivers/net/pcmcia/smc91c92_cs.c +++ b/drivers/net/pcmcia/smc91c92_cs.c @@ -895,6 +895,62 @@ free_cfg_mem: return rc; } +static int smc91c92_suspend(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct net_device *dev = link->priv; + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + if (link->open) + netif_device_detach(dev); + pcmcia_release_configuration(link->handle); + } + + return 0; +} + +static int smc91c92_resume(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct net_device *dev = link->priv; + struct smc_private *smc = netdev_priv(dev); + int i; + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + if ((smc->manfid == MANFID_MEGAHERTZ) && + (smc->cardid == PRODID_MEGAHERTZ_EM3288)) + mhz_3288_power(link); + pcmcia_request_configuration(link->handle, &link->conf); + if (smc->manfid == MANFID_MOTOROLA) + mot_config(link); + if ((smc->manfid == MANFID_OSITECH) && + (smc->cardid != PRODID_OSITECH_SEVEN)) { + /* Power up the card and enable interrupts */ + set_bits(0x0300, dev->base_addr-0x10+OSITECH_AUI_PWR); + set_bits(0x0300, dev->base_addr-0x10+OSITECH_RESET_ISR); + } + if (((smc->manfid == MANFID_OSITECH) && + (smc->cardid == PRODID_OSITECH_SEVEN)) || + ((smc->manfid == MANFID_PSION) && + (smc->cardid == PRODID_PSION_NET100))) { + /* Download the Seven of Diamonds firmware */ + for (i = 0; i < sizeof(__Xilinx7OD); i++) { + outb(__Xilinx7OD[i], link->io.BasePort1+2); + udelay(50); + } + } + if (link->open) { + smc_reset(dev); + netif_device_attach(dev); + } + } + + return 0; +} + + /*====================================================================== This verifies that the chip is some SMC91cXX variant, and returns @@ -935,14 +991,12 @@ static int check_sig(dev_link_t *link) } if (width) { - event_callback_args_t args; printk(KERN_INFO "smc91c92_cs: using 8-bit IO window.\n"); - args.client_data = link; - smc91c92_event(CS_EVENT_RESET_PHYSICAL, 0, &args); + smc91c92_suspend(link->handle); pcmcia_release_io(link->handle, &link->io); link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; pcmcia_request_io(link->handle, &link->io); - smc91c92_event(CS_EVENT_CARD_RESET, 0, &args); + smc91c92_resume(link->handle); return check_sig(link); } return -ENODEV; @@ -1184,8 +1238,6 @@ static int smc91c92_event(event_t event, int priority, { dev_link_t *link = args->client_data; struct net_device *dev = link->priv; - struct smc_private *smc = netdev_priv(dev); - int i; DEBUG(1, "smc91c92_event(0x%06x)\n", event); @@ -1199,49 +1251,6 @@ static int smc91c92_event(event_t event, int priority, link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; smc91c92_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - if (link->state & DEV_CONFIG) { - if (link->open) - netif_device_detach(dev); - pcmcia_release_configuration(link->handle); - } - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (link->state & DEV_CONFIG) { - if ((smc->manfid == MANFID_MEGAHERTZ) && - (smc->cardid == PRODID_MEGAHERTZ_EM3288)) - mhz_3288_power(link); - pcmcia_request_configuration(link->handle, &link->conf); - if (smc->manfid == MANFID_MOTOROLA) - mot_config(link); - if ((smc->manfid == MANFID_OSITECH) && - (smc->cardid != PRODID_OSITECH_SEVEN)) { - /* Power up the card and enable interrupts */ - set_bits(0x0300, dev->base_addr-0x10+OSITECH_AUI_PWR); - set_bits(0x0300, dev->base_addr-0x10+OSITECH_RESET_ISR); - } - if (((smc->manfid == MANFID_OSITECH) && - (smc->cardid == PRODID_OSITECH_SEVEN)) || - ((smc->manfid == MANFID_PSION) && - (smc->cardid == PRODID_PSION_NET100))) { - /* Download the Seven of Diamonds firmware */ - for (i = 0; i < sizeof(__Xilinx7OD); i++) { - outb(__Xilinx7OD[i], link->io.BasePort1+2); - udelay(50); - } - } - if (link->open) { - smc_reset(dev); - netif_device_attach(dev); - } - } - break; } return 0; } /* smc91c92_event */ @@ -2364,6 +2373,8 @@ static struct pcmcia_driver smc91c92_cs_driver = { .event = smc91c92_event, .detach = smc91c92_detach, .id_table = smc91c92_ids, + .suspend = smc91c92_suspend, + .resume = smc91c92_resume, }; static int __init init_smc91c92_cs(void) diff --git a/drivers/net/pcmcia/xirc2ps_cs.c b/drivers/net/pcmcia/xirc2ps_cs.c index ce143f08638a..917e50ac37f3 100644 --- a/drivers/net/pcmcia/xirc2ps_cs.c +++ b/drivers/net/pcmcia/xirc2ps_cs.c @@ -1157,6 +1157,41 @@ xirc2ps_release(dev_link_t *link) /*====================================================================*/ + +static int xirc2ps_suspend(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct net_device *dev = link->priv; + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + if (link->open) { + netif_device_detach(dev); + do_powerdown(dev); + } + pcmcia_release_configuration(link->handle); + } + + return 0; +} + +static int xirc2ps_resume(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct net_device *dev = link->priv; + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + pcmcia_request_configuration(link->handle, &link->conf); + if (link->open) { + do_reset(dev,1); + netif_device_attach(dev); + } + } + + return 0; +} + /**************** * The card status event handler. Mostly, this schedules other * stuff to run after an event is received. A CARD_REMOVAL event @@ -1191,30 +1226,6 @@ xirc2ps_event(event_t event, int priority, link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; xirc2ps_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - if (link->state & DEV_CONFIG) { - if (link->open) { - netif_device_detach(dev); - do_powerdown(dev); - } - pcmcia_release_configuration(link->handle); - } - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (link->state & DEV_CONFIG) { - pcmcia_request_configuration(link->handle, &link->conf); - if (link->open) { - do_reset(dev,1); - netif_device_attach(dev); - } - } - break; } return 0; } /* xirc2ps_event */ @@ -2013,6 +2024,8 @@ static struct pcmcia_driver xirc2ps_cs_driver = { .event = xirc2ps_event, .detach = xirc2ps_detach, .id_table = xirc2ps_ids, + .suspend = xirc2ps_suspend, + .resume = xirc2ps_resume, }; static int __init diff --git a/drivers/net/wireless/airo_cs.c b/drivers/net/wireless/airo_cs.c index e328547599dc..80c9de749b52 100644 --- a/drivers/net/wireless/airo_cs.c +++ b/drivers/net/wireless/airo_cs.c @@ -492,6 +492,35 @@ static void airo_release(dev_link_t *link) link->state &= ~DEV_CONFIG; } +static int airo_suspend(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + local_info_t *local = link->priv; + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + netif_device_detach(local->eth_dev); + pcmcia_release_configuration(link->handle); + } + + return 0; +} + +static int airo_resume(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + local_info_t *local = link->priv; + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + pcmcia_request_configuration(link->handle, &link->conf); + reset_airo_card(local->eth_dev); + netif_device_attach(local->eth_dev); + } + + return 0; +} + /*====================================================================== The card status event handler. Mostly, this schedules other @@ -524,25 +553,6 @@ static int airo_event(event_t event, int priority, link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; airo_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - if (link->state & DEV_CONFIG) { - netif_device_detach(local->eth_dev); - pcmcia_release_configuration(link->handle); - } - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (link->state & DEV_CONFIG) { - pcmcia_request_configuration(link->handle, &link->conf); - reset_airo_card(local->eth_dev); - netif_device_attach(local->eth_dev); - } - break; } return 0; } /* airo_event */ @@ -565,6 +575,8 @@ static struct pcmcia_driver airo_driver = { .event = airo_event, .detach = airo_detach, .id_table = airo_ids, + .suspend = airo_suspend, + .resume = airo_resume, }; static int airo_cs_init(void) diff --git a/drivers/net/wireless/atmel_cs.c b/drivers/net/wireless/atmel_cs.c index 17d1fd90f832..598a9cd0f83e 100644 --- a/drivers/net/wireless/atmel_cs.c +++ b/drivers/net/wireless/atmel_cs.c @@ -477,6 +477,35 @@ static void atmel_release(dev_link_t *link) link->state &= ~DEV_CONFIG; } +static int atmel_suspend(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + local_info_t *local = link->priv; + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + netif_device_detach(local->eth_dev); + pcmcia_release_configuration(link->handle); + } + + return 0; +} + +static int atmel_resume(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + local_info_t *local = link->priv; + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + pcmcia_request_configuration(link->handle, &link->conf); + atmel_open(local->eth_dev); + netif_device_attach(local->eth_dev); + } + + return 0; +} + /*====================================================================== The card status event handler. Mostly, this schedules other @@ -509,25 +538,6 @@ static int atmel_event(event_t event, int priority, link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; atmel_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - if (link->state & DEV_CONFIG) { - netif_device_detach(local->eth_dev); - pcmcia_release_configuration(link->handle); - } - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (link->state & DEV_CONFIG) { - pcmcia_request_configuration(link->handle, &link->conf); - atmel_open(local->eth_dev); - netif_device_attach(local->eth_dev); - } - break; } return 0; } /* atmel_event */ @@ -585,6 +595,8 @@ static struct pcmcia_driver atmel_driver = { .event = atmel_event, .detach = atmel_detach, .id_table = atmel_ids, + .suspend = atmel_suspend, + .resume = atmel_resume, }; static int atmel_cs_init(void) diff --git a/drivers/net/wireless/hostap/hostap_cs.c b/drivers/net/wireless/hostap/hostap_cs.c index 2643976a6677..ba4a7da98ccd 100644 --- a/drivers/net/wireless/hostap/hostap_cs.c +++ b/drivers/net/wireless/hostap/hostap_cs.c @@ -846,19 +846,63 @@ static void prism2_release(u_long arg) PDEBUG(DEBUG_FLOW, "release - done\n"); } +static int hostap_cs_suspend(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct net_device *dev = (struct net_device *) link->priv; + int dev_open = 0; + + PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_SUSPEND\n", dev_info); + + link->state |= DEV_SUSPEND; + + if (link->state & DEV_CONFIG) { + struct hostap_interface *iface = netdev_priv(dev); + if (iface && iface->local) + dev_open = iface->local->num_dev_open > 0; + if (dev_open) { + netif_stop_queue(dev); + netif_device_detach(dev); + } + prism2_suspend(dev); + pcmcia_release_configuration(link->handle); + } + + return 0; +} + +static int hostap_cs_resume(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct net_device *dev = (struct net_device *) link->priv; + int dev_open = 0; + + PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_RESUME\n", dev_info); + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + struct hostap_interface *iface = netdev_priv(dev); + if (iface && iface->local) + dev_open = iface->local->num_dev_open > 0; + + pcmcia_request_configuration(link->handle, &link->conf); + + prism2_hw_shutdown(dev, 1); + prism2_hw_config(dev, dev_open ? 0 : 1); + if (dev_open) { + netif_device_attach(dev); + netif_start_queue(dev); + } + } + + return 0; +} static int prism2_event(event_t event, int priority, event_callback_args_t *args) { dev_link_t *link = args->client_data; struct net_device *dev = (struct net_device *) link->priv; - int dev_open = 0; - - if (link->state & DEV_CONFIG) { - struct hostap_interface *iface = netdev_priv(dev); - if (iface && iface->local) - dev_open = iface->local->num_dev_open > 0; - } switch (event) { case CS_EVENT_CARD_INSERTION: @@ -879,42 +923,6 @@ static int prism2_event(event_t event, int priority, } break; - case CS_EVENT_PM_SUSPEND: - PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_SUSPEND\n", dev_info); - link->state |= DEV_SUSPEND; - /* fall through */ - - case CS_EVENT_RESET_PHYSICAL: - PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_RESET_PHYSICAL\n", dev_info); - if (link->state & DEV_CONFIG) { - if (dev_open) { - netif_stop_queue(dev); - netif_device_detach(dev); - } - prism2_suspend(dev); - pcmcia_release_configuration(link->handle); - } - break; - - case CS_EVENT_PM_RESUME: - PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_RESUME\n", dev_info); - link->state &= ~DEV_SUSPEND; - /* fall through */ - - case CS_EVENT_CARD_RESET: - PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_CARD_RESET\n", dev_info); - if (link->state & DEV_CONFIG) { - pcmcia_request_configuration(link->handle, - &link->conf); - prism2_hw_shutdown(dev, 1); - prism2_hw_config(dev, dev_open ? 0 : 1); - if (dev_open) { - netif_device_attach(dev); - netif_start_queue(dev); - } - } - break; - default: PDEBUG(DEBUG_EXTRA, "%s: prism2_event() - unknown event %d\n", dev_info, event); @@ -987,6 +995,8 @@ static struct pcmcia_driver hostap_driver = { .owner = THIS_MODULE, .event = prism2_event, .id_table = hostap_cs_ids, + .suspend = hostap_cs_suspend, + .resume = hostap_cs_resume, }; static int __init init_prism2_pccard(void) diff --git a/drivers/net/wireless/netwave_cs.c b/drivers/net/wireless/netwave_cs.c index 92793b958e32..7ab2d70ffddf 100644 --- a/drivers/net/wireless/netwave_cs.c +++ b/drivers/net/wireless/netwave_cs.c @@ -935,6 +935,39 @@ static void netwave_release(dev_link_t *link) link->state &= ~DEV_CONFIG; } +static int netwave_suspend(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct net_device *dev = link->priv; + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + if (link->open) + netif_device_detach(dev); + pcmcia_release_configuration(link->handle); + } + + return 0; +} + +static int netwave_resume(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct net_device *dev = link->priv; + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + pcmcia_request_configuration(link->handle, &link->conf); + if (link->open) { + netwave_reset(dev); + netif_device_attach(dev); + } + } + + return 0; +} + + /* * Function netwave_event (event, priority, args) * @@ -973,28 +1006,6 @@ static int netwave_event(event_t event, int priority, link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; netwave_pcmcia_config( link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - if (link->state & DEV_CONFIG) { - if (link->open) - netif_device_detach(dev); - pcmcia_release_configuration(link->handle); - } - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (link->state & DEV_CONFIG) { - pcmcia_request_configuration(link->handle, &link->conf); - if (link->open) { - netwave_reset(dev); - netif_device_attach(dev); - } - } - break; } return 0; } /* netwave_event */ @@ -1495,6 +1506,8 @@ static struct pcmcia_driver netwave_driver = { .event = netwave_event, .detach = netwave_detach, .id_table = netwave_ids, + .suspend = netwave_suspend, + .resume = netwave_resume, }; static int __init init_netwave_cs(void) diff --git a/drivers/net/wireless/orinoco_cs.c b/drivers/net/wireless/orinoco_cs.c index dc1128a00971..1d66050e3d6a 100644 --- a/drivers/net/wireless/orinoco_cs.c +++ b/drivers/net/wireless/orinoco_cs.c @@ -465,6 +465,83 @@ orinoco_cs_release(dev_link_t *link) ioport_unmap(priv->hw.iobase); } /* orinoco_cs_release */ +static int orinoco_cs_suspend(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct net_device *dev = link->priv; + struct orinoco_private *priv = netdev_priv(dev); + struct orinoco_pccard *card = priv->card; + int err = 0; + unsigned long flags; + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + /* This is probably racy, but I can't think of + a better way, short of rewriting the PCMCIA + layer to not suck :-( */ + if (! test_bit(0, &card->hard_reset_in_progress)) { + spin_lock_irqsave(&priv->lock, flags); + + err = __orinoco_down(dev); + if (err) + printk(KERN_WARNING "%s: Error %d downing interface\n", + dev->name, err); + + netif_device_detach(dev); + priv->hw_unavailable++; + + spin_unlock_irqrestore(&priv->lock, flags); + } + + pcmcia_release_configuration(link->handle); + } + + return 0; +} + +static int orinoco_cs_resume(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct net_device *dev = link->priv; + struct orinoco_private *priv = netdev_priv(dev); + struct orinoco_pccard *card = priv->card; + int err = 0; + unsigned long flags; + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + /* FIXME: should we double check that this is + * the same card as we had before */ + pcmcia_request_configuration(link->handle, &link->conf); + + if (! test_bit(0, &card->hard_reset_in_progress)) { + err = orinoco_reinit_firmware(dev); + if (err) { + printk(KERN_ERR "%s: Error %d re-initializing firmware\n", + dev->name, err); + return -EIO; + } + + spin_lock_irqsave(&priv->lock, flags); + + netif_device_attach(dev); + priv->hw_unavailable--; + + if (priv->open && ! priv->hw_unavailable) { + err = __orinoco_up(dev); + if (err) + printk(KERN_ERR "%s: Error %d restarting card\n", + dev->name, err); + } + + spin_unlock_irqrestore(&priv->lock, flags); + } + } + + return 0; +} + + /* * The card status event handler. Mostly, this schedules other stuff * to run after an event is received. @@ -476,9 +553,7 @@ orinoco_cs_event(event_t event, int priority, dev_link_t *link = args->client_data; struct net_device *dev = link->priv; struct orinoco_private *priv = netdev_priv(dev); - struct orinoco_pccard *card = priv->card; int err = 0; - unsigned long flags; switch (event) { case CS_EVENT_CARD_REMOVAL: @@ -497,70 +572,6 @@ orinoco_cs_event(event_t event, int priority, link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; orinoco_cs_config(link); break; - - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - /* Mark the device as stopped, to block IO until later */ - if (link->state & DEV_CONFIG) { - /* This is probably racy, but I can't think of - a better way, short of rewriting the PCMCIA - layer to not suck :-( */ - if (! test_bit(0, &card->hard_reset_in_progress)) { - spin_lock_irqsave(&priv->lock, flags); - - err = __orinoco_down(dev); - if (err) - printk(KERN_WARNING "%s: %s: Error %d downing interface\n", - dev->name, - event == CS_EVENT_PM_SUSPEND ? "SUSPEND" : "RESET_PHYSICAL", - err); - - netif_device_detach(dev); - priv->hw_unavailable++; - - spin_unlock_irqrestore(&priv->lock, flags); - } - - pcmcia_release_configuration(link->handle); - } - break; - - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (link->state & DEV_CONFIG) { - /* FIXME: should we double check that this is - * the same card as we had before */ - pcmcia_request_configuration(link->handle, &link->conf); - - if (! test_bit(0, &card->hard_reset_in_progress)) { - err = orinoco_reinit_firmware(dev); - if (err) { - printk(KERN_ERR "%s: Error %d re-initializing firmware\n", - dev->name, err); - break; - } - - spin_lock_irqsave(&priv->lock, flags); - - netif_device_attach(dev); - priv->hw_unavailable--; - - if (priv->open && ! priv->hw_unavailable) { - err = __orinoco_up(dev); - if (err) - printk(KERN_ERR "%s: Error %d restarting card\n", - dev->name, err); - - } - - spin_unlock_irqrestore(&priv->lock, flags); - } - } - break; } return err; @@ -669,6 +680,8 @@ static struct pcmcia_driver orinoco_driver = { .detach = orinoco_cs_detach, .event = orinoco_cs_event, .id_table = orinoco_cs_ids, + .suspend = orinoco_cs_suspend, + .resume = orinoco_cs_resume, }; static int __init diff --git a/drivers/net/wireless/ray_cs.c b/drivers/net/wireless/ray_cs.c index 70fd6fd8feb9..c2cb6c8e6d7c 100644 --- a/drivers/net/wireless/ray_cs.c +++ b/drivers/net/wireless/ray_cs.c @@ -891,6 +891,40 @@ static void ray_release(dev_link_t *link) DEBUG(2,"ray_release ending\n"); } +static int ray_suspend(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct net_device *dev = link->priv; + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + if (link->open) + netif_device_detach(dev); + + pcmcia_release_configuration(link->handle); + } + + + return 0; +} + +static int ray_resume(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct net_device *dev = link->priv; + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + pcmcia_request_configuration(link->handle, &link->conf); + if (link->open) { + ray_reset(dev); + netif_device_attach(dev); + } + } + + return 0; +} + /*============================================================================= The card status event handler. Mostly, this schedules other stuff to run after an event is received. A CARD_REMOVAL event @@ -923,29 +957,6 @@ static int ray_event(event_t event, int priority, link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; ray_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - if (link->state & DEV_CONFIG) { - if (link->open) - netif_device_detach(dev); - - pcmcia_release_configuration(link->handle); - } - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (link->state & DEV_CONFIG) { - pcmcia_request_configuration(link->handle, &link->conf); - if (link->open) { - ray_reset(dev); - netif_device_attach(dev); - } - } - break; } return 0; DEBUG(2,"ray_event ending\n"); @@ -2949,6 +2960,8 @@ static struct pcmcia_driver ray_driver = { .event = ray_event, .detach = ray_detach, .id_table = ray_ids, + .suspend = ray_suspend, + .resume = ray_resume, }; static int __init init_ray_cs(void) diff --git a/drivers/net/wireless/spectrum_cs.c b/drivers/net/wireless/spectrum_cs.c index b1bbc8e8e91f..3938a5735659 100644 --- a/drivers/net/wireless/spectrum_cs.c +++ b/drivers/net/wireless/spectrum_cs.c @@ -948,6 +948,56 @@ spectrum_cs_release(dev_link_t *link) ioport_unmap(priv->hw.iobase); } /* spectrum_cs_release */ + +static int +spectrum_cs_suspend(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct net_device *dev = link->priv; + struct orinoco_private *priv = netdev_priv(dev); + unsigned long flags; + int err = 0; + + link->state |= DEV_SUSPEND; + /* Mark the device as stopped, to block IO until later */ + if (link->state & DEV_CONFIG) { + spin_lock_irqsave(&priv->lock, flags); + + err = __orinoco_down(dev); + if (err) + printk(KERN_WARNING "%s: Error %d downing interface\n", + dev->name, err); + + netif_device_detach(dev); + priv->hw_unavailable++; + + spin_unlock_irqrestore(&priv->lock, flags); + + pcmcia_release_configuration(link->handle); + } + + return 0; +} + +static int +spectrum_cs_resume(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct net_device *dev = link->priv; + struct orinoco_private *priv = netdev_priv(dev); + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + /* FIXME: should we double check that this is + * the same card as we had before */ + pcmcia_request_configuration(link->handle, &link->conf); + netif_device_attach(dev); + priv->hw_unavailable--; + schedule_work(&priv->reset_work); + } + return 0; +} + /* * The card status event handler. Mostly, this schedules other stuff * to run after an event is received. @@ -959,8 +1009,6 @@ spectrum_cs_event(event_t event, int priority, dev_link_t *link = args->client_data; struct net_device *dev = link->priv; struct orinoco_private *priv = netdev_priv(dev); - int err = 0; - unsigned long flags; switch (event) { case CS_EVENT_CARD_REMOVAL: @@ -980,49 +1028,9 @@ spectrum_cs_event(event_t event, int priority, spectrum_cs_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - /* Mark the device as stopped, to block IO until later */ - if (link->state & DEV_CONFIG) { - /* This is probably racy, but I can't think of - a better way, short of rewriting the PCMCIA - layer to not suck :-( */ - spin_lock_irqsave(&priv->lock, flags); - - err = __orinoco_down(dev); - if (err) - printk(KERN_WARNING "%s: %s: Error %d downing interface\n", - dev->name, - event == CS_EVENT_PM_SUSPEND ? "SUSPEND" : "RESET_PHYSICAL", - err); - - netif_device_detach(dev); - priv->hw_unavailable++; - - spin_unlock_irqrestore(&priv->lock, flags); - - pcmcia_release_configuration(link->handle); - } - break; - - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (link->state & DEV_CONFIG) { - /* FIXME: should we double check that this is - * the same card as we had before */ - pcmcia_request_configuration(link->handle, &link->conf); - netif_device_attach(dev); - priv->hw_unavailable--; - schedule_work(&priv->reset_work); - } - break; } - return err; + return 0; } /* spectrum_cs_event */ /********************************************************************/ @@ -1050,6 +1058,8 @@ static struct pcmcia_driver orinoco_driver = { }, .attach = spectrum_cs_attach, .detach = spectrum_cs_detach, + .suspend = spectrum_cs_suspend, + .resume = spectrum_cs_resume, .event = spectrum_cs_event, .id_table = spectrum_cs_ids, }; diff --git a/drivers/net/wireless/wavelan_cs.c b/drivers/net/wireless/wavelan_cs.c index c822cad3333f..3e3532830c26 100644 --- a/drivers/net/wireless/wavelan_cs.c +++ b/drivers/net/wireless/wavelan_cs.c @@ -4775,6 +4775,56 @@ wavelan_detach(dev_link_t * link) #endif } +static int wavelan_suspend(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct net_device * dev = (struct net_device *) link->priv; + + /* NB: wavelan_close will be called, but too late, so we are + * obliged to close nicely the wavelan here. David, could you + * close the device before suspending them ? And, by the way, + * could you, on resume, add a "route add -net ..." after the + * ifconfig up ? Thanks... */ + + /* Stop receiving new messages and wait end of transmission */ + wv_ru_stop(dev); + + /* Power down the module */ + hacr_write(dev->base_addr, HACR_DEFAULT & (~HACR_PWR_STAT)); + + /* The card is now suspended */ + link->state |= DEV_SUSPEND; + + if(link->state & DEV_CONFIG) + { + if(link->open) + netif_device_detach(dev); + pcmcia_release_configuration(link->handle); + } + + return 0; +} + +static int wavelan_resume(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct net_device * dev = (struct net_device *) link->priv; + + link->state &= ~DEV_SUSPEND; + if(link->state & DEV_CONFIG) + { + pcmcia_request_configuration(link->handle, &link->conf); + if(link->open) /* If RESET -> True, If RESUME -> False ? */ + { + wv_hw_reset(dev); + netif_device_attach(dev); + } + } + + return 0; +} + + /*------------------------------------------------------------------*/ /* * The card status event handler. Mostly, this schedules other stuff @@ -4832,46 +4882,6 @@ wavelan_event(event_t event, /* The event received */ else dev->irq = 0; break; - - case CS_EVENT_PM_SUSPEND: - /* NB: wavelan_close will be called, but too late, so we are - * obliged to close nicely the wavelan here. David, could you - * close the device before suspending them ? And, by the way, - * could you, on resume, add a "route add -net ..." after the - * ifconfig up ? Thanks... */ - - /* Stop receiving new messages and wait end of transmission */ - wv_ru_stop(dev); - - /* Power down the module */ - hacr_write(dev->base_addr, HACR_DEFAULT & (~HACR_PWR_STAT)); - - /* The card is now suspended */ - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - if(link->state & DEV_CONFIG) - { - if(link->open) - netif_device_detach(dev); - pcmcia_release_configuration(link->handle); - } - break; - - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if(link->state & DEV_CONFIG) - { - pcmcia_request_configuration(link->handle, &link->conf); - if(link->open) /* If RESET -> True, If RESUME -> False ? */ - { - wv_hw_reset(dev); - netif_device_attach(dev); - } - } - break; } #ifdef DEBUG_CALLBACK_TRACE @@ -4898,6 +4908,8 @@ static struct pcmcia_driver wavelan_driver = { .event = wavelan_event, .detach = wavelan_detach, .id_table = wavelan_ids, + .suspend = wavelan_suspend, + .resume = wavelan_resume, }; static int __init diff --git a/drivers/net/wireless/wl3501_cs.c b/drivers/net/wireless/wl3501_cs.c index 978fdc606781..75114318457e 100644 --- a/drivers/net/wireless/wl3501_cs.c +++ b/drivers/net/wireless/wl3501_cs.c @@ -2173,6 +2173,41 @@ static void wl3501_release(dev_link_t *link) link->state &= ~DEV_CONFIG; } +static int wl3501_suspend(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct net_device *dev = link->priv; + + link->state |= DEV_SUSPEND; + + wl3501_pwr_mgmt(dev->priv, WL3501_SUSPEND); + if (link->state & DEV_CONFIG) { + if (link->open) + netif_device_detach(dev); + pcmcia_release_configuration(link->handle); + } + + return 0; +} + +static int wl3501_resume(struct pcmcia_device *p_dev) +{ + dev_link_t *link = dev_to_instance(p_dev); + struct net_device *dev = link->priv; + + wl3501_pwr_mgmt(dev->priv, WL3501_RESUME); + if (link->state & DEV_CONFIG) { + pcmcia_request_configuration(link->handle, &link->conf); + if (link->open) { + wl3501_reset(dev); + netif_device_attach(dev); + } + } + + return 0; +} + + /** * wl3501_event - The card status event handler * @event - event @@ -2206,30 +2241,6 @@ static int wl3501_event(event_t event, int pri, event_callback_args_t *args) link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; wl3501_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - wl3501_pwr_mgmt(dev->priv, WL3501_SUSPEND); - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - if (link->state & DEV_CONFIG) { - if (link->open) - netif_device_detach(dev); - pcmcia_release_configuration(link->handle); - } - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - wl3501_pwr_mgmt(dev->priv, WL3501_RESUME); - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (link->state & DEV_CONFIG) { - pcmcia_request_configuration(link->handle, &link->conf); - if (link->open) { - wl3501_reset(dev); - netif_device_attach(dev); - } - } - break; } return 0; } @@ -2249,6 +2260,8 @@ static struct pcmcia_driver wl3501_driver = { .event = wl3501_event, .detach = wl3501_detach, .id_table = wl3501_ids, + .suspend = wl3501_suspend, + .resume = wl3501_resume, }; static int __init wl3501_init_module(void) diff --git a/drivers/parport/parport_cs.c b/drivers/parport/parport_cs.c index 24e6aacddb74..4c89853785ed 100644 --- a/drivers/parport/parport_cs.c +++ b/drivers/parport/parport_cs.c @@ -325,6 +325,28 @@ void parport_cs_release(dev_link_t *link) } /* parport_cs_release */ +static int parport_suspend(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_release_configuration(link->handle); + + return 0; +} + +static int parport_resume(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + + link->state &= ~DEV_SUSPEND; + if (DEV_OK(link)) + pcmcia_request_configuration(link->handle, &link->conf); + + return 0; +} + /*====================================================================== The card status event handler. Mostly, this schedules other @@ -349,20 +371,6 @@ int parport_event(event_t event, int priority, link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; parport_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - if (link->state & DEV_CONFIG) - pcmcia_release_configuration(link->handle); - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (DEV_OK(link)) - pcmcia_request_configuration(link->handle, &link->conf); - break; } return 0; } /* parport_event */ @@ -383,7 +391,8 @@ static struct pcmcia_driver parport_cs_driver = { .event = parport_event, .detach = parport_detach, .id_table = parport_ids, - + .suspend = parport_suspend, + .resume = parport_resume, }; static int __init init_parport_cs(void) diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index b120794c03a9..a802c65c3534 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -951,6 +951,16 @@ static int send_event_callback(struct device *dev, void * _data) if (p_dev->state & (CLIENT_UNBOUND|CLIENT_STALE)) return 0; + if ((data->event == CS_EVENT_PM_SUSPEND) || + (data->event == CS_EVENT_RESET_PHYSICAL)) { + if (p_drv->suspend) + return p_drv->suspend(p_dev); + } else if ((data->event == CS_EVENT_PM_RESUME) || + (data->event == CS_EVENT_CARD_RESET)) { + if (p_drv->resume) + return p_drv->resume(p_dev); + } + if (p_drv->event) return p_drv->event(data->event, data->priority, &p_dev->event_callback_args); diff --git a/drivers/scsi/pcmcia/aha152x_stub.c b/drivers/scsi/pcmcia/aha152x_stub.c index 7c5306499832..82988a3e35ec 100644 --- a/drivers/scsi/pcmcia/aha152x_stub.c +++ b/drivers/scsi/pcmcia/aha152x_stub.c @@ -272,11 +272,37 @@ static void aha152x_release_cs(dev_link_t *link) link->state &= ~DEV_CONFIG; } +static int aha152x_suspend(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_release_configuration(link->handle); + + return 0; +} + +static int aha152x_resume(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + scsi_info_t *info = link->priv; + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + Scsi_Cmnd tmp; + pcmcia_request_configuration(link->handle, &link->conf); + tmp.device->host = info->host; + aha152x_host_reset(&tmp); + } + + return 0; +} + static int aha152x_event(event_t event, int priority, event_callback_args_t *args) { dev_link_t *link = args->client_data; - scsi_info_t *info = link->priv; DEBUG(0, "aha152x_event(0x%06x)\n", event); @@ -290,24 +316,6 @@ static int aha152x_event(event_t event, int priority, link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; aha152x_config_cs(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - if (link->state & DEV_CONFIG) - pcmcia_release_configuration(link->handle); - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (link->state & DEV_CONFIG) { - Scsi_Cmnd tmp; - pcmcia_request_configuration(link->handle, &link->conf); - tmp.device->host = info->host; - aha152x_host_reset(&tmp); - } - break; } return 0; } @@ -331,6 +339,8 @@ static struct pcmcia_driver aha152x_cs_driver = { .event = aha152x_event, .detach = aha152x_detach, .id_table = aha152x_ids, + .suspend = aha152x_suspend, + .resume = aha152x_resume, }; static int __init init_aha152x_cs(void) diff --git a/drivers/scsi/pcmcia/fdomain_stub.c b/drivers/scsi/pcmcia/fdomain_stub.c index db8f5cd85ffe..9e1d68c14694 100644 --- a/drivers/scsi/pcmcia/fdomain_stub.c +++ b/drivers/scsi/pcmcia/fdomain_stub.c @@ -256,6 +256,30 @@ static void fdomain_release(dev_link_t *link) /*====================================================================*/ +static int fdomain_suspend(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_release_configuration(link->handle); + + return 0; +} + +static int fdomain_resume(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + pcmcia_request_configuration(link->handle, &link->conf); + fdomain_16x0_bus_reset(NULL); + } + + return 0; +} + static int fdomain_event(event_t event, int priority, event_callback_args_t *args) { @@ -273,22 +297,6 @@ static int fdomain_event(event_t event, int priority, link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; fdomain_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - if (link->state & DEV_CONFIG) - pcmcia_release_configuration(link->handle); - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (link->state & DEV_CONFIG) { - pcmcia_request_configuration(link->handle, &link->conf); - fdomain_16x0_bus_reset(NULL); - } - break; } return 0; } /* fdomain_event */ @@ -311,6 +319,8 @@ static struct pcmcia_driver fdomain_cs_driver = { .event = fdomain_event, .detach = fdomain_detach, .id_table = fdomain_ids, + .suspend = fdomain_suspend, + .resume = fdomain_resume, }; static int __init init_fdomain_cs(void) diff --git a/drivers/scsi/pcmcia/nsp_cs.c b/drivers/scsi/pcmcia/nsp_cs.c index 050ea13ff80b..870e87180d12 100644 --- a/drivers/scsi/pcmcia/nsp_cs.c +++ b/drivers/scsi/pcmcia/nsp_cs.c @@ -2021,6 +2021,59 @@ static void nsp_cs_release(dev_link_t *link) #endif } /* nsp_cs_release */ +static int nsp_cs_suspend(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + scsi_info_t *info = link->priv; + nsp_hw_data *data; + + link->state |= DEV_SUSPEND; + + nsp_dbg(NSP_DEBUG_INIT, "event: suspend"); + + if (info->host != NULL) { + nsp_msg(KERN_INFO, "clear SDTR status"); + + data = (nsp_hw_data *)info->host->hostdata; + + nsphw_init_sync(data); + } + + info->stop = 1; + + if (link->state & DEV_CONFIG) + pcmcia_release_configuration(link->handle); + + return 0; +} + +static int nsp_cs_resume(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + scsi_info_t *info = link->priv; + nsp_hw_data *data; + + nsp_dbg(NSP_DEBUG_INIT, "event: resume"); + + link->state &= ~DEV_SUSPEND; + + if (link->state & DEV_CONFIG) + pcmcia_request_configuration(link->handle, &link->conf); + + info->stop = 0; + + if (info->host != NULL) { + nsp_msg(KERN_INFO, "reset host and bus"); + + data = (nsp_hw_data *)info->host->hostdata; + + nsphw_init (data); + nsp_bus_reset(data); + } + + return 0; +} + /*====================================================================== The card status event handler. Mostly, this schedules other @@ -2039,8 +2092,6 @@ static int nsp_cs_event(event_t event, event_callback_args_t *args) { dev_link_t *link = args->client_data; - scsi_info_t *info = link->priv; - nsp_hw_data *data; nsp_dbg(NSP_DEBUG_INIT, "in, event=0x%08x", event); @@ -2062,51 +2113,6 @@ static int nsp_cs_event(event_t event, #endif nsp_cs_config(link); break; - - case CS_EVENT_PM_SUSPEND: - nsp_dbg(NSP_DEBUG_INIT, "event: suspend"); - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - /* Mark the device as stopped, to block IO until later */ - nsp_dbg(NSP_DEBUG_INIT, "event: reset physical"); - - if (info->host != NULL) { - nsp_msg(KERN_INFO, "clear SDTR status"); - - data = (nsp_hw_data *)info->host->hostdata; - - nsphw_init_sync(data); - } - - info->stop = 1; - if (link->state & DEV_CONFIG) { - pcmcia_release_configuration(link->handle); - } - break; - - case CS_EVENT_PM_RESUME: - nsp_dbg(NSP_DEBUG_INIT, "event: resume"); - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - nsp_dbg(NSP_DEBUG_INIT, "event: reset"); - if (link->state & DEV_CONFIG) { - pcmcia_request_configuration(link->handle, &link->conf); - } - info->stop = 0; - - if (info->host != NULL) { - nsp_msg(KERN_INFO, "reset host and bus"); - - data = (nsp_hw_data *)info->host->hostdata; - - nsphw_init (data); - nsp_bus_reset(data); - } - - break; - default: nsp_dbg(NSP_DEBUG_INIT, "event: unknown"); break; @@ -2140,6 +2146,8 @@ static struct pcmcia_driver nsp_driver = { .event = nsp_cs_event, .detach = nsp_cs_detach, .id_table = nsp_cs_ids, + .suspend = nsp_cs_suspend, + .resume = nsp_cs_resume, }; #endif diff --git a/drivers/scsi/pcmcia/qlogic_stub.c b/drivers/scsi/pcmcia/qlogic_stub.c index bb091a45a880..2541a999a0e5 100644 --- a/drivers/scsi/pcmcia/qlogic_stub.c +++ b/drivers/scsi/pcmcia/qlogic_stub.c @@ -349,6 +349,40 @@ static void qlogic_release(dev_link_t *link) /*====================================================================*/ +static int qlogic_suspend(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_release_configuration(link->handle); + + return 0; +} + +static int qlogic_resume(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + scsi_info_t *info = link->priv; + + pcmcia_request_configuration(link->handle, &link->conf); + if ((info->manf_id == MANFID_MACNICA) || + (info->manf_id == MANFID_PIONEER) || + (info->manf_id == 0x0098)) { + outb(0x80, link->io.BasePort1 + 0xd); + outb(0x24, link->io.BasePort1 + 0x9); + outb(0x04, link->io.BasePort1 + 0xd); + } + /* Ugggglllyyyy!!! */ + qlogicfas408_bus_reset(NULL); + } + + return 0; +} + static int qlogic_event(event_t event, int priority, event_callback_args_t * args) { dev_link_t *link = args->client_data; @@ -365,29 +399,6 @@ static int qlogic_event(event_t event, int priority, event_callback_args_t * arg link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; qlogic_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - if (link->state & DEV_CONFIG) - pcmcia_release_configuration(link->handle); - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (link->state & DEV_CONFIG) { - scsi_info_t *info = link->priv; - pcmcia_request_configuration(link->handle, &link->conf); - if ((info->manf_id == MANFID_MACNICA) || (info->manf_id == MANFID_PIONEER) || (info->manf_id == 0x0098)) { - outb(0x80, link->io.BasePort1 + 0xd); - outb(0x24, link->io.BasePort1 + 0x9); - outb(0x04, link->io.BasePort1 + 0xd); - } - /* Ugggglllyyyy!!! */ - qlogicfas408_bus_reset(NULL); - } - break; } return 0; } /* qlogic_event */ @@ -423,6 +434,8 @@ static struct pcmcia_driver qlogic_cs_driver = { .event = qlogic_event, .detach = qlogic_detach, .id_table = qlogic_ids, + .suspend = qlogic_suspend, + .resume = qlogic_resume, }; static int __init init_qlogic_cs(void) diff --git a/drivers/scsi/pcmcia/sym53c500_cs.c b/drivers/scsi/pcmcia/sym53c500_cs.c index 98b64b2aa8ee..c4e3e2294c66 100644 --- a/drivers/scsi/pcmcia/sym53c500_cs.c +++ b/drivers/scsi/pcmcia/sym53c500_cs.c @@ -872,11 +872,48 @@ cs_failed: return; } /* SYM53C500_config */ +static int sym53c500_suspend(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_release_configuration(link->handle); + + return 0; +} + +static int sym53c500_resume(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + struct scsi_info_t *info = link->priv; + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) { + pcmcia_request_configuration(link->handle, &link->conf); + + /* See earlier comment about manufacturer IDs. */ + if ((info->manf_id == MANFID_MACNICA) || + (info->manf_id == MANFID_PIONEER) || + (info->manf_id == 0x0098)) { + outb(0x80, link->io.BasePort1 + 0xd); + outb(0x24, link->io.BasePort1 + 0x9); + outb(0x04, link->io.BasePort1 + 0xd); + } + /* + * If things don't work after a "resume", + * this is a good place to start looking. + */ + SYM53C500_int_host_reset(link->io.BasePort1); + } + + return 0; +} + static int SYM53C500_event(event_t event, int priority, event_callback_args_t *args) { dev_link_t *link = args->client_data; - struct scsi_info_t *info = link->priv; DEBUG(1, "SYM53C500_event(0x%06x)\n", event); @@ -890,34 +927,6 @@ SYM53C500_event(event_t event, int priority, event_callback_args_t *args) link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; SYM53C500_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - if (link->state & DEV_CONFIG) - pcmcia_release_configuration(link->handle); - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (link->state & DEV_CONFIG) { - pcmcia_request_configuration(link->handle, &link->conf); - /* See earlier comment about manufacturer IDs. */ - if ((info->manf_id == MANFID_MACNICA) || - (info->manf_id == MANFID_PIONEER) || - (info->manf_id == 0x0098)) { - outb(0x80, link->io.BasePort1 + 0xd); - outb(0x24, link->io.BasePort1 + 0x9); - outb(0x04, link->io.BasePort1 + 0xd); - } - /* - * If things don't work after a "resume", - * this is a good place to start looking. - */ - SYM53C500_int_host_reset(link->io.BasePort1); - } - break; } return 0; } /* SYM53C500_event */ @@ -1012,6 +1021,8 @@ static struct pcmcia_driver sym53c500_cs_driver = { .event = SYM53C500_event, .detach = SYM53C500_detach, .id_table = sym53c500_ids, + .suspend = sym53c500_suspend, + .resume = sym53c500_resume, }; static int __init diff --git a/drivers/serial/serial_cs.c b/drivers/serial/serial_cs.c index 7ce0c7e66d37..3487ee9eab1d 100644 --- a/drivers/serial/serial_cs.c +++ b/drivers/serial/serial_cs.c @@ -159,8 +159,9 @@ static void serial_remove(dev_link_t *link) } } -static void serial_suspend(dev_link_t *link) +static int serial_suspend(struct pcmcia_device *dev) { + dev_link_t *link = dev_to_instance(dev); link->state |= DEV_SUSPEND; if (link->state & DEV_CONFIG) { @@ -173,10 +174,13 @@ static void serial_suspend(dev_link_t *link) if (!info->slave) pcmcia_release_configuration(link->handle); } + + return 0; } -static void serial_resume(dev_link_t *link) +static int serial_resume(struct pcmcia_device *dev) { + dev_link_t *link = dev_to_instance(dev); link->state &= ~DEV_SUSPEND; if (DEV_OK(link)) { @@ -189,6 +193,8 @@ static void serial_resume(dev_link_t *link) for (i = 0; i < info->ndev; i++) serial8250_resume_port(info->line[i]); } + + return 0; } /*====================================================================== @@ -731,7 +737,6 @@ static int serial_event(event_t event, int priority, event_callback_args_t * args) { dev_link_t *link = args->client_data; - struct serial_info *info = link->priv; DEBUG(1, "serial_event(0x%06x)\n", event); @@ -744,24 +749,6 @@ serial_event(event_t event, int priority, event_callback_args_t * args) link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; serial_config(link); break; - - case CS_EVENT_PM_SUSPEND: - serial_suspend(link); - break; - - case CS_EVENT_RESET_PHYSICAL: - if ((link->state & DEV_CONFIG) && !info->slave) - pcmcia_release_configuration(link->handle); - break; - - case CS_EVENT_PM_RESUME: - serial_resume(link); - break; - - case CS_EVENT_CARD_RESET: - if (DEV_OK(link) && !info->slave) - pcmcia_request_configuration(link->handle, &link->conf); - break; } return 0; } @@ -881,6 +868,8 @@ static struct pcmcia_driver serial_cs_driver = { .event = serial_event, .detach = serial_detach, .id_table = serial_ids, + .suspend = serial_suspend, + .resume = serial_resume, }; static int __init init_serial_cs(void) diff --git a/drivers/telephony/ixj_pcmcia.c b/drivers/telephony/ixj_pcmcia.c index 57c0c6e3fbed..7cca46be0c0f 100644 --- a/drivers/telephony/ixj_pcmcia.c +++ b/drivers/telephony/ixj_pcmcia.c @@ -255,6 +255,28 @@ static void ixj_cs_release(dev_link_t *link) link->state &= ~DEV_CONFIG; } +static int ixj_suspend(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_release_configuration(link->handle); + + return 0; +} + +static int ixj_resume(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + + link->state &= ~DEV_SUSPEND; + if (DEV_OK(link)) + pcmcia_request_configuration(link->handle, &link->conf); + + return 0; +} + static int ixj_event(event_t event, int priority, event_callback_args_t * args) { dev_link_t *link = args->client_data; @@ -271,20 +293,6 @@ static int ixj_event(event_t event, int priority, event_callback_args_t * args) link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; ixj_config(link); break; - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - if (link->state & DEV_CONFIG) - pcmcia_release_configuration(link->handle); - break; - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (DEV_OK(link)) - pcmcia_request_configuration(link->handle, &link->conf); - break; } return 0; } @@ -304,6 +312,8 @@ static struct pcmcia_driver ixj_driver = { .event = ixj_event, .detach = ixj_detach, .id_table = ixj_ids, + .suspend = ixj_suspend, + .resume = ixj_resume, }; static int __init ixj_pcmcia_init(void) diff --git a/drivers/usb/host/sl811_cs.c b/drivers/usb/host/sl811_cs.c index 5056b7459994..cb8c2bdbbd04 100644 --- a/drivers/usb/host/sl811_cs.c +++ b/drivers/usb/host/sl811_cs.c @@ -323,6 +323,28 @@ cs_failed: } } +static int sl811_suspend(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + + link->state |= DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_release_configuration(link->handle); + + return 0; +} + +static int sl811_resume(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + + link->state &= ~DEV_SUSPEND; + if (link->state & DEV_CONFIG) + pcmcia_request_configuration(link->handle, &link->conf); + + return 0; +} + static int sl811_cs_event(event_t event, int priority, event_callback_args_t *args) { @@ -341,23 +363,6 @@ sl811_cs_event(event_t event, int priority, event_callback_args_t *args) link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; sl811_cs_config(link); break; - - case CS_EVENT_PM_SUSPEND: - link->state |= DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - if (link->state & DEV_CONFIG) - pcmcia_release_configuration(link->handle); - break; - - case CS_EVENT_PM_RESUME: - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - if (link->state & DEV_CONFIG) - pcmcia_request_configuration(link->handle, &link->conf); - DBG(0, "reset sl811-hcd here?\n"); - break; } return 0; } @@ -417,6 +422,8 @@ static struct pcmcia_driver sl811_cs_driver = { .event = sl811_cs_event, .detach = sl811_cs_detach, .id_table = sl811_ids, + .suspend = sl811_suspend, + .resume = sl811_resume, }; /*====================================================================*/ diff --git a/include/pcmcia/ds.h b/include/pcmcia/ds.h index cb8b6e6ce66c..020055199008 100644 --- a/include/pcmcia/ds.h +++ b/include/pcmcia/ds.h @@ -137,6 +137,10 @@ struct pcmcia_driver { int (*event) (event_t event, int priority, event_callback_args_t *); void (*detach)(dev_link_t *); + + int (*suspend) (struct pcmcia_device *dev); + int (*resume) (struct pcmcia_device *dev); + struct module *owner; struct pcmcia_device_id *id_table; struct device_driver drv; @@ -193,6 +197,8 @@ struct pcmcia_device { #define handle_to_pdev(handle) (handle) #define handle_to_dev(handle) (handle->dev) +#define dev_to_instance(dev) (dev->instance) + /* error reporting */ void cs_error(client_handle_t handle, int func, int ret); From 8e9e793d68fcda6cc84c18cedf85ca0f91d801a8 Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Fri, 6 Jan 2006 00:02:03 +0100 Subject: [PATCH 32/48] [PATCH] pcmcia: merge suspend into device model Merge the suspend and resume methods for 16-bit PCMCIA cards into the device model -- for both runtime power management and suspend to ram/disk. Bugfix in ds.c by Richard Purdie Signed-Off-By: Richard Purdie Signed-off-by: Dominik Brodowski --- drivers/base/power/runtime.c | 1 + drivers/pcmcia/cs.c | 14 +++++- drivers/pcmcia/cs_internal.h | 2 + drivers/pcmcia/ds.c | 94 ++++++++++++++++++++++++++++++++---- 4 files changed, 100 insertions(+), 11 deletions(-) diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 4bafef83e79f..96370ec1d673 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -62,6 +62,7 @@ int dpm_runtime_suspend(struct device * dev, pm_message_t state) up(&dpm_sem); return error; } +EXPORT_SYMBOL(dpm_runtime_suspend); #if 0 diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c index 7cf09084ef61..83d2753814c2 100644 --- a/drivers/pcmcia/cs.c +++ b/drivers/pcmcia/cs.c @@ -780,8 +780,13 @@ int pccard_reset_card(struct pcmcia_socket *skt) ret = send_event(skt, CS_EVENT_RESET_REQUEST, CS_EVENT_PRI_LOW); if (ret == 0) { send_event(skt, CS_EVENT_RESET_PHYSICAL, CS_EVENT_PRI_LOW); - if (socket_reset(skt) == CS_SUCCESS) + if (skt->callback) + skt->callback->suspend(skt); + if (socket_reset(skt) == CS_SUCCESS) { send_event(skt, CS_EVENT_CARD_RESET, CS_EVENT_PRI_LOW); + if (skt->callback) + skt->callback->resume(skt); + } } ret = CS_SUCCESS; @@ -812,6 +817,11 @@ int pcmcia_suspend_card(struct pcmcia_socket *skt) ret = CS_UNSUPPORTED_FUNCTION; break; } + if (skt->callback) { + ret = skt->callback->suspend(skt); + if (ret) + break; + } ret = socket_suspend(skt); } while (0); up(&skt->skt_sem); @@ -838,6 +848,8 @@ int pcmcia_resume_card(struct pcmcia_socket *skt) break; } ret = socket_resume(skt); + if (!ret && skt->callback) + skt->callback->resume(skt); } while (0); up(&skt->skt_sem); diff --git a/drivers/pcmcia/cs_internal.h b/drivers/pcmcia/cs_internal.h index 634426b78f2c..7b37eba35bf1 100644 --- a/drivers/pcmcia/cs_internal.h +++ b/drivers/pcmcia/cs_internal.h @@ -143,6 +143,8 @@ struct pcmcia_callback{ struct module *owner; int (*event) (struct pcmcia_socket *s, event_t event, int priority); void (*requery) (struct pcmcia_socket *s); + int (*suspend) (struct pcmcia_socket *s); + int (*resume) (struct pcmcia_socket *s); }; int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c); diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index a802c65c3534..5223395b246a 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -920,6 +920,78 @@ static struct device_attribute pcmcia_dev_attrs[] = { __ATTR_NULL, }; +/* PM support, also needed for reset */ + +static int pcmcia_dev_suspend(struct device * dev, pm_message_t state) +{ + struct pcmcia_device *p_dev = to_pcmcia_dev(dev); + struct pcmcia_driver *p_drv = NULL; + + if (dev->driver) + p_drv = to_pcmcia_drv(dev->driver); + + if (p_drv && p_drv->suspend) + return p_drv->suspend(p_dev); + + return 0; +} + + +static int pcmcia_dev_resume(struct device * dev) +{ + struct pcmcia_device *p_dev = to_pcmcia_dev(dev); + struct pcmcia_driver *p_drv = NULL; + + if (dev->driver) + p_drv = to_pcmcia_drv(dev->driver); + + if (p_drv && p_drv->resume) + return p_drv->resume(p_dev); + + return 0; +} + + +static int pcmcia_bus_suspend_callback(struct device *dev, void * _data) +{ + struct pcmcia_socket *skt = _data; + struct pcmcia_device *p_dev = to_pcmcia_dev(dev); + + if (p_dev->socket != skt) + return 0; + + return dpm_runtime_suspend(dev, PMSG_SUSPEND); +} + +static int pcmcia_bus_resume_callback(struct device *dev, void * _data) +{ + struct pcmcia_socket *skt = _data; + struct pcmcia_device *p_dev = to_pcmcia_dev(dev); + + if (p_dev->socket != skt) + return 0; + + dpm_runtime_resume(dev); + + return 0; +} + +static int pcmcia_bus_resume(struct pcmcia_socket *skt) +{ + bus_for_each_dev(&pcmcia_bus_type, NULL, skt, pcmcia_bus_resume_callback); + return 0; +} + +static int pcmcia_bus_suspend(struct pcmcia_socket *skt) +{ + if (bus_for_each_dev(&pcmcia_bus_type, NULL, skt, + pcmcia_bus_suspend_callback)) { + pcmcia_bus_resume(skt); + return -EIO; + } + return 0; +} + /*====================================================================== @@ -951,16 +1023,6 @@ static int send_event_callback(struct device *dev, void * _data) if (p_dev->state & (CLIENT_UNBOUND|CLIENT_STALE)) return 0; - if ((data->event == CS_EVENT_PM_SUSPEND) || - (data->event == CS_EVENT_RESET_PHYSICAL)) { - if (p_drv->suspend) - return p_drv->suspend(p_dev); - } else if ((data->event == CS_EVENT_PM_RESUME) || - (data->event == CS_EVENT_CARD_RESET)) { - if (p_drv->resume) - return p_drv->resume(p_dev); - } - if (p_drv->event) return p_drv->event(data->event, data->priority, &p_dev->event_callback_args); @@ -1012,6 +1074,13 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority) ret = send_event(skt, event, priority); break; + case CS_EVENT_PM_SUSPEND: + case CS_EVENT_PM_RESUME: + case CS_EVENT_RESET_PHYSICAL: + case CS_EVENT_CARD_RESET: + handle_event(skt, event); + break; + default: handle_event(skt, event); send_event(skt, event, priority); @@ -1166,10 +1235,13 @@ int pcmcia_deregister_client(struct pcmcia_device *p_dev) } /* deregister_client */ EXPORT_SYMBOL(pcmcia_deregister_client); + static struct pcmcia_callback pcmcia_bus_callback = { .owner = THIS_MODULE, .event = ds_event, .requery = pcmcia_bus_rescan, + .suspend = pcmcia_bus_suspend, + .resume = pcmcia_bus_resume, }; static int __devinit pcmcia_bus_add_socket(struct class_device *class_dev, @@ -1238,6 +1310,8 @@ struct bus_type pcmcia_bus_type = { .uevent = pcmcia_bus_uevent, .match = pcmcia_bus_match, .dev_attrs = pcmcia_dev_attrs, + .suspend = pcmcia_dev_suspend, + .resume = pcmcia_dev_resume, }; From cc3b4866bee996c922e875b8c8efe9f0d8803aae Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Mon, 14 Nov 2005 21:23:14 +0100 Subject: [PATCH 33/48] [PATCH] pcmcia: unify detach, REMOVAL_EVENT handlers into one remove callback Unify the "detach" and REMOVAL_EVENT handlers to one "remove" function. Old functionality is preserved, for the moment. Signed-off-by: Dominik Brodowski --- Documentation/pcmcia/driver-changes.txt | 3 + drivers/bluetooth/bluecard_cs.c | 24 ++---- drivers/bluetooth/bt3c_cs.c | 24 ++---- drivers/bluetooth/btuart_cs.c | 24 ++---- drivers/bluetooth/dtl1_cs.c | 24 ++---- drivers/char/pcmcia/cm4000_cs.c | 57 +++++---------- drivers/char/pcmcia/cm4040_cs.c | 52 +++++-------- drivers/char/pcmcia/synclink_cs.c | 34 ++------- drivers/ide/legacy/ide-cs.c | 21 ++---- drivers/isdn/hardware/avm/avm_cs.c | 34 ++------- drivers/isdn/hisax/avma1_cs.c | 39 ++-------- drivers/isdn/hisax/elsa_cs.c | 26 ++----- drivers/isdn/hisax/sedlbauer_cs.c | 38 ++-------- drivers/isdn/hisax/teles_cs.c | 26 ++----- drivers/mtd/maps/pcmciamtd.c | 36 +++------ drivers/net/pcmcia/3c574_cs.c | 18 ++--- drivers/net/pcmcia/3c589_cs.c | 20 ++--- drivers/net/pcmcia/axnet_cs.c | 18 ++--- drivers/net/pcmcia/com20020_cs.c | 19 ++--- drivers/net/pcmcia/fmvj18x_cs.c | 19 ++--- drivers/net/pcmcia/ibmtr_cs.c | 23 ++---- drivers/net/pcmcia/nmclan_cs.c | 18 ++--- drivers/net/pcmcia/pcnet_cs.c | 48 +++++------- drivers/net/pcmcia/smc91c92_cs.c | 18 ++--- drivers/net/pcmcia/xirc2ps_cs.c | 28 ++----- drivers/net/wireless/airo_cs.c | 31 +++----- drivers/net/wireless/atmel_cs.c | 25 ++----- drivers/net/wireless/hostap/hostap_cs.c | 28 ++----- drivers/net/wireless/netwave_cs.c | 33 +++------ drivers/net/wireless/orinoco_cs.c | 30 ++------ drivers/net/wireless/ray_cs.c | 43 ++++------- drivers/net/wireless/spectrum_cs.c | 37 ++-------- drivers/net/wireless/wavelan_cs.c | 31 ++------ drivers/net/wireless/wavelan_cs.p.h | 2 +- drivers/net/wireless/wl3501_cs.c | 32 +++----- drivers/parport/parport_cs.c | 26 ++----- drivers/pcmcia/ds.c | 97 ++++++++++++++++--------- drivers/scsi/pcmcia/aha152x_stub.c | 17 ++--- drivers/scsi/pcmcia/fdomain_stub.c | 17 ++--- drivers/scsi/pcmcia/nsp_cs.c | 23 ++---- drivers/scsi/pcmcia/nsp_cs.h | 2 +- drivers/scsi/pcmcia/qlogic_stub.c | 17 ++--- drivers/scsi/pcmcia/sym53c500_cs.c | 15 +--- drivers/serial/serial_cs.c | 19 ++--- drivers/telephony/ixj_pcmcia.c | 24 ++---- drivers/usb/host/sl811_cs.c | 31 +++----- include/pcmcia/ds.h | 2 + 47 files changed, 375 insertions(+), 898 deletions(-) diff --git a/Documentation/pcmcia/driver-changes.txt b/Documentation/pcmcia/driver-changes.txt index 5c822f54d46c..45c25c7a3445 100644 --- a/Documentation/pcmcia/driver-changes.txt +++ b/Documentation/pcmcia/driver-changes.txt @@ -1,5 +1,8 @@ This file details changes in 2.6 which affect PCMCIA card driver authors: +* Unify detach and REMOVAL event code (as of 2.6.16) + void (*remove) (struct pcmcia_device *dev); + * Move suspend, resume and reset out of event handler (as of 2.6.16) int (*suspend) (struct pcmcia_device *dev); int (*resume) (struct pcmcia_device *dev); diff --git a/drivers/bluetooth/bluecard_cs.c b/drivers/bluetooth/bluecard_cs.c index 5b24131e5430..f5088cb3812b 100644 --- a/drivers/bluetooth/bluecard_cs.c +++ b/drivers/bluetooth/bluecard_cs.c @@ -92,7 +92,7 @@ static int bluecard_event(event_t event, int priority, event_callback_args_t *ar static dev_info_t dev_info = "bluecard_cs"; static dev_link_t *bluecard_attach(void); -static void bluecard_detach(dev_link_t *); +static void bluecard_detach(struct pcmcia_device *p_dev); static dev_link_t *dev_list = NULL; @@ -899,7 +899,7 @@ static dev_link_t *bluecard_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != CS_SUCCESS) { cs_error(link->handle, RegisterClient, ret); - bluecard_detach(link); + bluecard_detach(link->handle); return NULL; } @@ -907,11 +907,11 @@ static dev_link_t *bluecard_attach(void) } -static void bluecard_detach(dev_link_t *link) +static void bluecard_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); bluecard_info_t *info = link->priv; dev_link_t **linkp; - int ret; /* Locate device structure */ for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) @@ -924,12 +924,6 @@ static void bluecard_detach(dev_link_t *link) if (link->state & DEV_CONFIG) bluecard_release(link); - if (link->handle) { - ret = pcmcia_deregister_client(link->handle); - if (ret != CS_SUCCESS) - cs_error(link->handle, DeregisterClient, ret); - } - /* Unlink device structure, free bits */ *linkp = link->next; @@ -1070,16 +1064,8 @@ static int bluecard_resume(struct pcmcia_device *dev) static int bluecard_event(event_t event, int priority, event_callback_args_t *args) { dev_link_t *link = args->client_data; - bluecard_info_t *info = link->priv; switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) { - bluecard_close(info); - bluecard_release(link); - } - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; bluecard_config(link); @@ -1104,7 +1090,7 @@ static struct pcmcia_driver bluecard_driver = { }, .attach = bluecard_attach, .event = bluecard_event, - .detach = bluecard_detach, + .remove = bluecard_detach, .id_table = bluecard_ids, .suspend = bluecard_suspend, .resume = bluecard_resume, diff --git a/drivers/bluetooth/bt3c_cs.c b/drivers/bluetooth/bt3c_cs.c index 1d524baa24a0..02ce38e33d32 100644 --- a/drivers/bluetooth/bt3c_cs.c +++ b/drivers/bluetooth/bt3c_cs.c @@ -95,7 +95,7 @@ static int bt3c_event(event_t event, int priority, event_callback_args_t *args); static dev_info_t dev_info = "bt3c_cs"; static dev_link_t *bt3c_attach(void); -static void bt3c_detach(dev_link_t *); +static void bt3c_detach(struct pcmcia_device *p_dev); static dev_link_t *dev_list = NULL; @@ -700,7 +700,7 @@ static dev_link_t *bt3c_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != CS_SUCCESS) { cs_error(link->handle, RegisterClient, ret); - bt3c_detach(link); + bt3c_detach(link->handle); return NULL; } @@ -708,11 +708,11 @@ static dev_link_t *bt3c_attach(void) } -static void bt3c_detach(dev_link_t *link) +static void bt3c_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); bt3c_info_t *info = link->priv; dev_link_t **linkp; - int ret; /* Locate device structure */ for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) @@ -725,12 +725,6 @@ static void bt3c_detach(dev_link_t *link) if (link->state & DEV_CONFIG) bt3c_release(link); - if (link->handle) { - ret = pcmcia_deregister_client(link->handle); - if (ret != CS_SUCCESS) - cs_error(link->handle, DeregisterClient, ret); - } - /* Unlink device structure, free bits */ *linkp = link->next; @@ -916,16 +910,8 @@ static int bt3c_resume(struct pcmcia_device *dev) static int bt3c_event(event_t event, int priority, event_callback_args_t *args) { dev_link_t *link = args->client_data; - bt3c_info_t *info = link->priv; switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) { - bt3c_close(info); - bt3c_release(link); - } - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; bt3c_config(link); @@ -948,7 +934,7 @@ static struct pcmcia_driver bt3c_driver = { }, .attach = bt3c_attach, .event = bt3c_event, - .detach = bt3c_detach, + .remove = bt3c_detach, .id_table = bt3c_ids, .suspend = bt3c_suspend, .resume = bt3c_resume, diff --git a/drivers/bluetooth/btuart_cs.c b/drivers/bluetooth/btuart_cs.c index 1828ba6ca25e..63221d383fda 100644 --- a/drivers/bluetooth/btuart_cs.c +++ b/drivers/bluetooth/btuart_cs.c @@ -91,7 +91,7 @@ static int btuart_event(event_t event, int priority, event_callback_args_t *args static dev_info_t dev_info = "btuart_cs"; static dev_link_t *btuart_attach(void); -static void btuart_detach(dev_link_t *); +static void btuart_detach(struct pcmcia_device *p_dev); static dev_link_t *dev_list = NULL; @@ -619,7 +619,7 @@ static dev_link_t *btuart_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != CS_SUCCESS) { cs_error(link->handle, RegisterClient, ret); - btuart_detach(link); + btuart_detach(link->handle); return NULL; } @@ -627,11 +627,11 @@ static dev_link_t *btuart_attach(void) } -static void btuart_detach(dev_link_t *link) +static void btuart_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); btuart_info_t *info = link->priv; dev_link_t **linkp; - int ret; /* Locate device structure */ for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) @@ -644,12 +644,6 @@ static void btuart_detach(dev_link_t *link) if (link->state & DEV_CONFIG) btuart_release(link); - if (link->handle) { - ret = pcmcia_deregister_client(link->handle); - if (ret != CS_SUCCESS) - cs_error(link->handle, DeregisterClient, ret); - } - /* Unlink device structure, free bits */ *linkp = link->next; @@ -837,16 +831,8 @@ static int btuart_resume(struct pcmcia_device *dev) static int btuart_event(event_t event, int priority, event_callback_args_t *args) { dev_link_t *link = args->client_data; - btuart_info_t *info = link->priv; switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) { - btuart_close(info); - btuart_release(link); - } - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; btuart_config(link); @@ -869,7 +855,7 @@ static struct pcmcia_driver btuart_driver = { }, .attach = btuart_attach, .event = btuart_event, - .detach = btuart_detach, + .remove = btuart_detach, .id_table = btuart_ids, .suspend = btuart_suspend, .resume = btuart_resume, diff --git a/drivers/bluetooth/dtl1_cs.c b/drivers/bluetooth/dtl1_cs.c index 9f9d3f91f455..2874d8722be9 100644 --- a/drivers/bluetooth/dtl1_cs.c +++ b/drivers/bluetooth/dtl1_cs.c @@ -94,7 +94,7 @@ static int dtl1_event(event_t event, int priority, event_callback_args_t *args); static dev_info_t dev_info = "dtl1_cs"; static dev_link_t *dtl1_attach(void); -static void dtl1_detach(dev_link_t *); +static void dtl1_detach(struct pcmcia_device *p_dev); static dev_link_t *dev_list = NULL; @@ -598,7 +598,7 @@ static dev_link_t *dtl1_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != CS_SUCCESS) { cs_error(link->handle, RegisterClient, ret); - dtl1_detach(link); + dtl1_detach(link->handle); return NULL; } @@ -606,11 +606,11 @@ static dev_link_t *dtl1_attach(void) } -static void dtl1_detach(dev_link_t *link) +static void dtl1_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); dtl1_info_t *info = link->priv; dev_link_t **linkp; - int ret; /* Locate device structure */ for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) @@ -623,12 +623,6 @@ static void dtl1_detach(dev_link_t *link) if (link->state & DEV_CONFIG) dtl1_release(link); - if (link->handle) { - ret = pcmcia_deregister_client(link->handle); - if (ret != CS_SUCCESS) - cs_error(link->handle, DeregisterClient, ret); - } - /* Unlink device structure, free bits */ *linkp = link->next; @@ -788,16 +782,8 @@ static int dtl1_resume(struct pcmcia_device *dev) static int dtl1_event(event_t event, int priority, event_callback_args_t *args) { dev_link_t *link = args->client_data; - dtl1_info_t *info = link->priv; switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) { - dtl1_close(info); - dtl1_release(link); - } - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; dtl1_config(link); @@ -821,7 +807,7 @@ static struct pcmcia_driver dtl1_driver = { }, .attach = dtl1_attach, .event = dtl1_event, - .detach = dtl1_detach, + .remove = dtl1_detach, .id_table = dtl1_ids, .suspend = dtl1_suspend, .resume = dtl1_resume, diff --git a/drivers/char/pcmcia/cm4000_cs.c b/drivers/char/pcmcia/cm4000_cs.c index 05e93054c98c..8a064f2f005d 100644 --- a/drivers/char/pcmcia/cm4000_cs.c +++ b/drivers/char/pcmcia/cm4000_cs.c @@ -66,7 +66,7 @@ static char *version = "cm4000_cs.c v2.4.0gm5 - All bugs added by Harald Welte"; #define T_100MSEC msecs_to_jiffies(100) #define T_500MSEC msecs_to_jiffies(500) -static void cm4000_detach(dev_link_t *link); +static void cm4000_detach(struct pcmcia_device *p_dev); static void cm4000_release(dev_link_t *link); static int major; /* major number we get from the kernel */ @@ -1888,11 +1888,6 @@ static int cm4000_event(event_t event, int priority, link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; cm4000_config(link, devno); break; - case CS_EVENT_CARD_REMOVAL: - DEBUGP(5, dev, "CS_EVENT_CARD_REMOVAL\n"); - link->state &= ~DEV_PRESENT; - stop_monitor(dev); - break; default: DEBUGP(5, dev, "unknown event %.2x\n", event); break; @@ -1978,7 +1973,7 @@ static dev_link_t *cm4000_attach(void) i = pcmcia_register_client(&link->handle, &client_reg); if (i) { cs_error(link->handle, RegisterClient, i); - cm4000_detach(link); + cm4000_detach(link->handle); return NULL; } @@ -1990,39 +1985,28 @@ static dev_link_t *cm4000_attach(void) return link; } -static void cm4000_detach_by_devno(int devno, dev_link_t * link) +static void cm4000_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); struct cm4000_dev *dev = link->priv; - - DEBUGP(3, dev, "-> detach_by_devno(devno=%d)\n", devno); - - if (link->state & DEV_CONFIG) { - DEBUGP(5, dev, "device still configured (try to release it)\n"); - cm4000_release(link); - } - - if (link->handle) { - pcmcia_deregister_client(link->handle); - } - - dev_table[devno] = NULL; - kfree(dev); - return; -} - -static void cm4000_detach(dev_link_t * link) -{ - int i; + int devno; /* find device */ - for (i = 0; i < CM4000_MAX_DEV; i++) - if (dev_table[i] == link) + for (devno = 0; devno < CM4000_MAX_DEV; devno++) + if (dev_table[devno] == link) break; - - if (i == CM4000_MAX_DEV) + if (devno == CM4000_MAX_DEV) return; - cm4000_detach_by_devno(i, link); + link->state &= ~DEV_PRESENT; + stop_monitor(dev); + + if (link->state & DEV_CONFIG) + cm4000_release(link); + + dev_table[devno] = NULL; + kfree(dev); + return; } @@ -2048,7 +2032,7 @@ static struct pcmcia_driver cm4000_driver = { .name = "cm4000_cs", }, .attach = cm4000_attach, - .detach = cm4000_detach, + .remove = cm4000_detach, .suspend = cm4000_suspend, .resume = cm4000_resume, .event = cm4000_event, @@ -2071,13 +2055,8 @@ static int __init cmm_init(void) static void __exit cmm_exit(void) { - int i; - printk(KERN_INFO MODULE_NAME ": unloading\n"); pcmcia_unregister_driver(&cm4000_driver); - for (i = 0; i < CM4000_MAX_DEV; i++) - if (dev_table[i]) - cm4000_detach_by_devno(i, dev_table[i]); unregister_chrdev(major, DEVICE_NAME); }; diff --git a/drivers/char/pcmcia/cm4040_cs.c b/drivers/char/pcmcia/cm4040_cs.c index 3622fd39c47b..e08ab949c116 100644 --- a/drivers/char/pcmcia/cm4040_cs.c +++ b/drivers/char/pcmcia/cm4040_cs.c @@ -65,7 +65,7 @@ static char *version = #define POLL_PERIOD msecs_to_jiffies(10) static void reader_release(dev_link_t *link); -static void reader_detach(dev_link_t *link); +static void reader_detach(struct pcmcia_device *p_dev); static int major; @@ -652,10 +652,6 @@ static int reader_event(event_t event, int priority, link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; reader_config(link, devno); break; - case CS_EVENT_CARD_REMOVAL: - DEBUGP(5, dev, "CS_EVENT_CARD_REMOVAL\n"); - link->state &= ~DEV_PRESENT; - break; default: DEBUGP(5, dev, "reader_event: unknown event %.2x\n", @@ -734,7 +730,7 @@ static dev_link_t *reader_attach(void) i = pcmcia_register_client(&link->handle, &client_reg); if (i) { cs_error(link->handle, RegisterClient, i); - reader_detach(link); + reader_detach(link->handle); return NULL; } init_waitqueue_head(&dev->devq); @@ -747,36 +743,28 @@ static dev_link_t *reader_attach(void) return link; } -static void reader_detach_by_devno(int devno, dev_link_t *link) +static void reader_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); struct reader_dev *dev = link->priv; - - if (link->state & DEV_CONFIG) { - DEBUGP(5, dev, "device still configured (try to release it)\n"); - reader_release(link); - } - - pcmcia_deregister_client(link->handle); - dev_table[devno] = NULL; - DEBUGP(5, dev, "freeing dev=%p\n", dev); - cm4040_stop_poll(dev); - kfree(dev); - return; -} - -static void reader_detach(dev_link_t *link) -{ - int i; + int devno; /* find device */ - for (i = 0; i < CM_MAX_DEV; i++) { - if (dev_table[i] == link) + for (devno = 0; devno < CM_MAX_DEV; devno++) { + if (dev_table[devno] == link) break; } - if (i == CM_MAX_DEV) + if (devno == CM_MAX_DEV) return; - reader_detach_by_devno(i, link); + link->state &= ~DEV_PRESENT; + + if (link->state & DEV_CONFIG) + reader_release(link); + + dev_table[devno] = NULL; + kfree(dev); + return; } @@ -803,7 +791,7 @@ static struct pcmcia_driver reader_driver = { .name = "cm4040_cs", }, .attach = reader_attach, - .detach = reader_detach, + .remove = reader_detach, .suspend = reader_suspend, .resume = reader_resume, .event = reader_event, @@ -825,14 +813,8 @@ static int __init cm4040_init(void) static void __exit cm4040_exit(void) { - int i; - printk(KERN_INFO MODULE_NAME ": unloading\n"); pcmcia_unregister_driver(&reader_driver); - for (i = 0; i < CM_MAX_DEV; i++) { - if (dev_table[i]) - reader_detach_by_devno(i, dev_table[i]); - } unregister_chrdev(major, DEVICE_NAME); } diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c index 776103e56042..34597144d9c1 100644 --- a/drivers/char/pcmcia/synclink_cs.c +++ b/drivers/char/pcmcia/synclink_cs.c @@ -489,7 +489,7 @@ static void mgslpc_release(u_long arg); static int mgslpc_event(event_t event, int priority, event_callback_args_t *args); static dev_link_t *mgslpc_attach(void); -static void mgslpc_detach(dev_link_t *); +static void mgslpc_detach(struct pcmcia_device *p_dev); static dev_info_t dev_info = "synclink_cs"; static dev_link_t *dev_list = NULL; @@ -598,7 +598,7 @@ static dev_link_t *mgslpc_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != CS_SUCCESS) { cs_error(link->handle, RegisterClient, ret); - mgslpc_detach(link); + mgslpc_detach(link->handle); return NULL; } @@ -736,17 +736,16 @@ static void mgslpc_release(u_long arg) pcmcia_release_io(link->handle, &link->io); if (link->irq.AssignedIRQ) pcmcia_release_irq(link->handle, &link->irq); - if (link->state & DEV_STALE_LINK) - mgslpc_detach(link); } -static void mgslpc_detach(dev_link_t *link) +static void mgslpc_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); dev_link_t **linkp; if (debug_level >= DEBUG_LEVEL_INFO) printk("mgslpc_detach(0x%p)\n", link); - + /* find device */ for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) if (*linkp == link) break; @@ -754,20 +753,10 @@ static void mgslpc_detach(dev_link_t *link) return; if (link->state & DEV_CONFIG) { - /* device is configured/active, mark it so when - * release() is called a proper detach() occurs. - */ - if (debug_level >= DEBUG_LEVEL_INFO) - printk(KERN_DEBUG "synclinkpc: detach postponed, '%s' " - "still locked\n", link->dev->dev_name); - link->state |= DEV_STALE_LINK; - return; + ((MGSLPC_INFO *)link->priv)->stop = 1; + mgslpc_release((u_long)link); } - /* Break the link with Card Services */ - if (link->handle) - pcmcia_deregister_client(link->handle); - /* Unlink device structure, and free it */ *linkp = link->next; mgslpc_remove_device((MGSLPC_INFO *)link->priv); @@ -809,13 +798,6 @@ static int mgslpc_event(event_t event, int priority, printk("mgslpc_event(0x%06x)\n", event); switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) { - ((MGSLPC_INFO *)link->priv)->stop = 1; - mgslpc_release((u_long)link); - } - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; mgslpc_config(link); @@ -3102,7 +3084,7 @@ static struct pcmcia_driver mgslpc_driver = { }, .attach = mgslpc_attach, .event = mgslpc_event, - .detach = mgslpc_detach, + .remove = mgslpc_detach, .id_table = mgslpc_ids, .suspend = mgslpc_suspend, .resume = mgslpc_resume, diff --git a/drivers/ide/legacy/ide-cs.c b/drivers/ide/legacy/ide-cs.c index 982b74af8c29..1fb8976496d9 100644 --- a/drivers/ide/legacy/ide-cs.c +++ b/drivers/ide/legacy/ide-cs.c @@ -94,7 +94,7 @@ static int ide_event(event_t event, int priority, static dev_info_t dev_info = "ide-cs"; static dev_link_t *ide_attach(void); -static void ide_detach(dev_link_t *); +static void ide_detach(struct pcmcia_device *p_dev); static dev_link_t *dev_list = NULL; @@ -138,7 +138,7 @@ static dev_link_t *ide_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != CS_SUCCESS) { cs_error(link->handle, RegisterClient, ret); - ide_detach(link); + ide_detach(link->handle); return NULL; } @@ -154,10 +154,10 @@ static dev_link_t *ide_attach(void) ======================================================================*/ -static void ide_detach(dev_link_t *link) +static void ide_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); dev_link_t **linkp; - int ret; DEBUG(0, "ide_detach(0x%p)\n", link); @@ -170,12 +170,6 @@ static void ide_detach(dev_link_t *link) if (link->state & DEV_CONFIG) ide_release(link); - if (link->handle) { - ret = pcmcia_deregister_client(link->handle); - if (ret != CS_SUCCESS) - cs_error(link->handle, DeregisterClient, ret); - } - /* Unlink, free device structure */ *linkp = link->next; kfree(link->priv); @@ -445,11 +439,6 @@ int ide_event(event_t event, int priority, DEBUG(1, "ide_event(0x%06x)\n", event); switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) - ide_release(link); - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; ide_config(link); @@ -504,7 +493,7 @@ static struct pcmcia_driver ide_cs_driver = { }, .attach = ide_attach, .event = ide_event, - .detach = ide_detach, + .remove = ide_detach, .id_table = ide_ids, .suspend = ide_suspend, .resume = ide_resume, diff --git a/drivers/isdn/hardware/avm/avm_cs.c b/drivers/isdn/hardware/avm/avm_cs.c index 6d9816e10ecb..2d898d3afc97 100644 --- a/drivers/isdn/hardware/avm/avm_cs.c +++ b/drivers/isdn/hardware/avm/avm_cs.c @@ -63,7 +63,7 @@ static int avmcs_event(event_t event, int priority, */ static dev_link_t *avmcs_attach(void); -static void avmcs_detach(dev_link_t *); +static void avmcs_detach(struct pcmcia_device *p_dev); /* The dev_info variable is the "key" that is used to match up this @@ -165,7 +165,7 @@ static dev_link_t *avmcs_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != 0) { cs_error(link->handle, RegisterClient, ret); - avmcs_detach(link); + avmcs_detach(link->handle); goto err; } return link; @@ -185,8 +185,9 @@ static dev_link_t *avmcs_attach(void) ======================================================================*/ -static void avmcs_detach(dev_link_t *link) +static void avmcs_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); dev_link_t **linkp; /* Locate device structure */ @@ -195,21 +196,9 @@ static void avmcs_detach(dev_link_t *link) if (*linkp == NULL) return; - /* - If the device is currently configured and active, we won't - actually delete it yet. Instead, it is marked so that when - the release() function is called, that will trigger a proper - detach(). - */ - if (link->state & DEV_CONFIG) { - link->state |= DEV_STALE_LINK; - return; - } + if (link->state & DEV_CONFIG) + avmcs_release(link); - /* Break the link with Card Services */ - if (link->handle) - pcmcia_deregister_client(link->handle); - /* Unlink device structure, free pieces */ *linkp = link->next; kfree(link->priv); @@ -424,10 +413,6 @@ static void avmcs_release(dev_link_t *link) pcmcia_release_io(link->handle, &link->io); pcmcia_release_irq(link->handle, &link->irq); link->state &= ~DEV_CONFIG; - - if (link->state & DEV_STALE_LINK) - avmcs_detach(link); - } /* avmcs_release */ static int avmcs_suspend(struct pcmcia_device *dev) @@ -472,11 +457,6 @@ static int avmcs_event(event_t event, int priority, dev_link_t *link = args->client_data; switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) - avmcs_release(link); - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; avmcs_config(link); @@ -500,7 +480,7 @@ static struct pcmcia_driver avmcs_driver = { }, .attach = avmcs_attach, .event = avmcs_event, - .detach = avmcs_detach, + .remove = avmcs_detach, .id_table = avmcs_ids, .suspend= avmcs_suspend, .resume = avmcs_resume, diff --git a/drivers/isdn/hisax/avma1_cs.c b/drivers/isdn/hisax/avma1_cs.c index 433cec4269a3..6b322e88c6c3 100644 --- a/drivers/isdn/hisax/avma1_cs.c +++ b/drivers/isdn/hisax/avma1_cs.c @@ -79,7 +79,7 @@ static int avma1cs_event(event_t event, int priority, */ static dev_link_t *avma1cs_attach(void); -static void avma1cs_detach(dev_link_t *); +static void avma1cs_detach(struct pcmcia_device *p_dev); /* The dev_info variable is the "key" that is used to match up this @@ -187,7 +187,7 @@ static dev_link_t *avma1cs_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != 0) { cs_error(link->handle, RegisterClient, ret); - avma1cs_detach(link); + avma1cs_detach(link->handle); return NULL; } @@ -203,42 +203,26 @@ static dev_link_t *avma1cs_attach(void) ======================================================================*/ -static void avma1cs_detach(dev_link_t *link) +static void avma1cs_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); dev_link_t **linkp; DEBUG(0, "avma1cs_detach(0x%p)\n", link); - + /* Locate device structure */ for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) if (*linkp == link) break; if (*linkp == NULL) return; - /* - If the device is currently configured and active, we won't - actually delete it yet. Instead, it is marked so that when - the release() function is called, that will trigger a proper - detach(). - */ - if (link->state & DEV_CONFIG) { -#ifdef PCMCIA_DEBUG - printk(KERN_DEBUG "avma1_cs: detach postponed, '%s' " - "still locked\n", link->dev->dev_name); -#endif - link->state |= DEV_STALE_LINK; - return; - } + if (link->state & DEV_CONFIG) + avma1cs_release(link); - /* Break the link with Card Services */ - if (link->handle) - pcmcia_deregister_client(link->handle); - /* Unlink device structure, free pieces */ *linkp = link->next; kfree(link->priv); kfree(link); - } /* avma1cs_detach */ /*====================================================================== @@ -440,9 +424,6 @@ static void avma1cs_release(dev_link_t *link) pcmcia_release_io(link->handle, &link->io); pcmcia_release_irq(link->handle, &link->irq); link->state &= ~DEV_CONFIG; - - if (link->state & DEV_STALE_LINK) - avma1cs_detach(link); } /* avma1cs_release */ static int avma1cs_suspend(struct pcmcia_device *dev) @@ -489,10 +470,6 @@ static int avma1cs_event(event_t event, int priority, DEBUG(1, "avma1cs_event(0x%06x)\n", event); switch (event) { - case CS_EVENT_CARD_REMOVAL: - if (link->state & DEV_CONFIG) - avma1cs_release(link); - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; avma1cs_config(link); @@ -515,7 +492,7 @@ static struct pcmcia_driver avma1cs_driver = { }, .attach = avma1cs_attach, .event = avma1cs_event, - .detach = avma1cs_detach, + .remove = avma1cs_detach, .id_table = avma1cs_ids, .suspend = avma1cs_suspend, .resume = avma1cs_resume, diff --git a/drivers/isdn/hisax/elsa_cs.c b/drivers/isdn/hisax/elsa_cs.c index 0cbe04593d87..48cc677249f1 100644 --- a/drivers/isdn/hisax/elsa_cs.c +++ b/drivers/isdn/hisax/elsa_cs.c @@ -106,7 +106,7 @@ static int elsa_cs_event(event_t event, int priority, */ static dev_link_t *elsa_cs_attach(void); -static void elsa_cs_detach(dev_link_t *); +static void elsa_cs_detach(struct pcmcia_device *p_dev); /* The dev_info variable is the "key" that is used to match up this @@ -216,7 +216,7 @@ static dev_link_t *elsa_cs_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != CS_SUCCESS) { cs_error(link->handle, RegisterClient, ret); - elsa_cs_detach(link); + elsa_cs_detach(link->handle); return NULL; } @@ -232,11 +232,11 @@ static dev_link_t *elsa_cs_attach(void) ======================================================================*/ -static void elsa_cs_detach(dev_link_t *link) +static void elsa_cs_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); dev_link_t **linkp; local_info_t *info = link->priv; - int ret; DEBUG(0, "elsa_cs_detach(0x%p)\n", link); @@ -246,14 +246,9 @@ static void elsa_cs_detach(dev_link_t *link) if (*linkp == NULL) return; - if (link->state & DEV_CONFIG) + if (link->state & DEV_CONFIG) { + ((local_info_t*)link->priv)->busy = 1; elsa_cs_release(link); - - /* Break the link with Card Services */ - if (link->handle) { - ret = pcmcia_deregister_client(link->handle); - if (ret != CS_SUCCESS) - cs_error(link->handle, DeregisterClient, ret); } /* Unlink device structure and free it */ @@ -495,13 +490,6 @@ static int elsa_cs_event(event_t event, int priority, DEBUG(1, "elsa_cs_event(%d)\n", event); switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) { - ((local_info_t*)link->priv)->busy = 1; - elsa_cs_release(link); - } - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; elsa_cs_config(link); @@ -524,7 +512,7 @@ static struct pcmcia_driver elsa_cs_driver = { }, .attach = elsa_cs_attach, .event = elsa_cs_event, - .detach = elsa_cs_detach, + .remove = elsa_cs_detach, .id_table = elsa_ids, .suspend = elsa_suspend, .resume = elsa_resume, diff --git a/drivers/isdn/hisax/sedlbauer_cs.c b/drivers/isdn/hisax/sedlbauer_cs.c index 27dce7c7b760..d2386f6867b7 100644 --- a/drivers/isdn/hisax/sedlbauer_cs.c +++ b/drivers/isdn/hisax/sedlbauer_cs.c @@ -107,7 +107,7 @@ static int sedlbauer_event(event_t event, int priority, */ static dev_link_t *sedlbauer_attach(void); -static void sedlbauer_detach(dev_link_t *); +static void sedlbauer_detach(struct pcmcia_device *p_dev); /* You'll also need to prototype all the functions that will actually @@ -230,7 +230,7 @@ static dev_link_t *sedlbauer_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != CS_SUCCESS) { cs_error(link->handle, RegisterClient, ret); - sedlbauer_detach(link); + sedlbauer_detach(link->handle); return NULL; } @@ -246,8 +246,9 @@ static dev_link_t *sedlbauer_attach(void) ======================================================================*/ -static void sedlbauer_detach(dev_link_t *link) +static void sedlbauer_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); dev_link_t **linkp; DEBUG(0, "sedlbauer_detach(0x%p)\n", link); @@ -258,25 +259,11 @@ static void sedlbauer_detach(dev_link_t *link) if (*linkp == NULL) return; - /* - If the device is currently configured and active, we won't - actually delete it yet. Instead, it is marked so that when - the release() function is called, that will trigger a proper - detach(). - */ if (link->state & DEV_CONFIG) { -#ifdef PCMCIA_DEBUG - printk(KERN_DEBUG "sedlbauer_cs: detach postponed, '%s' " - "still locked\n", link->dev->dev_name); -#endif - link->state |= DEV_STALE_LINK; - return; + ((local_info_t *)link->priv)->stop = 1; + sedlbauer_release(link); } - /* Break the link with Card Services */ - if (link->handle) - pcmcia_deregister_client(link->handle); - /* Unlink device structure, and free it */ *linkp = link->next; /* This points to the parent local_info_t struct */ @@ -547,10 +534,6 @@ static void sedlbauer_release(dev_link_t *link) if (link->irq.AssignedIRQ) pcmcia_release_irq(link->handle, &link->irq); link->state &= ~DEV_CONFIG; - - if (link->state & DEV_STALE_LINK) - sedlbauer_detach(link); - } /* sedlbauer_release */ static int sedlbauer_suspend(struct pcmcia_device *p_dev) @@ -599,13 +582,6 @@ static int sedlbauer_event(event_t event, int priority, DEBUG(1, "sedlbauer_event(0x%06x)\n", event); switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) { - ((local_info_t *)link->priv)->stop = 1; - sedlbauer_release(link); - } - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; sedlbauer_config(link); @@ -633,7 +609,7 @@ static struct pcmcia_driver sedlbauer_driver = { }, .attach = sedlbauer_attach, .event = sedlbauer_event, - .detach = sedlbauer_detach, + .remove = sedlbauer_detach, .id_table = sedlbauer_ids, .suspend = sedlbauer_suspend, .resume = sedlbauer_resume, diff --git a/drivers/isdn/hisax/teles_cs.c b/drivers/isdn/hisax/teles_cs.c index 70213bc1d30c..cd0f86f0975b 100644 --- a/drivers/isdn/hisax/teles_cs.c +++ b/drivers/isdn/hisax/teles_cs.c @@ -87,7 +87,7 @@ static int teles_cs_event(event_t event, int priority, */ static dev_link_t *teles_attach(void); -static void teles_detach(dev_link_t *); +static void teles_detach(struct pcmcia_device *p_dev); /* The dev_info variable is the "key" that is used to match up this @@ -197,7 +197,7 @@ static dev_link_t *teles_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != CS_SUCCESS) { cs_error(link->handle, RegisterClient, ret); - teles_detach(link); + teles_detach(link->handle); return NULL; } @@ -213,11 +213,11 @@ static dev_link_t *teles_attach(void) ======================================================================*/ -static void teles_detach(dev_link_t *link) +static void teles_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); dev_link_t **linkp; local_info_t *info = link->priv; - int ret; DEBUG(0, "teles_detach(0x%p)\n", link); @@ -227,14 +227,9 @@ static void teles_detach(dev_link_t *link) if (*linkp == NULL) return; - if (link->state & DEV_CONFIG) + if (link->state & DEV_CONFIG) { + info->busy = 1; teles_cs_release(link); - - /* Break the link with Card Services */ - if (link->handle) { - ret = pcmcia_deregister_client(link->handle); - if (ret != CS_SUCCESS) - cs_error(link->handle, DeregisterClient, ret); } /* Unlink device structure and free it */ @@ -476,13 +471,6 @@ static int teles_cs_event(event_t event, int priority, DEBUG(1, "teles_cs_event(%d)\n", event); switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) { - ((local_info_t*)link->priv)->busy = 1; - teles_cs_release(link); - } - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; teles_cs_config(link); @@ -504,7 +492,7 @@ static struct pcmcia_driver teles_cs_driver = { }, .attach = teles_attach, .event = teles_cs_event, - .detach = teles_detach, + .remove = teles_detach, .id_table = teles_ids, .suspend = teles_suspend, .resume = teles_resume, diff --git a/drivers/mtd/maps/pcmciamtd.c b/drivers/mtd/maps/pcmciamtd.c index 86443cf44dc6..3ddcb1bf6824 100644 --- a/drivers/mtd/maps/pcmciamtd.c +++ b/drivers/mtd/maps/pcmciamtd.c @@ -722,18 +722,6 @@ static int pcmciamtd_event(event_t event, int priority, DEBUG(1, "event=0x%06x", event); switch (event) { - case CS_EVENT_CARD_REMOVAL: - DEBUG(2, "EVENT_CARD_REMOVAL"); - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) { - struct pcmciamtd_dev *dev = link->priv; - if(dev->mtd_info) { - del_mtd_device(dev->mtd_info); - info("mtd%d: Removed", dev->mtd_info->index); - } - pcmciamtd_release(link); - } - break; case CS_EVENT_CARD_INSERTION: DEBUG(2, "EVENT_CARD_INSERTION"); link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; @@ -752,23 +740,21 @@ static int pcmciamtd_event(event_t event, int priority, * when the device is released. */ -static void pcmciamtd_detach(dev_link_t *link) +static void pcmciamtd_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); + DEBUG(3, "link=0x%p", link); if(link->state & DEV_CONFIG) { + struct pcmciamtd_dev *dev = link->priv; + if(dev->mtd_info) { + del_mtd_device(dev->mtd_info); + info("mtd%d: Removed", dev->mtd_info->index); + } + pcmciamtd_release(link); } - - if (link->handle) { - int ret; - DEBUG(2, "Deregistering with card services"); - ret = pcmcia_deregister_client(link->handle); - if (ret != CS_SUCCESS) - cs_error(link->handle, DeregisterClient, ret); - } - - link->state |= DEV_STALE_LINK; } @@ -807,7 +793,7 @@ static dev_link_t *pcmciamtd_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != 0) { cs_error(link->handle, RegisterClient, ret); - pcmciamtd_detach(link); + pcmciamtd_detach(link->handle); return NULL; } DEBUG(2, "link = %p", link); @@ -847,7 +833,7 @@ static struct pcmcia_driver pcmciamtd_driver = { }, .attach = pcmciamtd_attach, .event = pcmciamtd_event, - .detach = pcmciamtd_detach, + .remove = pcmciamtd_detach, .owner = THIS_MODULE, .id_table = pcmciamtd_ids, .suspend = pcmciamtd_suspend, diff --git a/drivers/net/pcmcia/3c574_cs.c b/drivers/net/pcmcia/3c574_cs.c index 80414a77fe75..60a3bc2b8fc4 100644 --- a/drivers/net/pcmcia/3c574_cs.c +++ b/drivers/net/pcmcia/3c574_cs.c @@ -253,7 +253,7 @@ static void set_rx_mode(struct net_device *dev); static dev_info_t dev_info = "3c574_cs"; static dev_link_t *tc574_attach(void); -static void tc574_detach(dev_link_t *); +static void tc574_detach(struct pcmcia_device *p_dev); static dev_link_t *dev_list; @@ -316,7 +316,7 @@ static dev_link_t *tc574_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != 0) { cs_error(link->handle, RegisterClient, ret); - tc574_detach(link); + tc574_detach(link->handle); return NULL; } @@ -332,8 +332,9 @@ static dev_link_t *tc574_attach(void) */ -static void tc574_detach(dev_link_t *link) +static void tc574_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); struct net_device *dev = link->priv; dev_link_t **linkp; @@ -351,9 +352,6 @@ static void tc574_detach(dev_link_t *link) if (link->state & DEV_CONFIG) tc574_release(link); - if (link->handle) - pcmcia_deregister_client(link->handle); - /* Unlink device structure, free bits */ *linkp = link->next; free_netdev(dev); @@ -590,16 +588,10 @@ static int tc574_event(event_t event, int priority, event_callback_args_t *args) { dev_link_t *link = args->client_data; - struct net_device *dev = link->priv; DEBUG(1, "3c574_event(0x%06x)\n", event); switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) - netif_device_detach(dev); - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; tc574_config(link); @@ -1304,7 +1296,7 @@ static struct pcmcia_driver tc574_driver = { }, .attach = tc574_attach, .event = tc574_event, - .detach = tc574_detach, + .remove = tc574_detach, .id_table = tc574_ids, .suspend = tc574_suspend, .resume = tc574_resume, diff --git a/drivers/net/pcmcia/3c589_cs.c b/drivers/net/pcmcia/3c589_cs.c index bbda681ac102..09b96c76216e 100644 --- a/drivers/net/pcmcia/3c589_cs.c +++ b/drivers/net/pcmcia/3c589_cs.c @@ -164,7 +164,7 @@ static struct ethtool_ops netdev_ethtool_ops; static dev_info_t dev_info = "3c589_cs"; static dev_link_t *tc589_attach(void); -static void tc589_detach(dev_link_t *); +static void tc589_detach(struct pcmcia_device *p_dev); static dev_link_t *dev_list; @@ -230,7 +230,7 @@ static dev_link_t *tc589_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != 0) { cs_error(link->handle, RegisterClient, ret); - tc589_detach(link); + tc589_detach(link->handle); return NULL; } @@ -246,8 +246,9 @@ static dev_link_t *tc589_attach(void) ======================================================================*/ -static void tc589_detach(dev_link_t *link) +static void tc589_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); struct net_device *dev = link->priv; dev_link_t **linkp; @@ -264,10 +265,7 @@ static void tc589_detach(dev_link_t *link) if (link->state & DEV_CONFIG) tc589_release(link); - - if (link->handle) - pcmcia_deregister_client(link->handle); - + /* Unlink device structure, free bits */ *linkp = link->next; free_netdev(dev); @@ -466,16 +464,10 @@ static int tc589_event(event_t event, int priority, event_callback_args_t *args) { dev_link_t *link = args->client_data; - struct net_device *dev = link->priv; DEBUG(1, "3c589_event(0x%06x)\n", event); switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) - netif_device_detach(dev); - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; tc589_config(link); @@ -1079,7 +1071,7 @@ static struct pcmcia_driver tc589_driver = { }, .attach = tc589_attach, .event = tc589_event, - .detach = tc589_detach, + .remove = tc589_detach, .id_table = tc589_ids, .suspend = tc589_suspend, .resume = tc589_resume, diff --git a/drivers/net/pcmcia/axnet_cs.c b/drivers/net/pcmcia/axnet_cs.c index 6c6b25265659..11f701a8ff02 100644 --- a/drivers/net/pcmcia/axnet_cs.c +++ b/drivers/net/pcmcia/axnet_cs.c @@ -108,7 +108,7 @@ static void block_output(struct net_device *dev, int count, const u_char *buf, const int start_page); static dev_link_t *axnet_attach(void); -static void axnet_detach(dev_link_t *); +static void axnet_detach(struct pcmcia_device *p_dev); static dev_info_t dev_info = "axnet_cs"; static dev_link_t *dev_list; @@ -185,7 +185,7 @@ static dev_link_t *axnet_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != CS_SUCCESS) { cs_error(link->handle, RegisterClient, ret); - axnet_detach(link); + axnet_detach(link->handle); return NULL; } @@ -201,8 +201,9 @@ static dev_link_t *axnet_attach(void) ======================================================================*/ -static void axnet_detach(dev_link_t *link) +static void axnet_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); struct net_device *dev = link->priv; dev_link_t **linkp; @@ -220,9 +221,6 @@ static void axnet_detach(dev_link_t *link) if (link->state & DEV_CONFIG) axnet_release(link); - if (link->handle) - pcmcia_deregister_client(link->handle); - /* Unlink device structure, free bits */ *linkp = link->next; free_netdev(dev); @@ -537,16 +535,10 @@ static int axnet_event(event_t event, int priority, event_callback_args_t *args) { dev_link_t *link = args->client_data; - struct net_device *dev = link->priv; DEBUG(2, "axnet_event(0x%06x)\n", event); switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) - netif_device_detach(dev); - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; axnet_config(link); @@ -890,7 +882,7 @@ static struct pcmcia_driver axnet_cs_driver = { }, .attach = axnet_attach, .event = axnet_event, - .detach = axnet_detach, + .remove = axnet_detach, .id_table = axnet_ids, .suspend = axnet_suspend, .resume = axnet_resume, diff --git a/drivers/net/pcmcia/com20020_cs.c b/drivers/net/pcmcia/com20020_cs.c index 68612222de6e..6970888cba10 100644 --- a/drivers/net/pcmcia/com20020_cs.c +++ b/drivers/net/pcmcia/com20020_cs.c @@ -126,7 +126,7 @@ static int com20020_event(event_t event, int priority, static dev_info_t dev_info = "com20020_cs"; static dev_link_t *com20020_attach(void); -static void com20020_detach(dev_link_t *); +static void com20020_detach(struct pcmcia_device *p_dev); static dev_link_t *dev_list; @@ -204,7 +204,7 @@ static dev_link_t *com20020_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != 0) { cs_error(link->handle, RegisterClient, ret); - com20020_detach(link); + com20020_detach(link->handle); return NULL; } @@ -226,8 +226,9 @@ fail_alloc_info: ======================================================================*/ -static void com20020_detach(dev_link_t *link) +static void com20020_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); struct com20020_dev_t *info = link->priv; dev_link_t **linkp; struct net_device *dev; @@ -260,9 +261,6 @@ static void com20020_detach(dev_link_t *link) if (link->state & DEV_CONFIG) com20020_release(link); - if (link->handle) - pcmcia_deregister_client(link->handle); - /* Unlink device structure, free bits */ DEBUG(1,"unlinking...\n"); *linkp = link->next; @@ -470,17 +468,10 @@ static int com20020_event(event_t event, int priority, event_callback_args_t *args) { dev_link_t *link = args->client_data; - com20020_dev_t *info = link->priv; - struct net_device *dev = info->dev; DEBUG(1, "com20020_event(0x%06x)\n", event); switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) - netif_device_detach(dev); - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT; com20020_config(link); @@ -502,7 +493,7 @@ static struct pcmcia_driver com20020_cs_driver = { }, .attach = com20020_attach, .event = com20020_event, - .detach = com20020_detach, + .remove = com20020_detach, .id_table = com20020_ids, .suspend = com20020_suspend, .resume = com20020_resume, diff --git a/drivers/net/pcmcia/fmvj18x_cs.c b/drivers/net/pcmcia/fmvj18x_cs.c index 388ecade13de..560d4ee22803 100644 --- a/drivers/net/pcmcia/fmvj18x_cs.c +++ b/drivers/net/pcmcia/fmvj18x_cs.c @@ -91,7 +91,7 @@ static void fmvj18x_release(dev_link_t *link); static int fmvj18x_event(event_t event, int priority, event_callback_args_t *args); static dev_link_t *fmvj18x_attach(void); -static void fmvj18x_detach(dev_link_t *); +static void fmvj18x_detach(struct pcmcia_device *p_dev); /* LAN controller(MBH86960A) specific routines @@ -291,7 +291,7 @@ static dev_link_t *fmvj18x_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != 0) { cs_error(link->handle, RegisterClient, ret); - fmvj18x_detach(link); + fmvj18x_detach(link->handle); return NULL; } @@ -300,8 +300,9 @@ static dev_link_t *fmvj18x_attach(void) /*====================================================================*/ -static void fmvj18x_detach(dev_link_t *link) +static void fmvj18x_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); struct net_device *dev = link->priv; dev_link_t **linkp; @@ -319,10 +320,6 @@ static void fmvj18x_detach(dev_link_t *link) if (link->state & DEV_CONFIG) fmvj18x_release(link); - /* Break the link with Card Services */ - if (link->handle) - pcmcia_deregister_client(link->handle); - /* Unlink device structure, free pieces */ *linkp = link->next; free_netdev(dev); @@ -752,16 +749,10 @@ static int fmvj18x_event(event_t event, int priority, event_callback_args_t *args) { dev_link_t *link = args->client_data; - struct net_device *dev = link->priv; DEBUG(1, "fmvj18x_event(0x%06x)\n", event); switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) - netif_device_detach(dev); - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; fmvj18x_config(link); @@ -802,7 +793,7 @@ static struct pcmcia_driver fmvj18x_cs_driver = { }, .attach = fmvj18x_attach, .event = fmvj18x_event, - .detach = fmvj18x_detach, + .remove = fmvj18x_detach, .id_table = fmvj18x_ids, .suspend = fmvj18x_suspend, .resume = fmvj18x_resume, diff --git a/drivers/net/pcmcia/ibmtr_cs.c b/drivers/net/pcmcia/ibmtr_cs.c index 3a7218e51b73..961294983354 100644 --- a/drivers/net/pcmcia/ibmtr_cs.c +++ b/drivers/net/pcmcia/ibmtr_cs.c @@ -114,7 +114,7 @@ static int ibmtr_event(event_t event, int priority, static dev_info_t dev_info = "ibmtr_cs"; static dev_link_t *ibmtr_attach(void); -static void ibmtr_detach(dev_link_t *); +static void ibmtr_detach(struct pcmcia_device *p_dev); static dev_link_t *dev_list; @@ -201,7 +201,7 @@ out: return link; out_detach: - ibmtr_detach(link); + ibmtr_detach(link->handle); link = NULL; goto out; } /* ibmtr_attach */ @@ -215,8 +215,9 @@ out_detach: ======================================================================*/ -static void ibmtr_detach(dev_link_t *link) +static void ibmtr_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); struct ibmtr_dev_t *info = link->priv; dev_link_t **linkp; struct net_device *dev; @@ -241,9 +242,6 @@ static void ibmtr_detach(dev_link_t *link) if (link->state & DEV_CONFIG) ibmtr_release(link); - if (link->handle) - pcmcia_deregister_client(link->handle); - /* Unlink device structure, free bits */ *linkp = link->next; free_netdev(dev); @@ -449,21 +447,10 @@ static int ibmtr_event(event_t event, int priority, event_callback_args_t *args) { dev_link_t *link = args->client_data; - ibmtr_dev_t *info = link->priv; - struct net_device *dev = info->dev; DEBUG(1, "ibmtr_event(0x%06x)\n", event); switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) { - /* set flag to bypass normal interrupt code */ - struct tok_info *priv = netdev_priv(dev); - priv->sram_phys |= 1; - netif_device_detach(dev); - } - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT; ibmtr_config(link); @@ -529,7 +516,7 @@ static struct pcmcia_driver ibmtr_cs_driver = { }, .attach = ibmtr_attach, .event = ibmtr_event, - .detach = ibmtr_detach, + .remove = ibmtr_detach, .id_table = ibmtr_ids, .suspend = ibmtr_suspend, .resume = ibmtr_resume, diff --git a/drivers/net/pcmcia/nmclan_cs.c b/drivers/net/pcmcia/nmclan_cs.c index fa4921f8b9fc..011ceb090320 100644 --- a/drivers/net/pcmcia/nmclan_cs.c +++ b/drivers/net/pcmcia/nmclan_cs.c @@ -440,7 +440,7 @@ static struct ethtool_ops netdev_ethtool_ops; static dev_link_t *nmclan_attach(void); -static void nmclan_detach(dev_link_t *); +static void nmclan_detach(struct pcmcia_device *p_dev); /* ---------------------------------------------------------------------------- nmclan_attach @@ -506,7 +506,7 @@ static dev_link_t *nmclan_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != 0) { cs_error(link->handle, RegisterClient, ret); - nmclan_detach(link); + nmclan_detach(link->handle); return NULL; } @@ -521,8 +521,9 @@ nmclan_detach when the device is released. ---------------------------------------------------------------------------- */ -static void nmclan_detach(dev_link_t *link) +static void nmclan_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); struct net_device *dev = link->priv; dev_link_t **linkp; @@ -540,9 +541,6 @@ static void nmclan_detach(dev_link_t *link) if (link->state & DEV_CONFIG) nmclan_release(link); - if (link->handle) - pcmcia_deregister_client(link->handle); - /* Unlink device structure, free bits */ *linkp = link->next; free_netdev(dev); @@ -845,16 +843,10 @@ static int nmclan_event(event_t event, int priority, event_callback_args_t *args) { dev_link_t *link = args->client_data; - struct net_device *dev = link->priv; DEBUG(1, "nmclan_event(0x%06x)\n", event); switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) - netif_device_detach(dev); - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; nmclan_config(link); @@ -1694,7 +1686,7 @@ static struct pcmcia_driver nmclan_cs_driver = { }, .attach = nmclan_attach, .event = nmclan_event, - .detach = nmclan_detach, + .remove = nmclan_detach, .id_table = nmclan_ids, .suspend = nmclan_suspend, .resume = nmclan_resume, diff --git a/drivers/net/pcmcia/pcnet_cs.c b/drivers/net/pcmcia/pcnet_cs.c index 7db4d6f3db45..fb3e411d6daf 100644 --- a/drivers/net/pcmcia/pcnet_cs.c +++ b/drivers/net/pcmcia/pcnet_cs.c @@ -121,7 +121,7 @@ static int setup_dma_config(dev_link_t *link, int start_pg, int stop_pg); static dev_link_t *pcnet_attach(void); -static void pcnet_detach(dev_link_t *); +static void pcnet_detach(struct pcmcia_device *p_dev); static dev_info_t dev_info = "pcnet_cs"; static dev_link_t *dev_list; @@ -280,7 +280,7 @@ static dev_link_t *pcnet_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != CS_SUCCESS) { cs_error(link->handle, RegisterClient, ret); - pcnet_detach(link); + pcnet_detach(link->handle); return NULL; } @@ -296,31 +296,29 @@ static dev_link_t *pcnet_attach(void) ======================================================================*/ -static void pcnet_detach(dev_link_t *link) +static void pcnet_detach(struct pcmcia_device *p_dev) { - struct net_device *dev = link->priv; - dev_link_t **linkp; + dev_link_t *link = dev_to_instance(p_dev); + struct net_device *dev = link->priv; + dev_link_t **linkp; - DEBUG(0, "pcnet_detach(0x%p)\n", link); + DEBUG(0, "pcnet_detach(0x%p)\n", link); - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) break; - if (*linkp == NULL) - return; + /* Locate device structure */ + for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) + if (*linkp == link) break; + if (*linkp == NULL) + return; - if (link->dev) - unregister_netdev(dev); + if (link->dev) + unregister_netdev(dev); - if (link->state & DEV_CONFIG) - pcnet_release(link); + if (link->state & DEV_CONFIG) + pcnet_release(link); - if (link->handle) - pcmcia_deregister_client(link->handle); - - /* Unlink device structure, free bits */ - *linkp = link->next; - free_netdev(dev); + /* Unlink device structure, free bits */ + *linkp = link->next; + free_netdev(dev); } /* pcnet_detach */ /*====================================================================== @@ -817,16 +815,10 @@ static int pcnet_event(event_t event, int priority, event_callback_args_t *args) { dev_link_t *link = args->client_data; - struct net_device *dev = link->priv; DEBUG(2, "pcnet_event(0x%06x)\n", event); switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) - netif_device_detach(dev); - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; pcnet_config(link); @@ -1856,7 +1848,7 @@ static struct pcmcia_driver pcnet_driver = { }, .attach = pcnet_attach, .event = pcnet_event, - .detach = pcnet_detach, + .remove = pcnet_detach, .owner = THIS_MODULE, .id_table = pcnet_ids, .suspend = pcnet_suspend, diff --git a/drivers/net/pcmcia/smc91c92_cs.c b/drivers/net/pcmcia/smc91c92_cs.c index 7c61ec90c2c3..6cb5198d6094 100644 --- a/drivers/net/pcmcia/smc91c92_cs.c +++ b/drivers/net/pcmcia/smc91c92_cs.c @@ -282,7 +282,7 @@ enum RxCfg { RxAllMulti = 0x0004, RxPromisc = 0x0002, /*====================================================================*/ static dev_link_t *smc91c92_attach(void); -static void smc91c92_detach(dev_link_t *); +static void smc91c92_detach(struct pcmcia_device *p_dev); static void smc91c92_config(dev_link_t *link); static void smc91c92_release(dev_link_t *link); static int smc91c92_event(event_t event, int priority, @@ -375,7 +375,7 @@ static dev_link_t *smc91c92_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != 0) { cs_error(link->handle, RegisterClient, ret); - smc91c92_detach(link); + smc91c92_detach(link->handle); return NULL; } @@ -391,8 +391,9 @@ static dev_link_t *smc91c92_attach(void) ======================================================================*/ -static void smc91c92_detach(dev_link_t *link) +static void smc91c92_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); struct net_device *dev = link->priv; dev_link_t **linkp; @@ -410,9 +411,6 @@ static void smc91c92_detach(dev_link_t *link) if (link->state & DEV_CONFIG) smc91c92_release(link); - if (link->handle) - pcmcia_deregister_client(link->handle); - /* Unlink device structure, free bits */ *linkp = link->next; free_netdev(dev); @@ -1237,16 +1235,10 @@ static int smc91c92_event(event_t event, int priority, event_callback_args_t *args) { dev_link_t *link = args->client_data; - struct net_device *dev = link->priv; DEBUG(1, "smc91c92_event(0x%06x)\n", event); switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) - netif_device_detach(dev); - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; smc91c92_config(link); @@ -2371,7 +2363,7 @@ static struct pcmcia_driver smc91c92_cs_driver = { }, .attach = smc91c92_attach, .event = smc91c92_event, - .detach = smc91c92_detach, + .remove = smc91c92_detach, .id_table = smc91c92_ids, .suspend = smc91c92_suspend, .resume = smc91c92_resume, diff --git a/drivers/net/pcmcia/xirc2ps_cs.c b/drivers/net/pcmcia/xirc2ps_cs.c index 917e50ac37f3..804e56771baf 100644 --- a/drivers/net/pcmcia/xirc2ps_cs.c +++ b/drivers/net/pcmcia/xirc2ps_cs.c @@ -302,7 +302,7 @@ static int xirc2ps_event(event_t event, int priority, */ static dev_link_t *xirc2ps_attach(void); -static void xirc2ps_detach(dev_link_t *); +static void xirc2ps_detach(struct pcmcia_device *p_dev); /**************** * You'll also need to prototype all the functions that will actually @@ -622,7 +622,7 @@ xirc2ps_attach(void) client_reg.event_callback_args.client_data = link; if ((err = pcmcia_register_client(&link->handle, &client_reg))) { cs_error(link->handle, RegisterClient, err); - xirc2ps_detach(link); + xirc2ps_detach(link->handle); return NULL; } @@ -637,8 +637,9 @@ xirc2ps_attach(void) */ static void -xirc2ps_detach(dev_link_t * link) +xirc2ps_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); struct net_device *dev = link->priv; dev_link_t **linkp; @@ -656,19 +657,9 @@ xirc2ps_detach(dev_link_t * link) if (link->dev) unregister_netdev(dev); - /* - * If the device is currently configured and active, we won't - * actually delete it yet. Instead, it is marked so that when - * the release() function is called, that will trigger a proper - * detach(). - */ if (link->state & DEV_CONFIG) xirc2ps_release(link); - /* Break the link with Card Services */ - if (link->handle) - pcmcia_deregister_client(link->handle); - /* Unlink device structure, free it */ *linkp = link->next; free_netdev(dev); @@ -1209,19 +1200,10 @@ xirc2ps_event(event_t event, int priority, event_callback_args_t * args) { dev_link_t *link = args->client_data; - struct net_device *dev = link->priv; DEBUG(0, "event(%d)\n", (int)event); switch (event) { - case CS_EVENT_REGISTRATION_COMPLETE: - DEBUG(0, "registration complete\n"); - break; - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) - netif_device_detach(dev); - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; xirc2ps_config(link); @@ -2022,7 +2004,7 @@ static struct pcmcia_driver xirc2ps_cs_driver = { }, .attach = xirc2ps_attach, .event = xirc2ps_event, - .detach = xirc2ps_detach, + .remove = xirc2ps_detach, .id_table = xirc2ps_ids, .suspend = xirc2ps_suspend, .resume = xirc2ps_resume, diff --git a/drivers/net/wireless/airo_cs.c b/drivers/net/wireless/airo_cs.c index 80c9de749b52..7a28139544c0 100644 --- a/drivers/net/wireless/airo_cs.c +++ b/drivers/net/wireless/airo_cs.c @@ -92,7 +92,7 @@ static int airo_event(event_t event, int priority, */ static dev_link_t *airo_attach(void); -static void airo_detach(dev_link_t *); +static void airo_detach(struct pcmcia_device *p_dev); /* You'll also need to prototype all the functions that will actually @@ -210,7 +210,7 @@ static dev_link_t *airo_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != 0) { cs_error(link->handle, RegisterClient, ret); - airo_detach(link); + airo_detach(link->handle); return NULL; } @@ -226,8 +226,9 @@ static dev_link_t *airo_attach(void) ======================================================================*/ -static void airo_detach(dev_link_t *link) +static void airo_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); dev_link_t **linkp; DEBUG(0, "airo_detach(0x%p)\n", link); @@ -244,14 +245,8 @@ static void airo_detach(dev_link_t *link) if ( ((local_info_t*)link->priv)->eth_dev ) { stop_airo_card( ((local_info_t*)link->priv)->eth_dev, 0 ); } - ((local_info_t*)link->priv)->eth_dev = NULL; - - /* Break the link with Card Services */ - if (link->handle) - pcmcia_deregister_client(link->handle); - - - + ((local_info_t*)link->priv)->eth_dev = NULL; + /* Unlink device structure, free pieces */ *linkp = link->next; kfree(link->priv); @@ -537,18 +532,10 @@ static int airo_event(event_t event, int priority, event_callback_args_t *args) { dev_link_t *link = args->client_data; - local_info_t *local = link->priv; - + DEBUG(1, "airo_event(0x%06x)\n", event); - + switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) { - netif_device_detach(local->eth_dev); - airo_release(link); - } - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; airo_config(link); @@ -573,7 +560,7 @@ static struct pcmcia_driver airo_driver = { }, .attach = airo_attach, .event = airo_event, - .detach = airo_detach, + .remove = airo_detach, .id_table = airo_ids, .suspend = airo_suspend, .resume = airo_resume, diff --git a/drivers/net/wireless/atmel_cs.c b/drivers/net/wireless/atmel_cs.c index 598a9cd0f83e..3ab33dd49ea2 100644 --- a/drivers/net/wireless/atmel_cs.c +++ b/drivers/net/wireless/atmel_cs.c @@ -103,7 +103,7 @@ static int atmel_event(event_t event, int priority, */ static dev_link_t *atmel_attach(void); -static void atmel_detach(dev_link_t *); +static void atmel_detach(struct pcmcia_device *p_dev); /* You'll also need to prototype all the functions that will actually @@ -221,7 +221,7 @@ static dev_link_t *atmel_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != 0) { cs_error(link->handle, RegisterClient, ret); - atmel_detach(link); + atmel_detach(link->handle); return NULL; } @@ -237,8 +237,9 @@ static dev_link_t *atmel_attach(void) ======================================================================*/ -static void atmel_detach(dev_link_t *link) +static void atmel_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); dev_link_t **linkp; DEBUG(0, "atmel_detach(0x%p)\n", link); @@ -252,10 +253,6 @@ static void atmel_detach(dev_link_t *link) if (link->state & DEV_CONFIG) atmel_release(link); - /* Break the link with Card Services */ - if (link->handle) - pcmcia_deregister_client(link->handle); - /* Unlink device structure, free pieces */ *linkp = link->next; kfree(link->priv); @@ -522,18 +519,10 @@ static int atmel_event(event_t event, int priority, event_callback_args_t *args) { dev_link_t *link = args->client_data; - local_info_t *local = link->priv; - + DEBUG(1, "atmel_event(0x%06x)\n", event); - + switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) { - netif_device_detach(local->eth_dev); - atmel_release(link); - } - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; atmel_config(link); @@ -593,7 +582,7 @@ static struct pcmcia_driver atmel_driver = { }, .attach = atmel_attach, .event = atmel_event, - .detach = atmel_detach, + .remove = atmel_detach, .id_table = atmel_ids, .suspend = atmel_suspend, .resume = atmel_resume, diff --git a/drivers/net/wireless/hostap/hostap_cs.c b/drivers/net/wireless/hostap/hostap_cs.c index ba4a7da98ccd..866142af7d92 100644 --- a/drivers/net/wireless/hostap/hostap_cs.c +++ b/drivers/net/wireless/hostap/hostap_cs.c @@ -203,7 +203,7 @@ static int hfa384x_to_bap(struct net_device *dev, u16 bap, void *buf, int len) -static void prism2_detach(dev_link_t *link); +static void prism2_detach(struct pcmcia_device *p_dev); static void prism2_release(u_long arg); static int prism2_event(event_t event, int priority, event_callback_args_t *args); @@ -528,15 +528,16 @@ static dev_link_t *prism2_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != CS_SUCCESS) { cs_error(link->handle, RegisterClient, ret); - prism2_detach(link); + prism2_detach(link->handle); return NULL; } return link; } -static void prism2_detach(dev_link_t *link) +static void prism2_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); dev_link_t **linkp; PDEBUG(DEBUG_FLOW, "prism2_detach\n"); @@ -554,14 +555,6 @@ static void prism2_detach(dev_link_t *link) prism2_release((u_long)link); } - if (link->handle) { - int res = pcmcia_deregister_client(link->handle); - if (res) { - printk("CardService(DeregisterClient) => %d\n", res); - cs_error(link->handle, DeregisterClient, res); - } - } - *linkp = link->next; /* release net devices */ if (link->priv) { @@ -902,7 +895,6 @@ static int prism2_event(event_t event, int priority, event_callback_args_t *args) { dev_link_t *link = args->client_data; - struct net_device *dev = (struct net_device *) link->priv; switch (event) { case CS_EVENT_CARD_INSERTION: @@ -913,16 +905,6 @@ static int prism2_event(event_t event, int priority, } break; - case CS_EVENT_CARD_REMOVAL: - PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_CARD_REMOVAL\n", dev_info); - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) { - netif_stop_queue(dev); - netif_device_detach(dev); - prism2_release((u_long) link); - } - break; - default: PDEBUG(DEBUG_EXTRA, "%s: prism2_event() - unknown event %d\n", dev_info, event); @@ -991,7 +973,7 @@ static struct pcmcia_driver hostap_driver = { .name = "hostap_cs", }, .attach = prism2_attach, - .detach = prism2_detach, + .remove = prism2_detach, .owner = THIS_MODULE, .event = prism2_event, .id_table = hostap_cs_ids, diff --git a/drivers/net/wireless/netwave_cs.c b/drivers/net/wireless/netwave_cs.c index 7ab2d70ffddf..1770677d9e10 100644 --- a/drivers/net/wireless/netwave_cs.c +++ b/drivers/net/wireless/netwave_cs.c @@ -200,7 +200,7 @@ static int netwave_event(event_t event, int priority, static void netwave_pcmcia_config(dev_link_t *arg); /* Runs after card insertion */ static dev_link_t *netwave_attach(void); /* Create instance */ -static void netwave_detach(dev_link_t *); /* Destroy instance */ +static void netwave_detach(struct pcmcia_device *p_dev); /* Destroy instance */ /* Hardware configuration */ static void netwave_doreset(kio_addr_t iobase, u_char __iomem *ramBase); @@ -459,7 +459,7 @@ static dev_link_t *netwave_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != 0) { cs_error(link->handle, RegisterClient, ret); - netwave_detach(link); + netwave_detach(link->handle); return NULL; } @@ -474,8 +474,9 @@ static dev_link_t *netwave_attach(void) * structures are freed. Otherwise, the structures will be freed * when the device is released. */ -static void netwave_detach(dev_link_t *link) +static void netwave_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); struct net_device *dev = link->priv; dev_link_t **linkp; @@ -489,11 +490,7 @@ static void netwave_detach(dev_link_t *link) */ if (link->state & DEV_CONFIG) netwave_release(link); - - /* Break the link with Card Services */ - if (link->handle) - pcmcia_deregister_client(link->handle); - + /* Locate device structure */ for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) if (*linkp == link) break; @@ -986,22 +983,10 @@ static int netwave_event(event_t event, int priority, event_callback_args_t *args) { dev_link_t *link = args->client_data; - struct net_device *dev = link->priv; - - DEBUG(1, "netwave_event(0x%06x)\n", event); - - switch (event) { - case CS_EVENT_REGISTRATION_COMPLETE: - DEBUG(0, "netwave_cs: registration complete\n"); - break; - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) { - netif_device_detach(dev); - netwave_release(link); - } - break; + DEBUG(1, "netwave_event(0x%06x)\n", event); + + switch (event) { case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; netwave_pcmcia_config( link); @@ -1504,7 +1489,7 @@ static struct pcmcia_driver netwave_driver = { }, .attach = netwave_attach, .event = netwave_event, - .detach = netwave_detach, + .remove = netwave_detach, .id_table = netwave_ids, .suspend = netwave_suspend, .resume = netwave_resume, diff --git a/drivers/net/wireless/orinoco_cs.c b/drivers/net/wireless/orinoco_cs.c index 1d66050e3d6a..00679b6c87c1 100644 --- a/drivers/net/wireless/orinoco_cs.c +++ b/drivers/net/wireless/orinoco_cs.c @@ -81,7 +81,7 @@ static dev_link_t *dev_list; /* = NULL */ /********************************************************************/ static void orinoco_cs_release(dev_link_t *link); -static void orinoco_cs_detach(dev_link_t *link); +static void orinoco_cs_detach(struct pcmcia_device *p_dev); /********************************************************************/ /* Device methods */ @@ -165,7 +165,7 @@ orinoco_cs_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != CS_SUCCESS) { cs_error(link->handle, RegisterClient, ret); - orinoco_cs_detach(link); + orinoco_cs_detach(link->handle); return NULL; } @@ -178,8 +178,9 @@ orinoco_cs_attach(void) * are freed. Otherwise, the structures will be freed when the device * is released. */ -static void orinoco_cs_detach(dev_link_t *link) +static void orinoco_cs_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); dev_link_t **linkp; struct net_device *dev = link->priv; @@ -193,10 +194,6 @@ static void orinoco_cs_detach(dev_link_t *link) if (link->state & DEV_CONFIG) orinoco_cs_release(link); - /* Break the link with Card Services */ - if (link->handle) - pcmcia_deregister_client(link->handle); - /* Unlink device structure, and free it */ *linkp = link->next; DEBUG(0, PFX "detach: link=%p link->dev=%p\n", link, link->dev); @@ -551,30 +548,15 @@ orinoco_cs_event(event_t event, int priority, event_callback_args_t * args) { dev_link_t *link = args->client_data; - struct net_device *dev = link->priv; - struct orinoco_private *priv = netdev_priv(dev); - int err = 0; switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) { - unsigned long flags; - - spin_lock_irqsave(&priv->lock, flags); - netif_device_detach(dev); - priv->hw_unavailable++; - spin_unlock_irqrestore(&priv->lock, flags); - } - break; - case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; orinoco_cs_config(link); break; } - return err; + return 0; } /* orinoco_cs_event */ /********************************************************************/ @@ -677,7 +659,7 @@ static struct pcmcia_driver orinoco_driver = { .name = DRIVER_NAME, }, .attach = orinoco_cs_attach, - .detach = orinoco_cs_detach, + .remove = orinoco_cs_detach, .event = orinoco_cs_event, .id_table = orinoco_cs_ids, .suspend = orinoco_cs_suspend, diff --git a/drivers/net/wireless/ray_cs.c b/drivers/net/wireless/ray_cs.c index c2cb6c8e6d7c..33a89e292126 100644 --- a/drivers/net/wireless/ray_cs.c +++ b/drivers/net/wireless/ray_cs.c @@ -94,7 +94,7 @@ static void ray_config(dev_link_t *link); static void ray_release(dev_link_t *link); static int ray_event(event_t event, int priority, event_callback_args_t *args); static dev_link_t *ray_attach(void); -static void ray_detach(dev_link_t *); +static void ray_detach(struct pcmcia_device *p_dev); /***** Prototypes indicated by device structure ******************************/ static int ray_dev_close(struct net_device *dev); @@ -402,7 +402,7 @@ static dev_link_t *ray_attach(void) if (ret != 0) { printk("ray_cs ray_attach RegisterClient unhappy - detaching\n"); cs_error(link->handle, RegisterClient, ret); - ray_detach(link); + ray_detach(link->handle); return NULL; } DEBUG(2,"ray_cs ray_attach ending\n"); @@ -418,9 +418,12 @@ fail_alloc_dev: structures are freed. Otherwise, the structures will be freed when the device is released. =============================================================================*/ -static void ray_detach(dev_link_t *link) +static void ray_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); dev_link_t **linkp; + struct net_device *dev; + ray_dev_t *local; DEBUG(1, "ray_detach(0x%p)\n", link); @@ -430,22 +433,18 @@ static void ray_detach(dev_link_t *link) if (*linkp == NULL) return; - /* If the device is currently configured and active, we won't - actually delete it yet. Instead, it is marked so that when - the release() function is called, that will trigger a proper - detach(). - */ - if (link->state & DEV_CONFIG) - ray_release(link); + dev = link->priv; + + if (link->state & DEV_CONFIG) { + ray_release(link); + + local = (ray_dev_t *)dev->priv; + del_timer(&local->timer); + } - /* Break the link with Card Services */ - if (link->handle) - pcmcia_deregister_client(link->handle); - /* Unlink device structure, free pieces */ *linkp = link->next; if (link->priv) { - struct net_device *dev = link->priv; if (link->dev) unregister_netdev(dev); free_netdev(dev); } @@ -940,19 +939,9 @@ static int ray_event(event_t event, int priority, event_callback_args_t *args) { dev_link_t *link = args->client_data; - struct net_device *dev = link->priv; - ray_dev_t *local = (ray_dev_t *)dev->priv; DEBUG(1, "ray_event(0x%06x)\n", event); - + switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - netif_device_detach(dev); - if (link->state & DEV_CONFIG) { - ray_release(link); - del_timer(&local->timer); - } - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; ray_config(link); @@ -2958,7 +2947,7 @@ static struct pcmcia_driver ray_driver = { }, .attach = ray_attach, .event = ray_event, - .detach = ray_detach, + .remove = ray_detach, .id_table = ray_ids, .suspend = ray_suspend, .resume = ray_resume, diff --git a/drivers/net/wireless/spectrum_cs.c b/drivers/net/wireless/spectrum_cs.c index 3938a5735659..a2dcab7995c1 100644 --- a/drivers/net/wireless/spectrum_cs.c +++ b/drivers/net/wireless/spectrum_cs.c @@ -90,7 +90,7 @@ static dev_link_t *dev_list; /* = NULL */ /********************************************************************/ static void spectrum_cs_release(dev_link_t *link); -static void spectrum_cs_detach(dev_link_t *link); +static void spectrum_cs_detach(struct pcmcia_device *p_dev); /********************************************************************/ /* Firmware downloader */ @@ -647,7 +647,7 @@ spectrum_cs_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != CS_SUCCESS) { cs_error(link->handle, RegisterClient, ret); - spectrum_cs_detach(link); + spectrum_cs_detach(link->handle); return NULL; } @@ -660,27 +660,14 @@ spectrum_cs_attach(void) * are freed. Otherwise, the structures will be freed when the device * is released. */ -static void spectrum_cs_detach(dev_link_t *link) +static void spectrum_cs_detach(struct pcmcia_device *p_dev) { - dev_link_t **linkp; + dev_link_t *link = dev_to_instance(p_dev); struct net_device *dev = link->priv; - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) - break; - - BUG_ON(*linkp == NULL); - if (link->state & DEV_CONFIG) spectrum_cs_release(link); - /* Break the link with Card Services */ - if (link->handle) - pcmcia_deregister_client(link->handle); - - /* Unlink device structure, and free it */ - *linkp = link->next; DEBUG(0, PFX "detach: link=%p link->dev=%p\n", link, link->dev); if (link->dev) { DEBUG(0, PFX "About to unregister net device %p\n", @@ -1007,22 +994,8 @@ spectrum_cs_event(event_t event, int priority, event_callback_args_t * args) { dev_link_t *link = args->client_data; - struct net_device *dev = link->priv; - struct orinoco_private *priv = netdev_priv(dev); switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) { - unsigned long flags; - - spin_lock_irqsave(&priv->lock, flags); - netif_device_detach(dev); - priv->hw_unavailable++; - spin_unlock_irqrestore(&priv->lock, flags); - } - break; - case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; spectrum_cs_config(link); @@ -1057,7 +1030,7 @@ static struct pcmcia_driver orinoco_driver = { .name = DRIVER_NAME, }, .attach = spectrum_cs_attach, - .detach = spectrum_cs_detach, + .remove = spectrum_cs_detach, .suspend = spectrum_cs_suspend, .resume = spectrum_cs_resume, .event = spectrum_cs_event, diff --git a/drivers/net/wireless/wavelan_cs.c b/drivers/net/wireless/wavelan_cs.c index 3e3532830c26..255952d8cea0 100644 --- a/drivers/net/wireless/wavelan_cs.c +++ b/drivers/net/wireless/wavelan_cs.c @@ -4692,7 +4692,7 @@ wavelan_attach(void) if(ret != 0) { cs_error(link->handle, RegisterClient, ret); - wavelan_detach(link); + wavelan_detach(link->handle); return NULL; } @@ -4711,8 +4711,10 @@ wavelan_attach(void) * is released. */ static void -wavelan_detach(dev_link_t * link) +wavelan_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); + #ifdef DEBUG_CALLBACK_TRACE printk(KERN_DEBUG "-> wavelan_detach(0x%p)\n", link); #endif @@ -4729,10 +4731,6 @@ wavelan_detach(dev_link_t * link) wv_pcmcia_release(link); } - /* Break the link with Card Services */ - if(link->handle) - pcmcia_deregister_client(link->handle); - /* Remove the interface data from the linked list */ if(dev_list == link) dev_list = link->next; @@ -4854,25 +4852,6 @@ wavelan_event(event_t event, /* The event received */ switch(event) { - case CS_EVENT_REGISTRATION_COMPLETE: -#ifdef DEBUG_CONFIG_INFO - printk(KERN_DEBUG "wavelan_cs: registration complete\n"); -#endif - break; - - case CS_EVENT_CARD_REMOVAL: - /* Oups ! The card is no more there */ - link->state &= ~DEV_PRESENT; - if(link->state & DEV_CONFIG) - { - /* Accept no more transmissions */ - netif_device_detach(dev); - - /* Release the card */ - wv_pcmcia_release(link); - } - break; - case CS_EVENT_CARD_INSERTION: /* Reset and configure the card */ link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; @@ -4906,7 +4885,7 @@ static struct pcmcia_driver wavelan_driver = { }, .attach = wavelan_attach, .event = wavelan_event, - .detach = wavelan_detach, + .remove = wavelan_detach, .id_table = wavelan_ids, .suspend = wavelan_suspend, .resume = wavelan_resume, diff --git a/drivers/net/wireless/wavelan_cs.p.h b/drivers/net/wireless/wavelan_cs.p.h index 724a715089c9..3cb34817c039 100644 --- a/drivers/net/wireless/wavelan_cs.p.h +++ b/drivers/net/wireless/wavelan_cs.p.h @@ -757,7 +757,7 @@ static int static dev_link_t * wavelan_attach(void); /* Create a new device */ static void - wavelan_detach(dev_link_t *); /* Destroy a removed device */ + wavelan_detach(struct pcmcia_device *p_dev); /* Destroy a removed device */ static int wavelan_event(event_t, /* Manage pcmcia events */ int, diff --git a/drivers/net/wireless/wl3501_cs.c b/drivers/net/wireless/wl3501_cs.c index 75114318457e..21e498fe7b14 100644 --- a/drivers/net/wireless/wl3501_cs.c +++ b/drivers/net/wireless/wl3501_cs.c @@ -1498,9 +1498,11 @@ static struct ethtool_ops ops = { * Services. If it has been released, all local data structures are freed. * Otherwise, the structures will be freed when the device is released. */ -static void wl3501_detach(dev_link_t *link) +static void wl3501_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); dev_link_t **linkp; + struct net_device *dev = link->priv; /* Locate device structure */ for (linkp = &wl3501_dev_list; *linkp; linkp = &(*linkp)->next) @@ -1514,16 +1516,12 @@ static void wl3501_detach(dev_link_t *link) * function is called, that will trigger a proper detach(). */ if (link->state & DEV_CONFIG) { -#ifdef PCMCIA_DEBUG - printk(KERN_DEBUG "wl3501_cs: detach postponed, '%s' " - "still locked\n", link->dev->dev_name); -#endif - goto out; - } + while (link->open > 0) + wl3501_close(dev); - /* Break the link with Card Services */ - if (link->handle) - pcmcia_deregister_client(link->handle); + netif_device_detach(dev); + wl3501_release(link); + } /* Unlink device structure, free pieces */ *linkp = link->next; @@ -2012,7 +2010,7 @@ static dev_link_t *wl3501_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret) { cs_error(link->handle, RegisterClient, ret); - wl3501_detach(link); + wl3501_detach(link->handle); link = NULL; } out: @@ -2225,18 +2223,8 @@ static int wl3501_resume(struct pcmcia_device *p_dev) static int wl3501_event(event_t event, int pri, event_callback_args_t *args) { dev_link_t *link = args->client_data; - struct net_device *dev = link->priv; switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) { - while (link->open > 0) - wl3501_close(dev); - netif_device_detach(dev); - wl3501_release(link); - } - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; wl3501_config(link); @@ -2258,7 +2246,7 @@ static struct pcmcia_driver wl3501_driver = { }, .attach = wl3501_attach, .event = wl3501_event, - .detach = wl3501_detach, + .remove = wl3501_detach, .id_table = wl3501_ids, .suspend = wl3501_suspend, .resume = wl3501_resume, diff --git a/drivers/parport/parport_cs.c b/drivers/parport/parport_cs.c index 4c89853785ed..063d22de9743 100644 --- a/drivers/parport/parport_cs.c +++ b/drivers/parport/parport_cs.c @@ -88,7 +88,7 @@ typedef struct parport_info_t { } parport_info_t; static dev_link_t *parport_attach(void); -static void parport_detach(dev_link_t *); +static void parport_detach(struct pcmcia_device *p_dev); static void parport_config(dev_link_t *link); static void parport_cs_release(dev_link_t *); static int parport_event(event_t event, int priority, @@ -137,7 +137,7 @@ static dev_link_t *parport_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != CS_SUCCESS) { cs_error(link->handle, RegisterClient, ret); - parport_detach(link); + parport_detach(link->handle); return NULL; } @@ -153,13 +153,13 @@ static dev_link_t *parport_attach(void) ======================================================================*/ -static void parport_detach(dev_link_t *link) +static void parport_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); dev_link_t **linkp; - int ret; DEBUG(0, "parport_detach(0x%p)\n", link); - + /* Locate device structure */ for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) if (*linkp == link) break; @@ -168,17 +168,10 @@ static void parport_detach(dev_link_t *link) if (link->state & DEV_CONFIG) parport_cs_release(link); - - if (link->handle) { - ret = pcmcia_deregister_client(link->handle); - if (ret != CS_SUCCESS) - cs_error(link->handle, DeregisterClient, ret); - } - + /* Unlink, free device structure */ *linkp = link->next; kfree(link->priv); - } /* parport_detach */ /*====================================================================== @@ -362,11 +355,6 @@ int parport_event(event_t event, int priority, DEBUG(1, "parport_event(0x%06x)\n", event); switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) - parport_cs_release(link); - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; parport_config(link); @@ -389,7 +377,7 @@ static struct pcmcia_driver parport_cs_driver = { }, .attach = parport_attach, .event = parport_event, - .detach = parport_detach, + .remove = parport_detach, .id_table = parport_ids, .suspend = parport_suspend, .resume = parport_resume, diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index 5223395b246a..32b4d6baa917 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -57,8 +57,6 @@ module_param_named(pc_debug, ds_pc_debug, int, 0644); spinlock_t pcmcia_dev_list_lock; -static int unbind_request(struct pcmcia_socket *s); - /*====================================================================*/ /* code which was in cs.c before */ @@ -205,7 +203,7 @@ static void pcmcia_check_driver(struct pcmcia_driver *p_drv) unsigned int i; u32 hash; - if (!p_drv->attach || !p_drv->event || !p_drv->detach) + if (!p_drv->attach || !p_drv->event || !p_drv->remove) printk(KERN_DEBUG "pcmcia: %s lacks a requisite callback " "function\n", p_drv->drv.name); @@ -399,13 +397,42 @@ static int pcmcia_device_remove(struct device * dev) { struct pcmcia_device *p_dev; struct pcmcia_driver *p_drv; + int i; /* detach the "instance" */ p_dev = to_pcmcia_dev(dev); p_drv = to_pcmcia_drv(dev->driver); + /* the likely, new path */ + if (p_drv && p_drv->remove) { + p_drv->remove(p_dev); + + /* check for proper unloading */ + if (p_dev->state & (CLIENT_IRQ_REQ|CLIENT_IO_REQ|CLIENT_CONFIG_LOCKED)) + printk(KERN_INFO "pcmcia: driver %s did not release config properly\n", + p_drv->drv.name); + + for (i = 0; i < MAX_WIN; i++) + if (p_dev->state & CLIENT_WIN_REQ(i)) + printk(KERN_INFO "pcmcia: driver %s did not release windows properly\n", + p_drv->drv.name); + + /* undo pcmcia_register_client */ + p_dev->state = CLIENT_UNBOUND; + pcmcia_put_dev(p_dev); + + /* references from pcmcia_probe_device */ + pcmcia_put_dev(p_dev); + module_put(p_drv->owner); + + return 0; + } + + /* old path */ if (p_drv) { if ((p_drv->detach) && (p_dev->instance)) { + printk(KERN_INFO "pcmcia: using deprecated detach mechanism. Fix the driver!\n"); + p_drv->detach(p_dev->instance); /* from pcmcia_probe_device */ put_device(&p_dev->dev); @@ -417,6 +444,36 @@ static int pcmcia_device_remove(struct device * dev) } +/* + * Removes a PCMCIA card from the device tree and socket list. + */ +static void pcmcia_card_remove(struct pcmcia_socket *s) +{ + struct pcmcia_device *p_dev; + unsigned long flags; + + ds_dbg(2, "unbind_request(%d)\n", s->sock); + + s->device_count = 0; + + for (;;) { + /* unregister all pcmcia_devices registered with this socket*/ + spin_lock_irqsave(&pcmcia_dev_list_lock, flags); + if (list_empty(&s->devices_list)) { + spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); + return; + } + p_dev = list_entry((&s->devices_list)->next, struct pcmcia_device, socket_device_list); + list_del(&p_dev->socket_device_list); + p_dev->state |= CLIENT_STALE; + spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); + + device_unregister(&p_dev->dev); + } + + return; +} /* unbind_request */ + /* * pcmcia_device_query -- determine information about a pcmcia device @@ -1059,8 +1116,8 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority) case CS_EVENT_CARD_REMOVAL: s->pcmcia_state.present = 0; - send_event(skt, event, priority); - unbind_request(skt); + send_event(skt, event, priority); + pcmcia_card_remove(skt); handle_event(skt, event); break; @@ -1177,36 +1234,6 @@ int pcmcia_register_client(struct pcmcia_device **handle, client_reg_t *req) EXPORT_SYMBOL(pcmcia_register_client); -/* unbind _all_ devices attached to a given pcmcia_bus_socket. The - * drivers have been called with EVENT_CARD_REMOVAL before. - */ -static int unbind_request(struct pcmcia_socket *s) -{ - struct pcmcia_device *p_dev; - unsigned long flags; - - ds_dbg(2, "unbind_request(%d)\n", s->sock); - - s->device_count = 0; - - for (;;) { - /* unregister all pcmcia_devices registered with this socket*/ - spin_lock_irqsave(&pcmcia_dev_list_lock, flags); - if (list_empty(&s->devices_list)) { - spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); - return 0; - } - p_dev = list_entry((&s->devices_list)->next, struct pcmcia_device, socket_device_list); - list_del(&p_dev->socket_device_list); - p_dev->state |= CLIENT_STALE; - spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); - - device_unregister(&p_dev->dev); - } - - return 0; -} /* unbind_request */ - int pcmcia_deregister_client(struct pcmcia_device *p_dev) { struct pcmcia_socket *s; diff --git a/drivers/scsi/pcmcia/aha152x_stub.c b/drivers/scsi/pcmcia/aha152x_stub.c index 82988a3e35ec..3128ba8c57a9 100644 --- a/drivers/scsi/pcmcia/aha152x_stub.c +++ b/drivers/scsi/pcmcia/aha152x_stub.c @@ -99,7 +99,7 @@ static int aha152x_event(event_t event, int priority, event_callback_args_t *args); static dev_link_t *aha152x_attach(void); -static void aha152x_detach(dev_link_t *); +static void aha152x_detach(struct pcmcia_device *p_dev); static dev_link_t *dev_list; static dev_info_t dev_info = "aha152x_cs"; @@ -138,7 +138,7 @@ static dev_link_t *aha152x_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != 0) { cs_error(link->handle, RegisterClient, ret); - aha152x_detach(link); + aha152x_detach(link->handle); return NULL; } @@ -147,8 +147,9 @@ static dev_link_t *aha152x_attach(void) /*====================================================================*/ -static void aha152x_detach(dev_link_t *link) +static void aha152x_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); dev_link_t **linkp; DEBUG(0, "aha152x_detach(0x%p)\n", link); @@ -162,9 +163,6 @@ static void aha152x_detach(dev_link_t *link) if (link->state & DEV_CONFIG) aha152x_release_cs(link); - if (link->handle) - pcmcia_deregister_client(link->handle); - /* Unlink device structure, free bits */ *linkp = link->next; kfree(link->priv); @@ -307,11 +305,6 @@ static int aha152x_event(event_t event, int priority, DEBUG(0, "aha152x_event(0x%06x)\n", event); switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) - aha152x_release_cs(link); - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; aha152x_config_cs(link); @@ -337,7 +330,7 @@ static struct pcmcia_driver aha152x_cs_driver = { }, .attach = aha152x_attach, .event = aha152x_event, - .detach = aha152x_detach, + .remove = aha152x_detach, .id_table = aha152x_ids, .suspend = aha152x_suspend, .resume = aha152x_resume, diff --git a/drivers/scsi/pcmcia/fdomain_stub.c b/drivers/scsi/pcmcia/fdomain_stub.c index 9e1d68c14694..5842c938fff5 100644 --- a/drivers/scsi/pcmcia/fdomain_stub.c +++ b/drivers/scsi/pcmcia/fdomain_stub.c @@ -84,7 +84,7 @@ static int fdomain_event(event_t event, int priority, event_callback_args_t *args); static dev_link_t *fdomain_attach(void); -static void fdomain_detach(dev_link_t *); +static void fdomain_detach(struct pcmcia_device *p_dev); static dev_link_t *dev_list = NULL; @@ -124,7 +124,7 @@ static dev_link_t *fdomain_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != 0) { cs_error(link->handle, RegisterClient, ret); - fdomain_detach(link); + fdomain_detach(link->handle); return NULL; } @@ -133,8 +133,9 @@ static dev_link_t *fdomain_attach(void) /*====================================================================*/ -static void fdomain_detach(dev_link_t *link) +static void fdomain_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); dev_link_t **linkp; DEBUG(0, "fdomain_detach(0x%p)\n", link); @@ -148,9 +149,6 @@ static void fdomain_detach(dev_link_t *link) if (link->state & DEV_CONFIG) fdomain_release(link); - if (link->handle) - pcmcia_deregister_client(link->handle); - /* Unlink device structure, free bits */ *linkp = link->next; kfree(link->priv); @@ -288,11 +286,6 @@ static int fdomain_event(event_t event, int priority, DEBUG(1, "fdomain_event(0x%06x)\n", event); switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) - fdomain_release(link); - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; fdomain_config(link); @@ -317,7 +310,7 @@ static struct pcmcia_driver fdomain_cs_driver = { }, .attach = fdomain_attach, .event = fdomain_event, - .detach = fdomain_detach, + .remove = fdomain_detach, .id_table = fdomain_ids, .suspend = fdomain_suspend, .resume = fdomain_resume, diff --git a/drivers/scsi/pcmcia/nsp_cs.c b/drivers/scsi/pcmcia/nsp_cs.c index 870e87180d12..e40a8c22aa9d 100644 --- a/drivers/scsi/pcmcia/nsp_cs.c +++ b/drivers/scsi/pcmcia/nsp_cs.c @@ -1646,7 +1646,7 @@ static dev_link_t *nsp_cs_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != CS_SUCCESS) { cs_error(link->handle, RegisterClient, ret); - nsp_cs_detach(link); + nsp_cs_detach(link->handle); return NULL; } @@ -1662,8 +1662,9 @@ static dev_link_t *nsp_cs_attach(void) structures are freed. Otherwise, the structures will be freed when the device is released. ======================================================================*/ -static void nsp_cs_detach(dev_link_t *link) +static void nsp_cs_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); dev_link_t **linkp; nsp_dbg(NSP_DEBUG_INIT, "in, link=0x%p", link); @@ -1678,12 +1679,9 @@ static void nsp_cs_detach(dev_link_t *link) return; } - if (link->state & DEV_CONFIG) + if (link->state & DEV_CONFIG) { + ((scsi_info_t *)link->priv)->stop = 1; nsp_cs_release(link); - - /* Break the link with Card Services */ - if (link->handle) { - pcmcia_deregister_client(link->handle); } /* Unlink device structure, free bits */ @@ -2096,15 +2094,6 @@ static int nsp_cs_event(event_t event, nsp_dbg(NSP_DEBUG_INIT, "in, event=0x%08x", event); switch (event) { - case CS_EVENT_CARD_REMOVAL: - nsp_dbg(NSP_DEBUG_INIT, "event: remove"); - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) { - ((scsi_info_t *)link->priv)->stop = 1; - nsp_cs_release(link); - } - break; - case CS_EVENT_CARD_INSERTION: nsp_dbg(NSP_DEBUG_INIT, "event: insert"); link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; @@ -2144,7 +2133,7 @@ static struct pcmcia_driver nsp_driver = { }, .attach = nsp_cs_attach, .event = nsp_cs_event, - .detach = nsp_cs_detach, + .remove = nsp_cs_detach, .id_table = nsp_cs_ids, .suspend = nsp_cs_suspend, .resume = nsp_cs_resume, diff --git a/drivers/scsi/pcmcia/nsp_cs.h b/drivers/scsi/pcmcia/nsp_cs.h index f8b943082717..d276c469edf1 100644 --- a/drivers/scsi/pcmcia/nsp_cs.h +++ b/drivers/scsi/pcmcia/nsp_cs.h @@ -297,7 +297,7 @@ typedef struct _nsp_hw_data { /* Card service functions */ static dev_link_t *nsp_cs_attach (void); -static void nsp_cs_detach (dev_link_t *link); +static void nsp_cs_detach (struct pcmcia_device *p_dev); static void nsp_cs_release(dev_link_t *link); static void nsp_cs_config (dev_link_t *link); static int nsp_cs_event (event_t event, int priority, event_callback_args_t *args); diff --git a/drivers/scsi/pcmcia/qlogic_stub.c b/drivers/scsi/pcmcia/qlogic_stub.c index 2541a999a0e5..8351dc234ffb 100644 --- a/drivers/scsi/pcmcia/qlogic_stub.c +++ b/drivers/scsi/pcmcia/qlogic_stub.c @@ -101,7 +101,7 @@ static void qlogic_release(dev_link_t *link); static int qlogic_event(event_t event, int priority, event_callback_args_t * args); static dev_link_t *qlogic_attach(void); -static void qlogic_detach(dev_link_t *); +static void qlogic_detach(struct pcmcia_device *p_dev); static dev_link_t *dev_list = NULL; @@ -198,7 +198,7 @@ static dev_link_t *qlogic_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != 0) { cs_error(link->handle, RegisterClient, ret); - qlogic_detach(link); + qlogic_detach(link->handle); return NULL; } @@ -207,8 +207,9 @@ static dev_link_t *qlogic_attach(void) /*====================================================================*/ -static void qlogic_detach(dev_link_t * link) +static void qlogic_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); dev_link_t **linkp; DEBUG(0, "qlogic_detach(0x%p)\n", link); @@ -223,9 +224,6 @@ static void qlogic_detach(dev_link_t * link) if (link->state & DEV_CONFIG) qlogic_release(link); - if (link->handle) - pcmcia_deregister_client(link->handle); - /* Unlink device structure, free bits */ *linkp = link->next; kfree(link->priv); @@ -390,11 +388,6 @@ static int qlogic_event(event_t event, int priority, event_callback_args_t * arg DEBUG(1, "qlogic_event(0x%06x)\n", event); switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) - qlogic_release(link); - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; qlogic_config(link); @@ -432,7 +425,7 @@ static struct pcmcia_driver qlogic_cs_driver = { }, .attach = qlogic_attach, .event = qlogic_event, - .detach = qlogic_detach, + .remove = qlogic_detach, .id_table = qlogic_ids, .suspend = qlogic_suspend, .resume = qlogic_resume, diff --git a/drivers/scsi/pcmcia/sym53c500_cs.c b/drivers/scsi/pcmcia/sym53c500_cs.c index c4e3e2294c66..a0f8e2691f9c 100644 --- a/drivers/scsi/pcmcia/sym53c500_cs.c +++ b/drivers/scsi/pcmcia/sym53c500_cs.c @@ -918,11 +918,6 @@ SYM53C500_event(event_t event, int priority, event_callback_args_t *args) DEBUG(1, "SYM53C500_event(0x%06x)\n", event); switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) - SYM53C500_release(link); - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; SYM53C500_config(link); @@ -932,8 +927,9 @@ SYM53C500_event(event_t event, int priority, event_callback_args_t *args) } /* SYM53C500_event */ static void -SYM53C500_detach(dev_link_t *link) +SYM53C500_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); dev_link_t **linkp; DEBUG(0, "SYM53C500_detach(0x%p)\n", link); @@ -948,9 +944,6 @@ SYM53C500_detach(dev_link_t *link) if (link->state & DEV_CONFIG) SYM53C500_release(link); - if (link->handle) - pcmcia_deregister_client(link->handle); - /* Unlink device structure, free bits. */ *linkp = link->next; kfree(link->priv); @@ -993,7 +986,7 @@ SYM53C500_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != 0) { cs_error(link->handle, RegisterClient, ret); - SYM53C500_detach(link); + SYM53C500_detach(link->handle); return NULL; } @@ -1019,7 +1012,7 @@ static struct pcmcia_driver sym53c500_cs_driver = { }, .attach = SYM53C500_attach, .event = SYM53C500_event, - .detach = SYM53C500_detach, + .remove = SYM53C500_detach, .id_table = sym53c500_ids, .suspend = sym53c500_suspend, .resume = sym53c500_resume, diff --git a/drivers/serial/serial_cs.c b/drivers/serial/serial_cs.c index 3487ee9eab1d..a95366366504 100644 --- a/drivers/serial/serial_cs.c +++ b/drivers/serial/serial_cs.c @@ -120,7 +120,7 @@ static int serial_event(event_t event, int priority, static dev_info_t dev_info = "serial_cs"; static dev_link_t *serial_attach(void); -static void serial_detach(dev_link_t *); +static void serial_detach(struct pcmcia_device *p_dev); static dev_link_t *dev_list = NULL; @@ -242,7 +242,7 @@ static dev_link_t *serial_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != CS_SUCCESS) { cs_error(link->handle, RegisterClient, ret); - serial_detach(link); + serial_detach(link->handle); return NULL; } @@ -258,11 +258,11 @@ static dev_link_t *serial_attach(void) ======================================================================*/ -static void serial_detach(dev_link_t * link) +static void serial_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); struct serial_info *info = link->priv; dev_link_t **linkp; - int ret; DEBUG(0, "serial_detach(0x%p)\n", link); @@ -283,12 +283,6 @@ static void serial_detach(dev_link_t * link) */ serial_remove(link); - if (link->handle) { - ret = pcmcia_deregister_client(link->handle); - if (ret != CS_SUCCESS) - cs_error(link->handle, DeregisterClient, ret); - } - /* Unlink device structure, free bits */ *linkp = link->next; kfree(info); @@ -741,9 +735,6 @@ serial_event(event_t event, int priority, event_callback_args_t * args) DEBUG(1, "serial_event(0x%06x)\n", event); switch (event) { - case CS_EVENT_CARD_REMOVAL: - serial_remove(link); - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; @@ -866,7 +857,7 @@ static struct pcmcia_driver serial_cs_driver = { }, .attach = serial_attach, .event = serial_event, - .detach = serial_detach, + .remove = serial_detach, .id_table = serial_ids, .suspend = serial_suspend, .resume = serial_resume, diff --git a/drivers/telephony/ixj_pcmcia.c b/drivers/telephony/ixj_pcmcia.c index 7cca46be0c0f..c58140dc7a73 100644 --- a/drivers/telephony/ixj_pcmcia.c +++ b/drivers/telephony/ixj_pcmcia.c @@ -35,7 +35,7 @@ typedef struct ixj_info_t { } ixj_info_t; static dev_link_t *ixj_attach(void); -static void ixj_detach(dev_link_t *); +static void ixj_detach(struct pcmcia_device *p_dev); static void ixj_config(dev_link_t * link); static void ixj_cs_release(dev_link_t * link); static int ixj_event(event_t event, int priority, event_callback_args_t * args); @@ -73,16 +73,17 @@ static dev_link_t *ixj_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != CS_SUCCESS) { cs_error(link->handle, RegisterClient, ret); - ixj_detach(link); + ixj_detach(link->handle); return NULL; } return link; } -static void ixj_detach(dev_link_t * link) +static void ixj_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); dev_link_t **linkp; - int ret; + DEBUG(0, "ixj_detach(0x%p)\n", link); for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) if (*linkp == link) @@ -92,11 +93,7 @@ static void ixj_detach(dev_link_t * link) link->state &= ~DEV_RELEASE_PENDING; if (link->state & DEV_CONFIG) ixj_cs_release(link); - if (link->handle) { - ret = pcmcia_deregister_client(link->handle); - if (ret != CS_SUCCESS) - cs_error(link->handle, DeregisterClient, ret); - } + /* Unlink device structure, free bits */ *linkp = link->next; kfree(link->priv); @@ -282,13 +279,6 @@ static int ixj_event(event_t event, int priority, event_callback_args_t * args) dev_link_t *link = args->client_data; DEBUG(1, "ixj_event(0x%06x)\n", event); switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) { - link->state |= DEV_RELEASE_PENDING; - ixj_cs_release(link); - } - break; case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; ixj_config(link); @@ -310,7 +300,7 @@ static struct pcmcia_driver ixj_driver = { }, .attach = ixj_attach, .event = ixj_event, - .detach = ixj_detach, + .remove = ixj_detach, .id_table = ixj_ids, .suspend = ixj_suspend, .resume = ixj_resume, diff --git a/drivers/usb/host/sl811_cs.c b/drivers/usb/host/sl811_cs.c index cb8c2bdbbd04..ed3e7014dbbc 100644 --- a/drivers/usb/host/sl811_cs.c +++ b/drivers/usb/host/sl811_cs.c @@ -73,6 +73,8 @@ typedef struct local_info_t { dev_node_t node; } local_info_t; +static void sl811_cs_release(dev_link_t * link); + /*====================================================================*/ static void release_platform_dev(struct device * dev) @@ -138,8 +140,9 @@ static int sl811_hc_init(struct device *parent, ioaddr_t base_addr, int irq) /*====================================================================*/ -static void sl811_cs_detach(dev_link_t *link) +static void sl811_cs_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); dev_link_t **linkp; DBG(0, "sl811_cs_detach(0x%p)\n", link); @@ -152,9 +155,9 @@ static void sl811_cs_detach(dev_link_t *link) if (*linkp == NULL) return; - /* Break the link with Card Services */ - if (link->handle) - pcmcia_deregister_client(link->handle); + link->state &= ~DEV_PRESENT; + if (link->state & DEV_CONFIG) + sl811_cs_release(link); /* Unlink device structure, and free it */ *linkp = link->next; @@ -167,13 +170,6 @@ static void sl811_cs_release(dev_link_t * link) DBG(0, "sl811_cs_release(0x%p)\n", link); - if (link->open) { - DBG(1, "sl811_cs: release postponed, '%s' still open\n", - link->dev->dev_name); - link->state |= DEV_STALE_CONFIG; - return; - } - /* Unlink the device chain */ link->dev = NULL; @@ -184,9 +180,6 @@ static void sl811_cs_release(dev_link_t * link) if (link->irq.AssignedIRQ) pcmcia_release_irq(link->handle, &link->irq); link->state &= ~DEV_CONFIG; - - if (link->state & DEV_STALE_LINK) - sl811_cs_detach(link); } static void sl811_cs_config(dev_link_t *link) @@ -353,12 +346,6 @@ sl811_cs_event(event_t event, int priority, event_callback_args_t *args) DBG(1, "sl811_cs_event(0x%06x)\n", event); switch (event) { - case CS_EVENT_CARD_REMOVAL: - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) - sl811_cs_release(link); - break; - case CS_EVENT_CARD_INSERTION: link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; sl811_cs_config(link); @@ -400,7 +387,7 @@ static dev_link_t *sl811_cs_attach(void) ret = pcmcia_register_client(&link->handle, &client_reg); if (ret != CS_SUCCESS) { cs_error(link->handle, RegisterClient, ret); - sl811_cs_detach(link); + sl811_cs_detach(link->handle); return NULL; } @@ -420,7 +407,7 @@ static struct pcmcia_driver sl811_cs_driver = { }, .attach = sl811_cs_attach, .event = sl811_cs_event, - .detach = sl811_cs_detach, + .remove = sl811_cs_detach, .id_table = sl811_ids, .suspend = sl811_suspend, .resume = sl811_resume, diff --git a/include/pcmcia/ds.h b/include/pcmcia/ds.h index 020055199008..2869283acd1d 100644 --- a/include/pcmcia/ds.h +++ b/include/pcmcia/ds.h @@ -138,6 +138,8 @@ struct pcmcia_driver { event_callback_args_t *); void (*detach)(dev_link_t *); + void (*remove) (struct pcmcia_device *dev); + int (*suspend) (struct pcmcia_device *dev); int (*resume) (struct pcmcia_device *dev); From f3990715589d378a2d3aa9b8accd78bb4a2378b7 Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Mon, 14 Nov 2005 21:25:23 +0100 Subject: [PATCH 34/48] [PATCH] pcmcia: remove old detach mechanism Remove the old "detach" mechanism as it is unused now. Signed-off-by: Dominik Brodowski --- drivers/pcmcia/ds.c | 77 ++++++++++----------------------------------- include/pcmcia/cs.h | 1 - include/pcmcia/ds.h | 1 - 3 files changed, 17 insertions(+), 62 deletions(-) diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index 32b4d6baa917..8eff55b6c9e9 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -402,43 +402,29 @@ static int pcmcia_device_remove(struct device * dev) /* detach the "instance" */ p_dev = to_pcmcia_dev(dev); p_drv = to_pcmcia_drv(dev->driver); + if (!p_drv) + return 0; - /* the likely, new path */ - if (p_drv && p_drv->remove) { + if (p_drv->remove) p_drv->remove(p_dev); - /* check for proper unloading */ - if (p_dev->state & (CLIENT_IRQ_REQ|CLIENT_IO_REQ|CLIENT_CONFIG_LOCKED)) - printk(KERN_INFO "pcmcia: driver %s did not release config properly\n", + /* check for proper unloading */ + if (p_dev->state & (CLIENT_IRQ_REQ|CLIENT_IO_REQ|CLIENT_CONFIG_LOCKED)) + printk(KERN_INFO "pcmcia: driver %s did not release config properly\n", + p_drv->drv.name); + + for (i = 0; i < MAX_WIN; i++) + if (p_dev->state & CLIENT_WIN_REQ(i)) + printk(KERN_INFO "pcmcia: driver %s did not release windows properly\n", p_drv->drv.name); - for (i = 0; i < MAX_WIN; i++) - if (p_dev->state & CLIENT_WIN_REQ(i)) - printk(KERN_INFO "pcmcia: driver %s did not release windows properly\n", - p_drv->drv.name); + /* undo pcmcia_register_client */ + p_dev->state = CLIENT_UNBOUND; + pcmcia_put_dev(p_dev); - /* undo pcmcia_register_client */ - p_dev->state = CLIENT_UNBOUND; - pcmcia_put_dev(p_dev); - - /* references from pcmcia_probe_device */ - pcmcia_put_dev(p_dev); - module_put(p_drv->owner); - - return 0; - } - - /* old path */ - if (p_drv) { - if ((p_drv->detach) && (p_dev->instance)) { - printk(KERN_INFO "pcmcia: using deprecated detach mechanism. Fix the driver!\n"); - - p_drv->detach(p_dev->instance); - /* from pcmcia_probe_device */ - put_device(&p_dev->dev); - } - module_put(p_drv->owner); - } + /* references from pcmcia_probe_device */ + pcmcia_put_dev(p_dev); + module_put(p_drv->owner); return 0; } @@ -1234,35 +1220,6 @@ int pcmcia_register_client(struct pcmcia_device **handle, client_reg_t *req) EXPORT_SYMBOL(pcmcia_register_client); -int pcmcia_deregister_client(struct pcmcia_device *p_dev) -{ - struct pcmcia_socket *s; - int i; - - s = p_dev->socket; - ds_dbg(1, "deregister_client(%p)\n", p_dev); - - if (p_dev->state & (CLIENT_IRQ_REQ|CLIENT_IO_REQ|CLIENT_CONFIG_LOCKED)) - goto warn_out; - for (i = 0; i < MAX_WIN; i++) - if (p_dev->state & CLIENT_WIN_REQ(i)) - goto warn_out; - - if (p_dev->state & CLIENT_STALE) { - p_dev->state &= ~CLIENT_STALE; - pcmcia_put_dev(p_dev); - } else { - p_dev->state = CLIENT_UNBOUND; - } - - return CS_SUCCESS; - warn_out: - printk(KERN_WARNING "ds: deregister_client was called too early.\n"); - return CS_IN_USE; -} /* deregister_client */ -EXPORT_SYMBOL(pcmcia_deregister_client); - - static struct pcmcia_callback pcmcia_bus_callback = { .owner = THIS_MODULE, .event = ds_event, diff --git a/include/pcmcia/cs.h b/include/pcmcia/cs.h index 2cab39f49eb2..a751251efdc8 100644 --- a/include/pcmcia/cs.h +++ b/include/pcmcia/cs.h @@ -382,7 +382,6 @@ enum service { struct pcmcia_socket; int pcmcia_access_configuration_register(struct pcmcia_device *p_dev, conf_reg_t *reg); -int pcmcia_deregister_client(struct pcmcia_device *p_dev); int pcmcia_get_configuration_info(struct pcmcia_device *p_dev, config_info_t *config); int pcmcia_get_first_window(window_handle_t *win, win_req_t *req); int pcmcia_get_next_window(window_handle_t *win, win_req_t *req); diff --git a/include/pcmcia/ds.h b/include/pcmcia/ds.h index 2869283acd1d..c53a0604e441 100644 --- a/include/pcmcia/ds.h +++ b/include/pcmcia/ds.h @@ -136,7 +136,6 @@ struct pcmcia_driver { dev_link_t *(*attach)(void); int (*event) (event_t event, int priority, event_callback_args_t *); - void (*detach)(dev_link_t *); void (*remove) (struct pcmcia_device *dev); From b463581154f3f3eecda27cae60df813fefcd84d3 Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Mon, 14 Nov 2005 21:25:35 +0100 Subject: [PATCH 35/48] [PATCH] pcmcia: remove dev_list from drivers The linked list of devices managed by each PCMCIA driver is, in very most cases, unused. Therefore, remove it from many drivers. Signed-off-by: Dominik Brodowski --- drivers/bluetooth/bluecard_cs.c | 18 +-------- drivers/bluetooth/bt3c_cs.c | 18 +-------- drivers/bluetooth/btuart_cs.c | 18 +-------- drivers/bluetooth/dtl1_cs.c | 18 +-------- drivers/char/pcmcia/synclink_cs.c | 14 +------ drivers/ide/legacy/ide-cs.c | 19 ++------- drivers/isdn/hardware/avm/avm_cs.c | 21 +--------- drivers/isdn/hisax/avma1_cs.c | 21 +--------- drivers/isdn/hisax/elsa_cs.c | 28 ++----------- drivers/isdn/hisax/sedlbauer_cs.c | 28 ++----------- drivers/isdn/hisax/teles_cs.c | 28 ++----------- drivers/mtd/maps/pcmciamtd.c | 5 +-- drivers/net/pcmcia/3c574_cs.c | 15 +------ drivers/net/pcmcia/3c589_cs.c | 17 +------- drivers/net/pcmcia/axnet_cs.c | 14 +------ drivers/net/pcmcia/com20020_cs.c | 22 ++--------- drivers/net/pcmcia/fmvj18x_cs.c | 16 +------- drivers/net/pcmcia/ibmtr_cs.c | 21 ++-------- drivers/net/pcmcia/nmclan_cs.c | 14 +------ drivers/net/pcmcia/pcnet_cs.c | 14 +------ drivers/net/pcmcia/smc91c92_cs.c | 15 +------ drivers/net/pcmcia/xirc2ps_cs.c | 24 +----------- drivers/net/wireless/airo_cs.c | 28 ++----------- drivers/net/wireless/atmel_cs.c | 25 ++---------- drivers/net/wireless/hostap/hostap_cs.c | 15 +------ drivers/net/wireless/netwave_cs.c | 52 +++++-------------------- drivers/net/wireless/orinoco_cs.c | 21 +--------- drivers/net/wireless/spectrum_cs.c | 11 +----- drivers/net/wireless/wavelan_cs.c | 24 +----------- drivers/net/wireless/wavelan_cs.p.h | 1 - drivers/parport/parport_cs.c | 14 +------ drivers/scsi/pcmcia/fdomain_stub.c | 26 +++---------- drivers/scsi/pcmcia/nsp_cs.c | 19 +-------- drivers/scsi/pcmcia/qlogic_stub.c | 16 +------- drivers/scsi/pcmcia/sym53c500_cs.c | 14 +------ drivers/serial/serial_cs.c | 17 +------- drivers/telephony/ixj_pcmcia.c | 14 +------ drivers/usb/host/sl811_cs.c | 16 +------- 38 files changed, 74 insertions(+), 647 deletions(-) diff --git a/drivers/bluetooth/bluecard_cs.c b/drivers/bluetooth/bluecard_cs.c index f5088cb3812b..bd80535646fa 100644 --- a/drivers/bluetooth/bluecard_cs.c +++ b/drivers/bluetooth/bluecard_cs.c @@ -94,8 +94,6 @@ static dev_info_t dev_info = "bluecard_cs"; static dev_link_t *bluecard_attach(void); static void bluecard_detach(struct pcmcia_device *p_dev); -static dev_link_t *dev_list = NULL; - /* Default baud rate: 57600, 115200, 230400 or 460800 */ #define DEFAULT_BAUD_RATE 230400 @@ -890,8 +888,7 @@ static dev_link_t *bluecard_attach(void) link->conf.IntType = INT_MEMORY_AND_IO; /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; @@ -911,22 +908,10 @@ static void bluecard_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); bluecard_info_t *info = link->priv; - dev_link_t **linkp; - - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) - break; - - if (*linkp == NULL) - return; if (link->state & DEV_CONFIG) bluecard_release(link); - /* Unlink device structure, free bits */ - *linkp = link->next; - kfree(info); } @@ -1105,7 +1090,6 @@ static int __init init_bluecard_cs(void) static void __exit exit_bluecard_cs(void) { pcmcia_unregister_driver(&bluecard_driver); - BUG_ON(dev_list != NULL); } module_init(init_bluecard_cs); diff --git a/drivers/bluetooth/bt3c_cs.c b/drivers/bluetooth/bt3c_cs.c index 02ce38e33d32..50aa52b3cd20 100644 --- a/drivers/bluetooth/bt3c_cs.c +++ b/drivers/bluetooth/bt3c_cs.c @@ -97,8 +97,6 @@ static dev_info_t dev_info = "bt3c_cs"; static dev_link_t *bt3c_attach(void); static void bt3c_detach(struct pcmcia_device *p_dev); -static dev_link_t *dev_list = NULL; - /* Transmit states */ #define XMIT_SENDING 1 @@ -691,8 +689,7 @@ static dev_link_t *bt3c_attach(void) link->conf.IntType = INT_MEMORY_AND_IO; /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; @@ -712,22 +709,10 @@ static void bt3c_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); bt3c_info_t *info = link->priv; - dev_link_t **linkp; - - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) - break; - - if (*linkp == NULL) - return; if (link->state & DEV_CONFIG) bt3c_release(link); - /* Unlink device structure, free bits */ - *linkp = link->next; - kfree(info); } @@ -949,7 +934,6 @@ static int __init init_bt3c_cs(void) static void __exit exit_bt3c_cs(void) { pcmcia_unregister_driver(&bt3c_driver); - BUG_ON(dev_list != NULL); } module_init(init_bt3c_cs); diff --git a/drivers/bluetooth/btuart_cs.c b/drivers/bluetooth/btuart_cs.c index 63221d383fda..7b04f89f7a71 100644 --- a/drivers/bluetooth/btuart_cs.c +++ b/drivers/bluetooth/btuart_cs.c @@ -93,8 +93,6 @@ static dev_info_t dev_info = "btuart_cs"; static dev_link_t *btuart_attach(void); static void btuart_detach(struct pcmcia_device *p_dev); -static dev_link_t *dev_list = NULL; - /* Maximum baud rate */ #define SPEED_MAX 115200 @@ -610,8 +608,7 @@ static dev_link_t *btuart_attach(void) link->conf.IntType = INT_MEMORY_AND_IO; /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; @@ -631,22 +628,10 @@ static void btuart_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); btuart_info_t *info = link->priv; - dev_link_t **linkp; - - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) - break; - - if (*linkp == NULL) - return; if (link->state & DEV_CONFIG) btuart_release(link); - /* Unlink device structure, free bits */ - *linkp = link->next; - kfree(info); } @@ -870,7 +855,6 @@ static int __init init_btuart_cs(void) static void __exit exit_btuart_cs(void) { pcmcia_unregister_driver(&btuart_driver); - BUG_ON(dev_list != NULL); } module_init(init_btuart_cs); diff --git a/drivers/bluetooth/dtl1_cs.c b/drivers/bluetooth/dtl1_cs.c index 2874d8722be9..c39d4576cfff 100644 --- a/drivers/bluetooth/dtl1_cs.c +++ b/drivers/bluetooth/dtl1_cs.c @@ -96,8 +96,6 @@ static dev_info_t dev_info = "dtl1_cs"; static dev_link_t *dtl1_attach(void); static void dtl1_detach(struct pcmcia_device *p_dev); -static dev_link_t *dev_list = NULL; - /* Transmit states */ #define XMIT_SENDING 1 @@ -589,8 +587,7 @@ static dev_link_t *dtl1_attach(void) link->conf.IntType = INT_MEMORY_AND_IO; /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; @@ -610,22 +607,10 @@ static void dtl1_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); dtl1_info_t *info = link->priv; - dev_link_t **linkp; - - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) - break; - - if (*linkp == NULL) - return; if (link->state & DEV_CONFIG) dtl1_release(link); - /* Unlink device structure, free bits */ - *linkp = link->next; - kfree(info); } @@ -822,7 +807,6 @@ static int __init init_dtl1_cs(void) static void __exit exit_dtl1_cs(void) { pcmcia_unregister_driver(&dtl1_driver); - BUG_ON(dev_list != NULL); } module_init(init_dtl1_cs); diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c index 34597144d9c1..dc38b1d0a725 100644 --- a/drivers/char/pcmcia/synclink_cs.c +++ b/drivers/char/pcmcia/synclink_cs.c @@ -492,7 +492,6 @@ static dev_link_t *mgslpc_attach(void); static void mgslpc_detach(struct pcmcia_device *p_dev); static dev_info_t dev_info = "synclink_cs"; -static dev_link_t *dev_list = NULL; /* * 1st function defined in .text section. Calling this function in @@ -588,8 +587,7 @@ static dev_link_t *mgslpc_attach(void) link->conf.IntType = INT_MEMORY_AND_IO; /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; @@ -741,24 +739,15 @@ static void mgslpc_release(u_long arg) static void mgslpc_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); - dev_link_t **linkp; if (debug_level >= DEBUG_LEVEL_INFO) printk("mgslpc_detach(0x%p)\n", link); - /* find device */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) break; - if (*linkp == NULL) - return; - if (link->state & DEV_CONFIG) { ((MGSLPC_INFO *)link->priv)->stop = 1; mgslpc_release((u_long)link); } - /* Unlink device structure, and free it */ - *linkp = link->next; mgslpc_remove_device((MGSLPC_INFO *)link->priv); } @@ -3131,7 +3120,6 @@ static void synclink_cs_cleanup(void) } pcmcia_unregister_driver(&mgslpc_driver); - BUG_ON(dev_list != NULL); } static int __init synclink_cs_init(void) diff --git a/drivers/ide/legacy/ide-cs.c b/drivers/ide/legacy/ide-cs.c index 1fb8976496d9..c83068dd42a0 100644 --- a/drivers/ide/legacy/ide-cs.c +++ b/drivers/ide/legacy/ide-cs.c @@ -96,7 +96,8 @@ static dev_info_t dev_info = "ide-cs"; static dev_link_t *ide_attach(void); static void ide_detach(struct pcmcia_device *p_dev); -static dev_link_t *dev_list = NULL; + + /*====================================================================== @@ -130,8 +131,7 @@ static dev_link_t *ide_attach(void) link->conf.IntType = INT_MEMORY_AND_IO; /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; @@ -157,23 +157,13 @@ static dev_link_t *ide_attach(void) static void ide_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); - dev_link_t **linkp; DEBUG(0, "ide_detach(0x%p)\n", link); - - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) break; - if (*linkp == NULL) - return; if (link->state & DEV_CONFIG) ide_release(link); - - /* Unlink, free device structure */ - *linkp = link->next; + kfree(link->priv); - } /* ide_detach */ static int idecs_register(unsigned long io, unsigned long ctl, unsigned long irq, struct pcmcia_device *handle) @@ -507,7 +497,6 @@ static int __init init_ide_cs(void) static void __exit exit_ide_cs(void) { pcmcia_unregister_driver(&ide_cs_driver); - BUG_ON(dev_list != NULL); } late_initcall(init_ide_cs); diff --git a/drivers/isdn/hardware/avm/avm_cs.c b/drivers/isdn/hardware/avm/avm_cs.c index 2d898d3afc97..0a8c1da10b4b 100644 --- a/drivers/isdn/hardware/avm/avm_cs.c +++ b/drivers/isdn/hardware/avm/avm_cs.c @@ -83,15 +83,7 @@ static dev_info_t dev_info = "avm_cs"; device numbers are used to derive the corresponding array index. */ -static dev_link_t *dev_list = NULL; - /* - A dev_link_t structure has fields for most things that are needed - to keep track of a socket, but there will usually be some device - specific information that also needs to be kept track of. The - 'priv' pointer in a dev_link_t structure can be used to point to - a device-specific private data structure, like this. - A driver needs to provide a dev_node_t structure for each device on a card. In some cases, there is only one device per card (for example, ethernet cards, modems). In other cases, there may be @@ -157,8 +149,7 @@ static dev_link_t *avmcs_attach(void) link->priv = local; /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; @@ -188,19 +179,10 @@ static dev_link_t *avmcs_attach(void) static void avmcs_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); - dev_link_t **linkp; - - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) break; - if (*linkp == NULL) - return; if (link->state & DEV_CONFIG) avmcs_release(link); - /* Unlink device structure, free pieces */ - *linkp = link->next; kfree(link->priv); kfree(link); } /* avmcs_detach */ @@ -494,7 +476,6 @@ static int __init avmcs_init(void) static void __exit avmcs_exit(void) { pcmcia_unregister_driver(&avmcs_driver); - BUG_ON(dev_list != NULL); } module_init(avmcs_init); diff --git a/drivers/isdn/hisax/avma1_cs.c b/drivers/isdn/hisax/avma1_cs.c index 6b322e88c6c3..b6ea653f881e 100644 --- a/drivers/isdn/hisax/avma1_cs.c +++ b/drivers/isdn/hisax/avma1_cs.c @@ -99,15 +99,7 @@ static dev_info_t dev_info = "avma1_cs"; device numbers are used to derive the corresponding array index. */ -static dev_link_t *dev_list = NULL; - /* - A dev_link_t structure has fields for most things that are needed - to keep track of a socket, but there will usually be some device - specific information that also needs to be kept track of. The - 'priv' pointer in a dev_link_t structure can be used to point to - a device-specific private data structure, like this. - A driver needs to provide a dev_node_t structure for each device on a card. In some cases, there is only one device per card (for example, ethernet cards, modems). In other cases, there may be @@ -179,8 +171,7 @@ static dev_link_t *avma1cs_attach(void) link->conf.Present = PRESENT_OPTION; /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; @@ -206,21 +197,12 @@ static dev_link_t *avma1cs_attach(void) static void avma1cs_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); - dev_link_t **linkp; DEBUG(0, "avma1cs_detach(0x%p)\n", link); - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) break; - if (*linkp == NULL) - return; - if (link->state & DEV_CONFIG) avma1cs_release(link); - /* Unlink device structure, free pieces */ - *linkp = link->next; kfree(link->priv); kfree(link); } /* avma1cs_detach */ @@ -508,7 +490,6 @@ static int __init init_avma1_cs(void) static void __exit exit_avma1_cs(void) { pcmcia_unregister_driver(&avma1cs_driver); - BUG_ON(dev_list != NULL); } module_init(init_avma1_cs); diff --git a/drivers/isdn/hisax/elsa_cs.c b/drivers/isdn/hisax/elsa_cs.c index 48cc677249f1..a0c5bad7bc6b 100644 --- a/drivers/isdn/hisax/elsa_cs.c +++ b/drivers/isdn/hisax/elsa_cs.c @@ -126,18 +126,7 @@ static dev_info_t dev_info = "elsa_cs"; device numbers are used to derive the corresponding array index. */ -static dev_link_t *dev_list = NULL; - /* - A dev_link_t structure has fields for most things that are needed - to keep track of a socket, but there will usually be some device - specific information that also needs to be kept track of. The - 'priv' pointer in a dev_link_t structure can be used to point to - a device-specific private data structure, like this. - - To simplify the data structure handling, we actually include the - dev_link_t structure in the device's private data structure. - A driver needs to provide a dev_node_t structure for each device on a card. In some cases, there is only one device per card (for example, ethernet cards, modems). In other cases, there may be @@ -208,8 +197,7 @@ static dev_link_t *elsa_cs_attach(void) link->conf.IntType = INT_MEMORY_AND_IO; /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; @@ -235,24 +223,15 @@ static dev_link_t *elsa_cs_attach(void) static void elsa_cs_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); - dev_link_t **linkp; local_info_t *info = link->priv; DEBUG(0, "elsa_cs_detach(0x%p)\n", link); - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) break; - if (*linkp == NULL) - return; - if (link->state & DEV_CONFIG) { - ((local_info_t*)link->priv)->busy = 1; - elsa_cs_release(link); + info->busy = 1; + elsa_cs_release(link); } - /* Unlink device structure and free it */ - *linkp = link->next; kfree(info); } /* elsa_cs_detach */ @@ -526,7 +505,6 @@ static int __init init_elsa_cs(void) static void __exit exit_elsa_cs(void) { pcmcia_unregister_driver(&elsa_cs_driver); - BUG_ON(dev_list != NULL); } module_init(init_elsa_cs); diff --git a/drivers/isdn/hisax/sedlbauer_cs.c b/drivers/isdn/hisax/sedlbauer_cs.c index d2386f6867b7..814b32a9ef3b 100644 --- a/drivers/isdn/hisax/sedlbauer_cs.c +++ b/drivers/isdn/hisax/sedlbauer_cs.c @@ -134,18 +134,7 @@ static dev_info_t dev_info = "sedlbauer_cs"; device numbers are used to derive the corresponding array index. */ -static dev_link_t *dev_list = NULL; - /* - A dev_link_t structure has fields for most things that are needed - to keep track of a socket, but there will usually be some device - specific information that also needs to be kept track of. The - 'priv' pointer in a dev_link_t structure can be used to point to - a device-specific private data structure, like this. - - To simplify the data structure handling, we actually include the - dev_link_t structure in the device's private data structure. - A driver needs to provide a dev_node_t structure for each device on a card. In some cases, there is only one device per card (for example, ethernet cards, modems). In other cases, there may be @@ -222,8 +211,7 @@ static dev_link_t *sedlbauer_attach(void) link->conf.IntType = INT_MEMORY_AND_IO; /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; @@ -249,23 +237,14 @@ static dev_link_t *sedlbauer_attach(void) static void sedlbauer_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); - dev_link_t **linkp; DEBUG(0, "sedlbauer_detach(0x%p)\n", link); - - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) break; - if (*linkp == NULL) - return; if (link->state & DEV_CONFIG) { - ((local_info_t *)link->priv)->stop = 1; - sedlbauer_release(link); + ((local_info_t *)link->priv)->stop = 1; + sedlbauer_release(link); } - /* Unlink device structure, and free it */ - *linkp = link->next; /* This points to the parent local_info_t struct */ kfree(link->priv); } /* sedlbauer_detach */ @@ -623,7 +602,6 @@ static int __init init_sedlbauer_cs(void) static void __exit exit_sedlbauer_cs(void) { pcmcia_unregister_driver(&sedlbauer_driver); - BUG_ON(dev_list != NULL); } module_init(init_sedlbauer_cs); diff --git a/drivers/isdn/hisax/teles_cs.c b/drivers/isdn/hisax/teles_cs.c index cd0f86f0975b..f956fceb9db2 100644 --- a/drivers/isdn/hisax/teles_cs.c +++ b/drivers/isdn/hisax/teles_cs.c @@ -107,18 +107,7 @@ static dev_info_t dev_info = "teles_cs"; device numbers are used to derive the corresponding array index. */ -static dev_link_t *dev_list = NULL; - /* - A dev_link_t structure has fields for most things that are needed - to keep track of a socket, but there will usually be some device - specific information that also needs to be kept track of. The - 'priv' pointer in a dev_link_t structure can be used to point to - a device-specific private data structure, like this. - - To simplify the data structure handling, we actually include the - dev_link_t structure in the device's private data structure. - A driver needs to provide a dev_node_t structure for each device on a card. In some cases, there is only one device per card (for example, ethernet cards, modems). In other cases, there may be @@ -189,8 +178,7 @@ static dev_link_t *teles_attach(void) link->conf.IntType = INT_MEMORY_AND_IO; /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; @@ -216,24 +204,15 @@ static dev_link_t *teles_attach(void) static void teles_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); - dev_link_t **linkp; local_info_t *info = link->priv; DEBUG(0, "teles_detach(0x%p)\n", link); - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) break; - if (*linkp == NULL) - return; - if (link->state & DEV_CONFIG) { - info->busy = 1; - teles_cs_release(link); + info->busy = 1; + teles_cs_release(link); } - /* Unlink device structure and free it */ - *linkp = link->next; kfree(info); } /* teles_detach */ @@ -506,7 +485,6 @@ static int __init init_teles_cs(void) static void __exit exit_teles_cs(void) { pcmcia_unregister_driver(&teles_cs_driver); - BUG_ON(dev_list != NULL); } module_init(init_teles_cs); diff --git a/drivers/mtd/maps/pcmciamtd.c b/drivers/mtd/maps/pcmciamtd.c index 3ddcb1bf6824..93c05dfa030d 100644 --- a/drivers/mtd/maps/pcmciamtd.c +++ b/drivers/mtd/maps/pcmciamtd.c @@ -67,7 +67,6 @@ struct pcmciamtd_dev { static dev_info_t dev_info = "pcmciamtd"; -static dev_link_t *dev_list; /* Module parameters */ @@ -782,8 +781,7 @@ static dev_link_t *pcmciamtd_attach(void) link->conf.Attributes = 0; link->conf.IntType = INT_MEMORY; - link->next = dev_list; - dev_list = link; + link->next = NULL; /* Register with Card Services */ client_reg.dev_info = &dev_info; @@ -865,7 +863,6 @@ static void __exit exit_pcmciamtd(void) { DEBUG(1, DRIVER_DESC " unloading"); pcmcia_unregister_driver(&pcmciamtd_driver); - BUG_ON(dev_list != NULL); } module_init(init_pcmciamtd); diff --git a/drivers/net/pcmcia/3c574_cs.c b/drivers/net/pcmcia/3c574_cs.c index 60a3bc2b8fc4..8fcb63698ef1 100644 --- a/drivers/net/pcmcia/3c574_cs.c +++ b/drivers/net/pcmcia/3c574_cs.c @@ -255,8 +255,6 @@ static dev_info_t dev_info = "3c574_cs"; static dev_link_t *tc574_attach(void); static void tc574_detach(struct pcmcia_device *p_dev); -static dev_link_t *dev_list; - /* tc574_attach() creates an "instance" of the driver, allocating local data structures for one device. The device is registered @@ -308,8 +306,7 @@ static dev_link_t *tc574_attach(void) #endif /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; @@ -336,24 +333,15 @@ static void tc574_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); struct net_device *dev = link->priv; - dev_link_t **linkp; DEBUG(0, "3c574_detach(0x%p)\n", link); - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) break; - if (*linkp == NULL) - return; - if (link->dev) unregister_netdev(dev); if (link->state & DEV_CONFIG) tc574_release(link); - /* Unlink device structure, free bits */ - *linkp = link->next; free_netdev(dev); } /* tc574_detach */ @@ -1310,7 +1298,6 @@ static int __init init_tc574(void) static void __exit exit_tc574(void) { pcmcia_unregister_driver(&tc574_driver); - BUG_ON(dev_list != NULL); } module_init(init_tc574); diff --git a/drivers/net/pcmcia/3c589_cs.c b/drivers/net/pcmcia/3c589_cs.c index 09b96c76216e..3516c02b9c89 100644 --- a/drivers/net/pcmcia/3c589_cs.c +++ b/drivers/net/pcmcia/3c589_cs.c @@ -166,8 +166,6 @@ static dev_info_t dev_info = "3c589_cs"; static dev_link_t *tc589_attach(void); static void tc589_detach(struct pcmcia_device *p_dev); -static dev_link_t *dev_list; - /*====================================================================== tc589_attach() creates an "instance" of the driver, allocating @@ -222,8 +220,7 @@ static dev_link_t *tc589_attach(void) SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops); /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; @@ -250,15 +247,8 @@ static void tc589_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); struct net_device *dev = link->priv; - dev_link_t **linkp; - + DEBUG(0, "3c589_detach(0x%p)\n", link); - - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) break; - if (*linkp == NULL) - return; if (link->dev) unregister_netdev(dev); @@ -266,8 +256,6 @@ static void tc589_detach(struct pcmcia_device *p_dev) if (link->state & DEV_CONFIG) tc589_release(link); - /* Unlink device structure, free bits */ - *linkp = link->next; free_netdev(dev); } /* tc589_detach */ @@ -1085,7 +1073,6 @@ static int __init init_tc589(void) static void __exit exit_tc589(void) { pcmcia_unregister_driver(&tc589_driver); - BUG_ON(dev_list != NULL); } module_init(init_tc589); diff --git a/drivers/net/pcmcia/axnet_cs.c b/drivers/net/pcmcia/axnet_cs.c index 11f701a8ff02..3d36207d3332 100644 --- a/drivers/net/pcmcia/axnet_cs.c +++ b/drivers/net/pcmcia/axnet_cs.c @@ -111,7 +111,6 @@ static dev_link_t *axnet_attach(void); static void axnet_detach(struct pcmcia_device *p_dev); static dev_info_t dev_info = "axnet_cs"; -static dev_link_t *dev_list; static void axdev_setup(struct net_device *dev); static void AX88190_init(struct net_device *dev, int startp); @@ -177,8 +176,7 @@ static dev_link_t *axnet_attach(void) SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops); /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; @@ -205,24 +203,15 @@ static void axnet_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); struct net_device *dev = link->priv; - dev_link_t **linkp; DEBUG(0, "axnet_detach(0x%p)\n", link); - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) break; - if (*linkp == NULL) - return; - if (link->dev) unregister_netdev(dev); if (link->state & DEV_CONFIG) axnet_release(link); - /* Unlink device structure, free bits */ - *linkp = link->next; free_netdev(dev); } /* axnet_detach */ @@ -896,7 +885,6 @@ static int __init init_axnet_cs(void) static void __exit exit_axnet_cs(void) { pcmcia_unregister_driver(&axnet_cs_driver); - BUG_ON(dev_list != NULL); } module_init(init_axnet_cs); diff --git a/drivers/net/pcmcia/com20020_cs.c b/drivers/net/pcmcia/com20020_cs.c index 6970888cba10..d48dbd3e153a 100644 --- a/drivers/net/pcmcia/com20020_cs.c +++ b/drivers/net/pcmcia/com20020_cs.c @@ -128,8 +128,6 @@ static dev_info_t dev_info = "com20020_cs"; static dev_link_t *com20020_attach(void); static void com20020_detach(struct pcmcia_device *p_dev); -static dev_link_t *dev_list; - /*====================================================================*/ typedef struct com20020_dev_t { @@ -196,8 +194,7 @@ static dev_link_t *com20020_attach(void) link->priv = info; /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; @@ -230,26 +227,17 @@ static void com20020_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); struct com20020_dev_t *info = link->priv; - dev_link_t **linkp; - struct net_device *dev; - + struct net_device *dev = info->dev; + DEBUG(1,"detach...\n"); DEBUG(0, "com20020_detach(0x%p)\n", link); - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) break; - if (*linkp == NULL) - return; - - dev = info->dev; - if (link->dev) { DEBUG(1,"unregister...\n"); unregister_netdev(dev); - + /* * this is necessary because we register our IRQ separately * from card services. @@ -263,7 +251,6 @@ static void com20020_detach(struct pcmcia_device *p_dev) /* Unlink device structure, free bits */ DEBUG(1,"unlinking...\n"); - *linkp = link->next; if (link->priv) { dev = info->dev; @@ -507,7 +494,6 @@ static int __init init_com20020_cs(void) static void __exit exit_com20020_cs(void) { pcmcia_unregister_driver(&com20020_cs_driver); - BUG_ON(dev_list != NULL); } module_init(init_com20020_cs); diff --git a/drivers/net/pcmcia/fmvj18x_cs.c b/drivers/net/pcmcia/fmvj18x_cs.c index 560d4ee22803..dad6393052ff 100644 --- a/drivers/net/pcmcia/fmvj18x_cs.c +++ b/drivers/net/pcmcia/fmvj18x_cs.c @@ -109,7 +109,6 @@ static void fjn_tx_timeout(struct net_device *dev); static struct ethtool_ops netdev_ethtool_ops; static dev_info_t dev_info = "fmvj18x_cs"; -static dev_link_t *dev_list; /* card type @@ -283,8 +282,7 @@ static dev_link_t *fmvj18x_attach(void) SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops); /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; @@ -304,15 +302,8 @@ static void fmvj18x_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); struct net_device *dev = link->priv; - dev_link_t **linkp; - + DEBUG(0, "fmvj18x_detach(0x%p)\n", link); - - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) break; - if (*linkp == NULL) - return; if (link->dev) unregister_netdev(dev); @@ -320,8 +311,6 @@ static void fmvj18x_detach(struct pcmcia_device *p_dev) if (link->state & DEV_CONFIG) fmvj18x_release(link); - /* Unlink device structure, free pieces */ - *linkp = link->next; free_netdev(dev); } /* fmvj18x_detach */ @@ -807,7 +796,6 @@ static int __init init_fmvj18x_cs(void) static void __exit exit_fmvj18x_cs(void) { pcmcia_unregister_driver(&fmvj18x_cs_driver); - BUG_ON(dev_list != NULL); } module_init(init_fmvj18x_cs); diff --git a/drivers/net/pcmcia/ibmtr_cs.c b/drivers/net/pcmcia/ibmtr_cs.c index 961294983354..90da35d1f4a5 100644 --- a/drivers/net/pcmcia/ibmtr_cs.c +++ b/drivers/net/pcmcia/ibmtr_cs.c @@ -116,8 +116,6 @@ static dev_info_t dev_info = "ibmtr_cs"; static dev_link_t *ibmtr_attach(void); static void ibmtr_detach(struct pcmcia_device *p_dev); -static dev_link_t *dev_list; - /*====================================================================*/ typedef struct ibmtr_dev_t { @@ -186,8 +184,7 @@ static dev_link_t *ibmtr_attach(void) SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops); /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; @@ -219,19 +216,10 @@ static void ibmtr_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); struct ibmtr_dev_t *info = link->priv; - dev_link_t **linkp; - struct net_device *dev; + struct net_device *dev = info->dev; DEBUG(0, "ibmtr_detach(0x%p)\n", link); - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) break; - if (*linkp == NULL) - return; - - dev = info->dev; - if (link->dev) unregister_netdev(dev); @@ -242,10 +230,8 @@ static void ibmtr_detach(struct pcmcia_device *p_dev) if (link->state & DEV_CONFIG) ibmtr_release(link); - /* Unlink device structure, free bits */ - *linkp = link->next; free_netdev(dev); - kfree(info); + kfree(info); } /* ibmtr_detach */ /*====================================================================== @@ -530,7 +516,6 @@ static int __init init_ibmtr_cs(void) static void __exit exit_ibmtr_cs(void) { pcmcia_unregister_driver(&ibmtr_cs_driver); - BUG_ON(dev_list != NULL); } module_init(init_ibmtr_cs); diff --git a/drivers/net/pcmcia/nmclan_cs.c b/drivers/net/pcmcia/nmclan_cs.c index 011ceb090320..0c9cb9f49a81 100644 --- a/drivers/net/pcmcia/nmclan_cs.c +++ b/drivers/net/pcmcia/nmclan_cs.c @@ -389,7 +389,6 @@ DRV_NAME " " DRV_VERSION " (Roger C. Pao)"; #endif static dev_info_t dev_info="nmclan_cs"; -static dev_link_t *dev_list; static char *if_names[]={ "Auto", "10baseT", "BNC", @@ -498,8 +497,7 @@ static dev_link_t *nmclan_attach(void) #endif /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; @@ -525,24 +523,15 @@ static void nmclan_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); struct net_device *dev = link->priv; - dev_link_t **linkp; DEBUG(0, "nmclan_detach(0x%p)\n", link); - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) break; - if (*linkp == NULL) - return; - if (link->dev) unregister_netdev(dev); if (link->state & DEV_CONFIG) nmclan_release(link); - /* Unlink device structure, free bits */ - *linkp = link->next; free_netdev(dev); } /* nmclan_detach */ @@ -1700,7 +1689,6 @@ static int __init init_nmclan_cs(void) static void __exit exit_nmclan_cs(void) { pcmcia_unregister_driver(&nmclan_cs_driver); - BUG_ON(dev_list != NULL); } module_init(init_nmclan_cs); diff --git a/drivers/net/pcmcia/pcnet_cs.c b/drivers/net/pcmcia/pcnet_cs.c index fb3e411d6daf..b35c951fc6fa 100644 --- a/drivers/net/pcmcia/pcnet_cs.c +++ b/drivers/net/pcmcia/pcnet_cs.c @@ -124,7 +124,6 @@ static dev_link_t *pcnet_attach(void); static void pcnet_detach(struct pcmcia_device *p_dev); static dev_info_t dev_info = "pcnet_cs"; -static dev_link_t *dev_list; /*====================================================================*/ @@ -272,8 +271,7 @@ static dev_link_t *pcnet_attach(void) dev->set_config = &set_config; /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; @@ -300,24 +298,15 @@ static void pcnet_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); struct net_device *dev = link->priv; - dev_link_t **linkp; DEBUG(0, "pcnet_detach(0x%p)\n", link); - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) break; - if (*linkp == NULL) - return; - if (link->dev) unregister_netdev(dev); if (link->state & DEV_CONFIG) pcnet_release(link); - /* Unlink device structure, free bits */ - *linkp = link->next; free_netdev(dev); } /* pcnet_detach */ @@ -1864,7 +1853,6 @@ static void __exit exit_pcnet_cs(void) { DEBUG(0, "pcnet_cs: unloading\n"); pcmcia_unregister_driver(&pcnet_driver); - BUG_ON(dev_list != NULL); } module_init(init_pcnet_cs); diff --git a/drivers/net/pcmcia/smc91c92_cs.c b/drivers/net/pcmcia/smc91c92_cs.c index 6cb5198d6094..9eb5cecfb2f5 100644 --- a/drivers/net/pcmcia/smc91c92_cs.c +++ b/drivers/net/pcmcia/smc91c92_cs.c @@ -104,8 +104,6 @@ static const char *version = static dev_info_t dev_info = "smc91c92_cs"; -static dev_link_t *dev_list; - struct smc_private { dev_link_t link; spinlock_t lock; @@ -367,8 +365,7 @@ static dev_link_t *smc91c92_attach(void) smc->mii_if.reg_num_mask = 0x1f; /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; @@ -395,24 +392,15 @@ static void smc91c92_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); struct net_device *dev = link->priv; - dev_link_t **linkp; DEBUG(0, "smc91c92_detach(0x%p)\n", link); - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) break; - if (*linkp == NULL) - return; - if (link->dev) unregister_netdev(dev); if (link->state & DEV_CONFIG) smc91c92_release(link); - /* Unlink device structure, free bits */ - *linkp = link->next; free_netdev(dev); } /* smc91c92_detach */ @@ -2377,7 +2365,6 @@ static int __init init_smc91c92_cs(void) static void __exit exit_smc91c92_cs(void) { pcmcia_unregister_driver(&smc91c92_cs_driver); - BUG_ON(dev_list != NULL); } module_init(init_smc91c92_cs); diff --git a/drivers/net/pcmcia/xirc2ps_cs.c b/drivers/net/pcmcia/xirc2ps_cs.c index 804e56771baf..8c8cc40bbb7d 100644 --- a/drivers/net/pcmcia/xirc2ps_cs.c +++ b/drivers/net/pcmcia/xirc2ps_cs.c @@ -331,15 +331,7 @@ static dev_info_t dev_info = "xirc2ps_cs"; * device numbers are used to derive the corresponding array index. */ -static dev_link_t *dev_list; - /**************** - * A dev_link_t structure has fields for most things that are needed - * to keep track of a socket, but there will usually be some device - * specific information that also needs to be kept track of. The - * 'priv' pointer in a dev_link_t structure can be used to point to - * a device-specific private data structure, like this. - * * A driver needs to provide a dev_node_t structure for each device * on a card. In some cases, there is only one device per card (for * example, ethernet cards, modems). In other cases, there may be @@ -615,8 +607,7 @@ xirc2ps_attach(void) #endif /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; @@ -641,27 +632,15 @@ xirc2ps_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); struct net_device *dev = link->priv; - dev_link_t **linkp; DEBUG(0, "detach(0x%p)\n", link); - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) - break; - if (!*linkp) { - DEBUG(0, "detach(0x%p): dev_link lost\n", link); - return; - } - if (link->dev) unregister_netdev(dev); if (link->state & DEV_CONFIG) xirc2ps_release(link); - /* Unlink device structure, free it */ - *linkp = link->next; free_netdev(dev); } /* xirc2ps_detach */ @@ -2020,7 +1999,6 @@ static void __exit exit_xirc2ps_cs(void) { pcmcia_unregister_driver(&xirc2ps_cs_driver); - BUG_ON(dev_list != NULL); } module_init(init_xirc2ps_cs); diff --git a/drivers/net/wireless/airo_cs.c b/drivers/net/wireless/airo_cs.c index 7a28139544c0..88805a4c29f1 100644 --- a/drivers/net/wireless/airo_cs.c +++ b/drivers/net/wireless/airo_cs.c @@ -119,15 +119,7 @@ static dev_info_t dev_info = "airo_cs"; device numbers are used to derive the corresponding array index. */ -static dev_link_t *dev_list = NULL; - /* - A dev_link_t structure has fields for most things that are needed - to keep track of a socket, but there will usually be some device - specific information that also needs to be kept track of. The - 'priv' pointer in a dev_link_t structure can be used to point to - a device-specific private data structure, like this. - A driver needs to provide a dev_node_t structure for each device on a card. In some cases, there is only one device per card (for example, ethernet cards, modems). In other cases, there may be @@ -202,8 +194,7 @@ static dev_link_t *airo_attach(void) link->priv = local; /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; @@ -229,29 +220,19 @@ static dev_link_t *airo_attach(void) static void airo_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); - dev_link_t **linkp; - + DEBUG(0, "airo_detach(0x%p)\n", link); - - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) break; - if (*linkp == NULL) - return; - + if (link->state & DEV_CONFIG) airo_release(link); - + if ( ((local_info_t*)link->priv)->eth_dev ) { stop_airo_card( ((local_info_t*)link->priv)->eth_dev, 0 ); } ((local_info_t*)link->priv)->eth_dev = NULL; - /* Unlink device structure, free pieces */ - *linkp = link->next; kfree(link->priv); kfree(link); - } /* airo_detach */ /*====================================================================== @@ -574,7 +555,6 @@ static int airo_cs_init(void) static void airo_cs_cleanup(void) { pcmcia_unregister_driver(&airo_driver); - BUG_ON(dev_list != NULL); } /* diff --git a/drivers/net/wireless/atmel_cs.c b/drivers/net/wireless/atmel_cs.c index 3ab33dd49ea2..32f009709355 100644 --- a/drivers/net/wireless/atmel_cs.c +++ b/drivers/net/wireless/atmel_cs.c @@ -130,15 +130,7 @@ static dev_info_t dev_info = "atmel_cs"; device numbers are used to derive the corresponding array index. */ -static dev_link_t *dev_list = NULL; - /* - A dev_link_t structure has fields for most things that are needed - to keep track of a socket, but there will usually be some device - specific information that also needs to be kept track of. The - 'priv' pointer in a dev_link_t structure can be used to point to - a device-specific private data structure, like this. - A driver needs to provide a dev_node_t structure for each device on a card. In some cases, there is only one device per card (for example, ethernet cards, modems). In other cases, there may be @@ -213,8 +205,7 @@ static dev_link_t *atmel_attach(void) link->priv = local; /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; @@ -240,21 +231,12 @@ static dev_link_t *atmel_attach(void) static void atmel_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); - dev_link_t **linkp; - + DEBUG(0, "atmel_detach(0x%p)\n", link); - - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) break; - if (*linkp == NULL) - return; if (link->state & DEV_CONFIG) atmel_release(link); - - /* Unlink device structure, free pieces */ - *linkp = link->next; + kfree(link->priv); kfree(link); } @@ -596,7 +578,6 @@ static int atmel_cs_init(void) static void atmel_cs_cleanup(void) { pcmcia_unregister_driver(&atmel_driver); - BUG_ON(dev_list != NULL); } /* diff --git a/drivers/net/wireless/hostap/hostap_cs.c b/drivers/net/wireless/hostap/hostap_cs.c index 866142af7d92..195a5bf3d725 100644 --- a/drivers/net/wireless/hostap/hostap_cs.c +++ b/drivers/net/wireless/hostap/hostap_cs.c @@ -25,7 +25,6 @@ static char *version = PRISM2_VERSION " (Jouni Malinen )"; static dev_info_t dev_info = "hostap_cs"; -static dev_link_t *dev_list = NULL; MODULE_AUTHOR("Jouni Malinen"); MODULE_DESCRIPTION("Support for Intersil Prism2-based 802.11 wireless LAN " @@ -520,8 +519,7 @@ static dev_link_t *prism2_attach(void) link->conf.IntType = INT_MEMORY_AND_IO; /* register with CardServices */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; @@ -538,24 +536,13 @@ static dev_link_t *prism2_attach(void) static void prism2_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); - dev_link_t **linkp; PDEBUG(DEBUG_FLOW, "prism2_detach\n"); - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) - break; - if (*linkp == NULL) { - printk(KERN_WARNING "%s: Attempt to detach non-existing " - "PCMCIA client\n", dev_info); - return; - } - if (link->state & DEV_CONFIG) { prism2_release((u_long)link); } - *linkp = link->next; /* release net devices */ if (link->priv) { struct hostap_cs_priv *hw_priv; diff --git a/drivers/net/wireless/netwave_cs.c b/drivers/net/wireless/netwave_cs.c index 1770677d9e10..af9a32d8d22d 100644 --- a/drivers/net/wireless/netwave_cs.c +++ b/drivers/net/wireless/netwave_cs.c @@ -227,17 +227,6 @@ static struct iw_statistics* netwave_get_wireless_stats(struct net_device *dev); static void set_multicast_list(struct net_device *dev); -/* - A linked list of "instances" of the skeleton device. Each actual - PCMCIA card corresponds to one device instance, and is described - by one dev_link_t structure (defined in ds.h). - - You may not want to use a linked list for this -- for example, the - memory card driver uses an array of dev_link_t pointers, where minor - device numbers are used to derive the corresponding array index. -*/ -static dev_link_t *dev_list; - /* A dev_link_t structure has fields for most things that are needed to keep track of a socket, but there will usually be some device @@ -451,8 +440,7 @@ static dev_link_t *netwave_attach(void) link->irq.Instance = dev; /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; @@ -476,37 +464,18 @@ static dev_link_t *netwave_attach(void) */ static void netwave_detach(struct pcmcia_device *p_dev) { - dev_link_t *link = dev_to_instance(p_dev); - struct net_device *dev = link->priv; - dev_link_t **linkp; + dev_link_t *link = dev_to_instance(p_dev); + struct net_device *dev = link->priv; - DEBUG(0, "netwave_detach(0x%p)\n", link); - - /* - If the device is currently configured and active, we won't - actually delete it yet. Instead, it is marked so that when - the release() function is called, that will trigger a proper - detach(). - */ - if (link->state & DEV_CONFIG) - netwave_release(link); + DEBUG(0, "netwave_detach(0x%p)\n", link); - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) break; - if (*linkp == NULL) - { - DEBUG(1, "netwave_cs: detach fail, '%s' not in list\n", - link->dev->dev_name); - return; - } + if (link->state & DEV_CONFIG) + netwave_release(link); - /* Unlink device structure, free pieces */ - *linkp = link->next; - if (link->dev) - unregister_netdev(dev); - free_netdev(dev); - + if (link->dev) + unregister_netdev(dev); + + free_netdev(dev); } /* netwave_detach */ /* @@ -1503,7 +1472,6 @@ static int __init init_netwave_cs(void) static void __exit exit_netwave_cs(void) { pcmcia_unregister_driver(&netwave_driver); - BUG_ON(dev_list != NULL); } module_init(init_netwave_cs); diff --git a/drivers/net/wireless/orinoco_cs.c b/drivers/net/wireless/orinoco_cs.c index 00679b6c87c1..bfeeef49f0b3 100644 --- a/drivers/net/wireless/orinoco_cs.c +++ b/drivers/net/wireless/orinoco_cs.c @@ -69,12 +69,6 @@ struct orinoco_pccard { unsigned long hard_reset_in_progress; }; -/* - * A linked list of "instances" of the 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 */ /********************************************************************/ /* Function prototypes */ @@ -154,9 +148,7 @@ orinoco_cs_attach(void) link->conf.IntType = INT_MEMORY_AND_IO; /* Register with Card Services */ - /* FIXME: need a lock? */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; /* FIXME: what does this mean? */ @@ -181,21 +173,11 @@ orinoco_cs_attach(void) static void orinoco_cs_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); - dev_link_t **linkp; struct net_device *dev = link->priv; - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) - break; - - BUG_ON(*linkp == NULL); - if (link->state & DEV_CONFIG) orinoco_cs_release(link); - /* Unlink device structure, and free it */ - *linkp = link->next; DEBUG(0, PFX "detach: link=%p link->dev=%p\n", link, link->dev); if (link->dev) { DEBUG(0, PFX "About to unregister net device %p\n", @@ -678,7 +660,6 @@ static void __exit exit_orinoco_cs(void) { pcmcia_unregister_driver(&orinoco_driver); - BUG_ON(dev_list != NULL); } module_init(init_orinoco_cs); diff --git a/drivers/net/wireless/spectrum_cs.c b/drivers/net/wireless/spectrum_cs.c index a2dcab7995c1..1933250dad1a 100644 --- a/drivers/net/wireless/spectrum_cs.c +++ b/drivers/net/wireless/spectrum_cs.c @@ -78,13 +78,6 @@ struct orinoco_pccard { dev_node_t node; }; -/* - * A linked list of "instances" of the 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 */ - /********************************************************************/ /* Function prototypes */ /********************************************************************/ @@ -637,8 +630,7 @@ spectrum_cs_attach(void) /* Register with Card Services */ /* FIXME: need a lock? */ - link->next = dev_list; - dev_list = link; + link->next = NULL; /* not needed */ client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; /* FIXME: what does this mean? */ @@ -1049,7 +1041,6 @@ static void __exit exit_spectrum_cs(void) { pcmcia_unregister_driver(&orinoco_driver); - BUG_ON(dev_list != NULL); } module_init(init_spectrum_cs); diff --git a/drivers/net/wireless/wavelan_cs.c b/drivers/net/wireless/wavelan_cs.c index 255952d8cea0..196e827fc846 100644 --- a/drivers/net/wireless/wavelan_cs.c +++ b/drivers/net/wireless/wavelan_cs.c @@ -4627,8 +4627,7 @@ wavelan_attach(void) link->conf.IntType = INT_MEMORY_AND_IO; /* Chain drivers */ - link->next = dev_list; - dev_list = link; + link->next = NULL; /* Allocate the generic data structure */ dev = alloc_etherdev(sizeof(net_local)); @@ -4731,27 +4730,6 @@ wavelan_detach(struct pcmcia_device *p_dev) wv_pcmcia_release(link); } - /* Remove the interface data from the linked list */ - if(dev_list == link) - dev_list = link->next; - else - { - dev_link_t * prev = dev_list; - - while((prev != (dev_link_t *) NULL) && (prev->next != link)) - prev = prev->next; - - if(prev == (dev_link_t *) NULL) - { -#ifdef DEBUG_CONFIG_ERRORS - printk(KERN_WARNING "wavelan_detach : Attempting to remove a nonexistent device.\n"); -#endif - return; - } - - prev->next = link->next; - } - /* Free pieces */ if(link->priv) { diff --git a/drivers/net/wireless/wavelan_cs.p.h b/drivers/net/wireless/wavelan_cs.p.h index 3cb34817c039..a1a19177c5cd 100644 --- a/drivers/net/wireless/wavelan_cs.p.h +++ b/drivers/net/wireless/wavelan_cs.p.h @@ -766,7 +766,6 @@ static int /**************************** VARIABLES ****************************/ static dev_info_t dev_info = "wavelan_cs"; -static dev_link_t *dev_list = NULL; /* Linked list of devices */ /* * Parameters that can be set with 'insmod' diff --git a/drivers/parport/parport_cs.c b/drivers/parport/parport_cs.c index 063d22de9743..763f91a79085 100644 --- a/drivers/parport/parport_cs.c +++ b/drivers/parport/parport_cs.c @@ -95,7 +95,6 @@ static int parport_event(event_t event, int priority, event_callback_args_t *args); static dev_info_t dev_info = "parport_cs"; -static dev_link_t *dev_list = NULL; /*====================================================================== @@ -129,8 +128,7 @@ static dev_link_t *parport_attach(void) link->conf.IntType = INT_MEMORY_AND_IO; /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; @@ -156,21 +154,12 @@ static dev_link_t *parport_attach(void) static void parport_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); - dev_link_t **linkp; DEBUG(0, "parport_detach(0x%p)\n", link); - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) break; - if (*linkp == NULL) - return; - if (link->state & DEV_CONFIG) parport_cs_release(link); - /* Unlink, free device structure */ - *linkp = link->next; kfree(link->priv); } /* parport_detach */ @@ -391,7 +380,6 @@ static int __init init_parport_cs(void) static void __exit exit_parport_cs(void) { pcmcia_unregister_driver(&parport_cs_driver); - BUG_ON(dev_list != NULL); } module_init(init_parport_cs); diff --git a/drivers/scsi/pcmcia/fdomain_stub.c b/drivers/scsi/pcmcia/fdomain_stub.c index 5842c938fff5..538fedb97924 100644 --- a/drivers/scsi/pcmcia/fdomain_stub.c +++ b/drivers/scsi/pcmcia/fdomain_stub.c @@ -87,8 +87,6 @@ static dev_link_t *fdomain_attach(void); static void fdomain_detach(struct pcmcia_device *p_dev); -static dev_link_t *dev_list = NULL; - static dev_info_t dev_info = "fdomain_cs"; static dev_link_t *fdomain_attach(void) @@ -116,8 +114,7 @@ static dev_link_t *fdomain_attach(void) link->conf.Present = PRESENT_OPTION; /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; @@ -135,24 +132,14 @@ static dev_link_t *fdomain_attach(void) static void fdomain_detach(struct pcmcia_device *p_dev) { - dev_link_t *link = dev_to_instance(p_dev); - dev_link_t **linkp; + dev_link_t *link = dev_to_instance(p_dev); - DEBUG(0, "fdomain_detach(0x%p)\n", link); - - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) break; - if (*linkp == NULL) - return; + DEBUG(0, "fdomain_detach(0x%p)\n", link); - if (link->state & DEV_CONFIG) - fdomain_release(link); + if (link->state & DEV_CONFIG) + fdomain_release(link); - /* Unlink device structure, free bits */ - *linkp = link->next; - kfree(link->priv); - + kfree(link->priv); } /* fdomain_detach */ /*====================================================================*/ @@ -324,7 +311,6 @@ static int __init init_fdomain_cs(void) static void __exit exit_fdomain_cs(void) { pcmcia_unregister_driver(&fdomain_cs_driver); - BUG_ON(dev_list != NULL); } module_init(init_fdomain_cs); diff --git a/drivers/scsi/pcmcia/nsp_cs.c b/drivers/scsi/pcmcia/nsp_cs.c index e40a8c22aa9d..e48e9fb3c58c 100644 --- a/drivers/scsi/pcmcia/nsp_cs.c +++ b/drivers/scsi/pcmcia/nsp_cs.c @@ -104,7 +104,6 @@ static struct scsi_host_template nsp_driver_template = { #endif }; -static dev_link_t *dev_list = NULL; static dev_info_t dev_info = {"nsp_cs"}; static nsp_hw_data nsp_data_base; /* attach <-> detect glue */ @@ -1638,8 +1637,7 @@ static dev_link_t *nsp_cs_attach(void) /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; @@ -1665,30 +1663,16 @@ static dev_link_t *nsp_cs_attach(void) static void nsp_cs_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); - dev_link_t **linkp; nsp_dbg(NSP_DEBUG_INIT, "in, link=0x%p", link); - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) { - if (*linkp == link) { - break; - } - } - if (*linkp == NULL) { - return; - } - if (link->state & DEV_CONFIG) { ((scsi_info_t *)link->priv)->stop = 1; nsp_cs_release(link); } - /* Unlink device structure, free bits */ - *linkp = link->next; kfree(link->priv); link->priv = NULL; - } /* nsp_cs_detach */ @@ -2168,7 +2152,6 @@ static void __exit nsp_cs_exit(void) #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,68)) pcmcia_unregister_driver(&nsp_driver); - BUG_ON(dev_list != NULL); #else unregister_pcmcia_driver(&dev_info); /* XXX: this really needs to move into generic code.. */ diff --git a/drivers/scsi/pcmcia/qlogic_stub.c b/drivers/scsi/pcmcia/qlogic_stub.c index 8351dc234ffb..e10281a6e5f9 100644 --- a/drivers/scsi/pcmcia/qlogic_stub.c +++ b/drivers/scsi/pcmcia/qlogic_stub.c @@ -104,8 +104,6 @@ static dev_link_t *qlogic_attach(void); static void qlogic_detach(struct pcmcia_device *p_dev); -static dev_link_t *dev_list = NULL; - static dev_info_t dev_info = "qlogic_cs"; static struct Scsi_Host *qlogic_detect(struct scsi_host_template *host, @@ -190,8 +188,7 @@ static dev_link_t *qlogic_attach(void) link->conf.Present = PRESENT_OPTION; /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; @@ -210,22 +207,12 @@ static dev_link_t *qlogic_attach(void) static void qlogic_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); - dev_link_t **linkp; DEBUG(0, "qlogic_detach(0x%p)\n", link); - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) - break; - if (*linkp == NULL) - return; - if (link->state & DEV_CONFIG) qlogic_release(link); - /* Unlink device structure, free bits */ - *linkp = link->next; kfree(link->priv); } /* qlogic_detach */ @@ -439,7 +426,6 @@ static int __init init_qlogic_cs(void) static void __exit exit_qlogic_cs(void) { pcmcia_unregister_driver(&qlogic_cs_driver); - BUG_ON(dev_list != NULL); } MODULE_AUTHOR("Tom Zerucha, Michael Griffith"); diff --git a/drivers/scsi/pcmcia/sym53c500_cs.c b/drivers/scsi/pcmcia/sym53c500_cs.c index a0f8e2691f9c..87d50b33475e 100644 --- a/drivers/scsi/pcmcia/sym53c500_cs.c +++ b/drivers/scsi/pcmcia/sym53c500_cs.c @@ -232,7 +232,6 @@ enum Phase { * Global (within this module) variables other than * sym53c500_driver_template (the scsi_host_template). */ -static dev_link_t *dev_list; static dev_info_t dev_info = "sym53c500_cs"; /* ================================================================== */ @@ -930,22 +929,12 @@ static void SYM53C500_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); - dev_link_t **linkp; DEBUG(0, "SYM53C500_detach(0x%p)\n", link); - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) - break; - if (*linkp == NULL) - return; - if (link->state & DEV_CONFIG) SYM53C500_release(link); - /* Unlink device structure, free bits. */ - *linkp = link->next; kfree(link->priv); link->priv = NULL; } /* SYM53C500_detach */ @@ -978,8 +967,7 @@ SYM53C500_attach(void) link->conf.Present = PRESENT_OPTION; /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; diff --git a/drivers/serial/serial_cs.c b/drivers/serial/serial_cs.c index a95366366504..6e7a1a0ae015 100644 --- a/drivers/serial/serial_cs.c +++ b/drivers/serial/serial_cs.c @@ -122,8 +122,6 @@ static dev_info_t dev_info = "serial_cs"; static dev_link_t *serial_attach(void); static void serial_detach(struct pcmcia_device *p_dev); -static dev_link_t *dev_list = NULL; - /*====================================================================== After a card is removed, serial_remove() will unregister @@ -234,8 +232,7 @@ static dev_link_t *serial_attach(void) link->conf.IntType = INT_MEMORY_AND_IO; /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; /* not needed */ client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; @@ -262,17 +259,9 @@ static void serial_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); struct serial_info *info = link->priv; - dev_link_t **linkp; DEBUG(0, "serial_detach(0x%p)\n", link); - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) - break; - if (*linkp == NULL) - return; - /* * Ensure any outstanding scheduled tasks are completed. */ @@ -283,8 +272,7 @@ static void serial_detach(struct pcmcia_device *p_dev) */ serial_remove(link); - /* Unlink device structure, free bits */ - *linkp = link->next; + /* free bits */ kfree(info); } @@ -871,7 +859,6 @@ static int __init init_serial_cs(void) static void __exit exit_serial_cs(void) { pcmcia_unregister_driver(&serial_cs_driver); - BUG_ON(dev_list != NULL); } module_init(init_serial_cs); diff --git a/drivers/telephony/ixj_pcmcia.c b/drivers/telephony/ixj_pcmcia.c index c58140dc7a73..6b992985d782 100644 --- a/drivers/telephony/ixj_pcmcia.c +++ b/drivers/telephony/ixj_pcmcia.c @@ -40,7 +40,6 @@ static void ixj_config(dev_link_t * link); static void ixj_cs_release(dev_link_t * link); static int ixj_event(event_t event, int priority, event_callback_args_t * args); static dev_info_t dev_info = "ixj_cs"; -static dev_link_t *dev_list = NULL; static dev_link_t *ixj_attach(void) { @@ -65,8 +64,7 @@ static dev_link_t *ixj_attach(void) } memset(link->priv, 0, sizeof(struct ixj_info_t)); /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = &dev_info; client_reg.Version = 0x0210; client_reg.event_callback_args.client_data = link; @@ -82,20 +80,13 @@ static dev_link_t *ixj_attach(void) static void ixj_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); - dev_link_t **linkp; DEBUG(0, "ixj_detach(0x%p)\n", link); - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) - break; - if (*linkp == NULL) - return; + link->state &= ~DEV_RELEASE_PENDING; if (link->state & DEV_CONFIG) ixj_cs_release(link); - /* Unlink device structure, free bits */ - *linkp = link->next; kfree(link->priv); kfree(link); } @@ -314,7 +305,6 @@ static int __init ixj_pcmcia_init(void) static void ixj_pcmcia_exit(void) { pcmcia_unregister_driver(&ixj_driver); - BUG_ON(dev_list != NULL); } module_init(ixj_pcmcia_init); diff --git a/drivers/usb/host/sl811_cs.c b/drivers/usb/host/sl811_cs.c index ed3e7014dbbc..439709670d0b 100644 --- a/drivers/usb/host/sl811_cs.c +++ b/drivers/usb/host/sl811_cs.c @@ -66,8 +66,6 @@ module_param(pc_debug, int, 0644); static const char driver_name[DEV_NAME_LEN] = "sl811_cs"; -static dev_link_t *dev_list = NULL; - typedef struct local_info_t { dev_link_t link; dev_node_t node; @@ -143,24 +141,13 @@ static int sl811_hc_init(struct device *parent, ioaddr_t base_addr, int irq) static void sl811_cs_detach(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); - dev_link_t **linkp; DBG(0, "sl811_cs_detach(0x%p)\n", link); - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) { - if (*linkp == link) - break; - } - if (*linkp == NULL) - return; - link->state &= ~DEV_PRESENT; if (link->state & DEV_CONFIG) sl811_cs_release(link); - /* Unlink device structure, and free it */ - *linkp = link->next; /* This points to the parent local_info_t struct */ kfree(link->priv); } @@ -378,8 +365,7 @@ static dev_link_t *sl811_cs_attach(void) link->conf.IntType = INT_MEMORY_AND_IO; /* Register with Card Services */ - link->next = dev_list; - dev_list = link; + link->next = NULL; client_reg.dev_info = (dev_info_t *) &driver_name; client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE; client_reg.Version = 0x0210; From f8cfa618dccbdc6dab5297f75779566a388a98fd Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Mon, 14 Nov 2005 21:25:51 +0100 Subject: [PATCH 36/48] [PATCH] pcmcia: unify attach, EVENT_CARD_INSERTION handlers into one probe callback Unify the EVENT_CARD_INSERTION and "attach" callbacks to one unified probe() callback. As all in-kernel drivers are changed to this new callback, there will be no temporary backwards-compatibility. Inside a probe() function, each driver _must_ set struct pcmcia_device *p_dev->instance and instance->handle correctly. With these patches, the basic driver interface for 16-bit PCMCIA drivers now has the classic four callbacks known also from other buses: int (*probe) (struct pcmcia_device *dev); void (*remove) (struct pcmcia_device *dev); int (*suspend) (struct pcmcia_device *dev); int (*resume) (struct pcmcia_device *dev); Signed-off-by: Dominik Brodowski --- Documentation/pcmcia/driver-changes.txt | 6 +- drivers/bluetooth/bluecard_cs.c | 44 ++---- drivers/bluetooth/bt3c_cs.c | 43 ++---- drivers/bluetooth/btuart_cs.c | 44 ++---- drivers/bluetooth/dtl1_cs.c | 43 ++---- drivers/char/pcmcia/cm4000_cs.c | 68 ++------- drivers/char/pcmcia/cm4040_cs.c | 67 ++------- drivers/char/pcmcia/synclink_cs.c | 49 ++----- drivers/ide/legacy/ide-cs.c | 56 ++------ drivers/isdn/hardware/avm/avm_cs.c | 56 ++------ drivers/isdn/hisax/avma1_cs.c | 70 ++-------- drivers/isdn/hisax/elsa_cs.c | 78 ++--------- drivers/isdn/hisax/sedlbauer_cs.c | 75 ++-------- drivers/isdn/hisax/teles_cs.c | 67 ++------- drivers/mtd/maps/pcmciamtd.c | 54 ++------ drivers/net/pcmcia/3c574_cs.c | 55 ++------ drivers/net/pcmcia/3c589_cs.c | 63 ++------- drivers/net/pcmcia/axnet_cs.c | 59 ++------ drivers/net/pcmcia/com20020_cs.c | 59 ++------ drivers/net/pcmcia/fmvj18x_cs.c | 54 ++------ drivers/net/pcmcia/ibmtr_cs.c | 69 ++------- drivers/net/pcmcia/nmclan_cs.c | 57 ++------ drivers/net/pcmcia/pcnet_cs.c | 45 ++---- drivers/net/pcmcia/smc91c92_cs.c | 57 ++------ drivers/net/pcmcia/xirc2ps_cs.c | 67 ++------- drivers/net/wireless/airo_cs.c | 74 ++-------- drivers/net/wireless/atmel_cs.c | 80 +++-------- drivers/net/wireless/hostap/hostap_cs.c | 55 ++------ drivers/net/wireless/netwave_cs.c | 68 ++------- drivers/net/wireless/orinoco_cs.c | 58 ++------ drivers/net/wireless/ray_cs.c | 70 ++-------- drivers/net/wireless/spectrum_cs.c | 63 ++------- drivers/net/wireless/wavelan_cs.c | 84 ++--------- drivers/net/wireless/wavelan_cs.p.h | 8 -- drivers/net/wireless/wl3501_cs.c | 60 ++------ drivers/parport/parport_cs.c | 61 ++------ drivers/pcmcia/ds.c | 177 ++++-------------------- drivers/scsi/pcmcia/aha152x_stub.c | 52 ++----- drivers/scsi/pcmcia/fdomain_stub.c | 56 ++------ drivers/scsi/pcmcia/nsp_cs.c | 67 ++------- drivers/scsi/pcmcia/nsp_cs.h | 2 - drivers/scsi/pcmcia/qlogic_stub.c | 49 ++----- drivers/scsi/pcmcia/sym53c500_cs.c | 53 ++----- drivers/serial/serial_cs.c | 58 ++------ drivers/telephony/ixj_pcmcia.c | 48 ++----- drivers/usb/host/sl811_cs.c | 44 ++---- include/pcmcia/cs.h | 1 - include/pcmcia/ds.h | 6 +- 48 files changed, 469 insertions(+), 2230 deletions(-) diff --git a/Documentation/pcmcia/driver-changes.txt b/Documentation/pcmcia/driver-changes.txt index 45c25c7a3445..97420f08c786 100644 --- a/Documentation/pcmcia/driver-changes.txt +++ b/Documentation/pcmcia/driver-changes.txt @@ -1,7 +1,9 @@ This file details changes in 2.6 which affect PCMCIA card driver authors: -* Unify detach and REMOVAL event code (as of 2.6.16) - void (*remove) (struct pcmcia_device *dev); +* Unify detach and REMOVAL event code, as well as attach and INSERTION + code (as of 2.6.16) + void (*remove) (struct pcmcia_device *dev); + int (*probe) (struct pcmcia_device *dev); * Move suspend, resume and reset out of event handler (as of 2.6.16) int (*suspend) (struct pcmcia_device *dev); diff --git a/drivers/bluetooth/bluecard_cs.c b/drivers/bluetooth/bluecard_cs.c index bd80535646fa..9888bc151755 100644 --- a/drivers/bluetooth/bluecard_cs.c +++ b/drivers/bluetooth/bluecard_cs.c @@ -87,11 +87,7 @@ typedef struct bluecard_info_t { static void bluecard_config(dev_link_t *link); static void bluecard_release(dev_link_t *link); -static int bluecard_event(event_t event, int priority, event_callback_args_t *args); -static dev_info_t dev_info = "bluecard_cs"; - -static dev_link_t *bluecard_attach(void); static void bluecard_detach(struct pcmcia_device *p_dev); @@ -860,17 +856,15 @@ static int bluecard_close(bluecard_info_t *info) return 0; } -static dev_link_t *bluecard_attach(void) +static int bluecard_attach(struct pcmcia_device *p_dev) { bluecard_info_t *info; - client_reg_t client_reg; dev_link_t *link; - int ret; /* Create new info device */ info = kzalloc(sizeof(*info), GFP_KERNEL); if (!info) - return NULL; + return -ENOMEM; link = &info->link; link->priv = info; @@ -887,20 +881,13 @@ static dev_link_t *bluecard_attach(void) link->conf.Vcc = 50; link->conf.IntType = INT_MEMORY_AND_IO; - /* Register with Card Services */ - link->next = NULL; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; + link->handle = p_dev; + p_dev->instance = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != CS_SUCCESS) { - cs_error(link->handle, RegisterClient, ret); - bluecard_detach(link->handle); - return NULL; - } + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + bluecard_config(link); - return link; + return 0; } @@ -1046,20 +1033,6 @@ static int bluecard_resume(struct pcmcia_device *dev) return 0; } -static int bluecard_event(event_t event, int priority, event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - bluecard_config(link); - break; - } - - return 0; -} - static struct pcmcia_device_id bluecard_ids[] = { PCMCIA_DEVICE_PROD_ID12("BlueCard", "LSE041", 0xbaf16fbf, 0x657cc15e), PCMCIA_DEVICE_PROD_ID12("BTCFCARD", "LSE139", 0xe3987764, 0x2524b59c), @@ -1073,8 +1046,7 @@ static struct pcmcia_driver bluecard_driver = { .drv = { .name = "bluecard_cs", }, - .attach = bluecard_attach, - .event = bluecard_event, + .probe = bluecard_attach, .remove = bluecard_detach, .id_table = bluecard_ids, .suspend = bluecard_suspend, diff --git a/drivers/bluetooth/bt3c_cs.c b/drivers/bluetooth/bt3c_cs.c index 50aa52b3cd20..e522d19ad886 100644 --- a/drivers/bluetooth/bt3c_cs.c +++ b/drivers/bluetooth/bt3c_cs.c @@ -90,11 +90,7 @@ typedef struct bt3c_info_t { static void bt3c_config(dev_link_t *link); static void bt3c_release(dev_link_t *link); -static int bt3c_event(event_t event, int priority, event_callback_args_t *args); -static dev_info_t dev_info = "bt3c_cs"; - -static dev_link_t *bt3c_attach(void); static void bt3c_detach(struct pcmcia_device *p_dev); @@ -661,17 +657,15 @@ static int bt3c_close(bt3c_info_t *info) return 0; } -static dev_link_t *bt3c_attach(void) +static int bt3c_attach(struct pcmcia_device *p_dev) { bt3c_info_t *info; - client_reg_t client_reg; dev_link_t *link; - int ret; /* Create new info device */ info = kzalloc(sizeof(*info), GFP_KERNEL); if (!info) - return NULL; + return -ENOMEM; link = &info->link; link->priv = info; @@ -688,20 +682,13 @@ static dev_link_t *bt3c_attach(void) link->conf.Vcc = 50; link->conf.IntType = INT_MEMORY_AND_IO; - /* Register with Card Services */ - link->next = NULL; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; + link->handle = p_dev; + p_dev->instance = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != CS_SUCCESS) { - cs_error(link->handle, RegisterClient, ret); - bt3c_detach(link->handle); - return NULL; - } + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + bt3c_config(link); - return link; + return 0; } @@ -892,19 +879,6 @@ static int bt3c_resume(struct pcmcia_device *dev) return 0; } -static int bt3c_event(event_t event, int priority, event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - bt3c_config(link); - break; - } - - return 0; -} static struct pcmcia_device_id bt3c_ids[] = { PCMCIA_DEVICE_PROD_ID13("3COM", "Bluetooth PC Card", 0xefce0a31, 0xd4ce9b02), @@ -917,8 +891,7 @@ static struct pcmcia_driver bt3c_driver = { .drv = { .name = "bt3c_cs", }, - .attach = bt3c_attach, - .event = bt3c_event, + .probe = bt3c_attach, .remove = bt3c_detach, .id_table = bt3c_ids, .suspend = bt3c_suspend, diff --git a/drivers/bluetooth/btuart_cs.c b/drivers/bluetooth/btuart_cs.c index 7b04f89f7a71..7b4bff4cfa2d 100644 --- a/drivers/bluetooth/btuart_cs.c +++ b/drivers/bluetooth/btuart_cs.c @@ -86,11 +86,7 @@ typedef struct btuart_info_t { static void btuart_config(dev_link_t *link); static void btuart_release(dev_link_t *link); -static int btuart_event(event_t event, int priority, event_callback_args_t *args); -static dev_info_t dev_info = "btuart_cs"; - -static dev_link_t *btuart_attach(void); static void btuart_detach(struct pcmcia_device *p_dev); @@ -580,17 +576,15 @@ static int btuart_close(btuart_info_t *info) return 0; } -static dev_link_t *btuart_attach(void) +static int btuart_attach(struct pcmcia_device *p_dev) { btuart_info_t *info; - client_reg_t client_reg; dev_link_t *link; - int ret; /* Create new info device */ info = kzalloc(sizeof(*info), GFP_KERNEL); if (!info) - return NULL; + return -ENOMEM; link = &info->link; link->priv = info; @@ -607,20 +601,13 @@ static dev_link_t *btuart_attach(void) link->conf.Vcc = 50; link->conf.IntType = INT_MEMORY_AND_IO; - /* Register with Card Services */ - link->next = NULL; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; + link->handle = p_dev; + p_dev->instance = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != CS_SUCCESS) { - cs_error(link->handle, RegisterClient, ret); - btuart_detach(link->handle); - return NULL; - } + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + btuart_config(link); - return link; + return 0; } @@ -813,20 +800,6 @@ static int btuart_resume(struct pcmcia_device *dev) } -static int btuart_event(event_t event, int priority, event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - btuart_config(link); - break; - } - - return 0; -} - static struct pcmcia_device_id btuart_ids[] = { /* don't use this driver. Use serial_cs + hci_uart instead */ PCMCIA_DEVICE_NULL @@ -838,8 +811,7 @@ static struct pcmcia_driver btuart_driver = { .drv = { .name = "btuart_cs", }, - .attach = btuart_attach, - .event = btuart_event, + .probe = btuart_attach, .remove = btuart_detach, .id_table = btuart_ids, .suspend = btuart_suspend, diff --git a/drivers/bluetooth/dtl1_cs.c b/drivers/bluetooth/dtl1_cs.c index c39d4576cfff..787c5eb9950e 100644 --- a/drivers/bluetooth/dtl1_cs.c +++ b/drivers/bluetooth/dtl1_cs.c @@ -89,11 +89,7 @@ typedef struct dtl1_info_t { static void dtl1_config(dev_link_t *link); static void dtl1_release(dev_link_t *link); -static int dtl1_event(event_t event, int priority, event_callback_args_t *args); -static dev_info_t dev_info = "dtl1_cs"; - -static dev_link_t *dtl1_attach(void); static void dtl1_detach(struct pcmcia_device *p_dev); @@ -559,17 +555,15 @@ static int dtl1_close(dtl1_info_t *info) return 0; } -static dev_link_t *dtl1_attach(void) +static int dtl1_attach(struct pcmcia_device *p_dev) { dtl1_info_t *info; - client_reg_t client_reg; dev_link_t *link; - int ret; /* Create new info device */ info = kzalloc(sizeof(*info), GFP_KERNEL); if (!info) - return NULL; + return -ENOMEM; link = &info->link; link->priv = info; @@ -586,20 +580,13 @@ static dev_link_t *dtl1_attach(void) link->conf.Vcc = 50; link->conf.IntType = INT_MEMORY_AND_IO; - /* Register with Card Services */ - link->next = NULL; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; + link->handle = p_dev; + p_dev->instance = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != CS_SUCCESS) { - cs_error(link->handle, RegisterClient, ret); - dtl1_detach(link->handle); - return NULL; - } + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + dtl1_config(link); - return link; + return 0; } @@ -764,19 +751,6 @@ static int dtl1_resume(struct pcmcia_device *dev) return 0; } -static int dtl1_event(event_t event, int priority, event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - dtl1_config(link); - break; - } - - return 0; -} static struct pcmcia_device_id dtl1_ids[] = { PCMCIA_DEVICE_PROD_ID12("Nokia Mobile Phones", "DTL-1", 0xe1bfdd64, 0xe168480d), @@ -790,8 +764,7 @@ static struct pcmcia_driver dtl1_driver = { .drv = { .name = "dtl1_cs", }, - .attach = dtl1_attach, - .event = dtl1_event, + .probe = dtl1_attach, .remove = dtl1_detach, .id_table = dtl1_ids, .suspend = dtl1_suspend, diff --git a/drivers/char/pcmcia/cm4000_cs.c b/drivers/char/pcmcia/cm4000_cs.c index 8a064f2f005d..649677b5dc36 100644 --- a/drivers/char/pcmcia/cm4000_cs.c +++ b/drivers/char/pcmcia/cm4000_cs.c @@ -66,7 +66,6 @@ static char *version = "cm4000_cs.c v2.4.0gm5 - All bugs added by Harald Welte"; #define T_100MSEC msecs_to_jiffies(100) #define T_500MSEC msecs_to_jiffies(500) -static void cm4000_detach(struct pcmcia_device *p_dev); static void cm4000_release(dev_link_t *link); static int major; /* major number we get from the kernel */ @@ -156,7 +155,6 @@ struct cm4000_dev { /*sbuf*/ 512*sizeof(char) - \ /*queue*/ 4*sizeof(wait_queue_head_t)) -static dev_info_t dev_info = MODULE_NAME; static dev_link_t *dev_table[CM4000_MAX_DEV]; /* This table doesn't use spaces after the comma between fields and thus @@ -1864,38 +1862,6 @@ cs_release: link->state &= ~DEV_CONFIG_PENDING; } -static int cm4000_event(event_t event, int priority, - event_callback_args_t *args) -{ - dev_link_t *link; - struct cm4000_dev *dev; - int devno; - - link = args->client_data; - dev = link->priv; - - DEBUGP(3, dev, "-> cm4000_event\n"); - for (devno = 0; devno < CM4000_MAX_DEV; devno++) - if (dev_table[devno] == link) - break; - - if (devno == CM4000_MAX_DEV) - return CS_BAD_ADAPTER; - - switch (event) { - case CS_EVENT_CARD_INSERTION: - DEBUGP(5, dev, "CS_EVENT_CARD_INSERTION\n"); - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - cm4000_config(link, devno); - break; - default: - DEBUGP(5, dev, "unknown event %.2x\n", event); - break; - } - DEBUGP(3, dev, "<- cm4000_event\n"); - return CS_SUCCESS; -} - static int cm4000_suspend(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); @@ -1935,11 +1901,10 @@ static void cm4000_release(dev_link_t *link) pcmcia_release_io(link->handle, &link->io); } -static dev_link_t *cm4000_attach(void) +static int cm4000_attach(struct pcmcia_device *p_dev) { struct cm4000_dev *dev; dev_link_t *link; - client_reg_t client_reg; int i; for (i = 0; i < CM4000_MAX_DEV; i++) @@ -1948,41 +1913,31 @@ static dev_link_t *cm4000_attach(void) if (i == CM4000_MAX_DEV) { printk(KERN_NOTICE MODULE_NAME ": all devices in use\n"); - return NULL; + return -ENODEV; } /* create a new cm4000_cs device */ dev = kzalloc(sizeof(struct cm4000_dev), GFP_KERNEL); if (dev == NULL) - return NULL; + return -ENOMEM; link = &dev->link; link->priv = dev; link->conf.IntType = INT_MEMORY_AND_IO; dev_table[i] = link; - /* register with card services */ - client_reg.dev_info = &dev_info; - client_reg.EventMask = - CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL | - CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET | - CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - - i = pcmcia_register_client(&link->handle, &client_reg); - if (i) { - cs_error(link->handle, RegisterClient, i); - cm4000_detach(link->handle); - return NULL; - } - init_waitqueue_head(&dev->devq); init_waitqueue_head(&dev->ioq); init_waitqueue_head(&dev->atrq); init_waitqueue_head(&dev->readq); - return link; + link->handle = p_dev; + p_dev->instance = link; + + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + cm4000_config(link, i); + + return 0; } static void cm4000_detach(struct pcmcia_device *p_dev) @@ -2031,11 +1986,10 @@ static struct pcmcia_driver cm4000_driver = { .drv = { .name = "cm4000_cs", }, - .attach = cm4000_attach, + .probe = cm4000_attach, .remove = cm4000_detach, .suspend = cm4000_suspend, .resume = cm4000_resume, - .event = cm4000_event, .id_table = cm4000_ids, }; diff --git a/drivers/char/pcmcia/cm4040_cs.c b/drivers/char/pcmcia/cm4040_cs.c index e08ab949c116..46eb371bf17e 100644 --- a/drivers/char/pcmcia/cm4040_cs.c +++ b/drivers/char/pcmcia/cm4040_cs.c @@ -65,7 +65,6 @@ static char *version = #define POLL_PERIOD msecs_to_jiffies(10) static void reader_release(dev_link_t *link); -static void reader_detach(struct pcmcia_device *p_dev); static int major; @@ -86,7 +85,6 @@ struct reader_dev { struct timer_list poll_timer; }; -static dev_info_t dev_info = MODULE_NAME; static dev_link_t *dev_table[CM_MAX_DEV]; #ifndef PCMCIA_DEBUG @@ -629,39 +627,6 @@ cs_release: link->state &= ~DEV_CONFIG_PENDING; } -static int reader_event(event_t event, int priority, - event_callback_args_t *args) -{ - dev_link_t *link; - struct reader_dev *dev; - int devno; - - link = args->client_data; - dev = link->priv; - DEBUGP(3, dev, "-> reader_event\n"); - for (devno = 0; devno < CM_MAX_DEV; devno++) { - if (dev_table[devno] == link) - break; - } - if (devno == CM_MAX_DEV) - return CS_BAD_ADAPTER; - - switch (event) { - case CS_EVENT_CARD_INSERTION: - DEBUGP(5, dev, "CS_EVENT_CARD_INSERTION\n"); - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - reader_config(link, devno); - break; - - default: - DEBUGP(5, dev, "reader_event: unknown event %.2x\n", - event); - break; - } - DEBUGP(3, dev, "<- reader_event\n"); - return CS_SUCCESS; -} - static int reader_suspend(struct pcmcia_device *p_dev) { dev_link_t *link = dev_to_instance(p_dev); @@ -691,11 +656,10 @@ static void reader_release(dev_link_t *link) pcmcia_release_io(link->handle, &link->io); } -static dev_link_t *reader_attach(void) +static int reader_attach(struct pcmcia_device *p_dev) { struct reader_dev *dev; dev_link_t *link; - client_reg_t client_reg; int i; for (i = 0; i < CM_MAX_DEV; i++) { @@ -704,11 +668,11 @@ static dev_link_t *reader_attach(void) } if (i == CM_MAX_DEV) - return NULL; + return -ENODEV; dev = kzalloc(sizeof(struct reader_dev), GFP_KERNEL); if (dev == NULL) - return NULL; + return -ENOMEM; dev->timeout = CCID_DRIVER_MINIMUM_TIMEOUT; dev->buffer_status = 0; @@ -719,20 +683,6 @@ static dev_link_t *reader_attach(void) link->conf.IntType = INT_MEMORY_AND_IO; dev_table[i] = link; - client_reg.dev_info = &dev_info; - client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE; - client_reg.EventMask= - CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL | - CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET | - CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - i = pcmcia_register_client(&link->handle, &client_reg); - if (i) { - cs_error(link->handle, RegisterClient, i); - reader_detach(link->handle); - return NULL; - } init_waitqueue_head(&dev->devq); init_waitqueue_head(&dev->poll_wait); init_waitqueue_head(&dev->read_wait); @@ -740,7 +690,13 @@ static dev_link_t *reader_attach(void) init_timer(&dev->poll_timer); dev->poll_timer.function = &cm4040_do_poll; - return link; + link->handle = p_dev; + p_dev->instance = link; + + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + reader_config(link, i); + + return 0; } static void reader_detach(struct pcmcia_device *p_dev) @@ -790,11 +746,10 @@ static struct pcmcia_driver reader_driver = { .drv = { .name = "cm4040_cs", }, - .attach = reader_attach, + .probe = reader_attach, .remove = reader_detach, .suspend = reader_suspend, .resume = reader_resume, - .event = reader_event, .id_table = cm4040_ids, }; diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c index dc38b1d0a725..cf45b100eff1 100644 --- a/drivers/char/pcmcia/synclink_cs.c +++ b/drivers/char/pcmcia/synclink_cs.c @@ -486,13 +486,8 @@ static void mgslpc_wait_until_sent(struct tty_struct *tty, int timeout); static void mgslpc_config(dev_link_t *link); static void mgslpc_release(u_long arg); -static int mgslpc_event(event_t event, int priority, - event_callback_args_t *args); -static dev_link_t *mgslpc_attach(void); static void mgslpc_detach(struct pcmcia_device *p_dev); -static dev_info_t dev_info = "synclink_cs"; - /* * 1st function defined in .text section. Calling this function in * init_module() followed by a breakpoint allows a remote debugger @@ -538,12 +533,10 @@ static void ldisc_receive_buf(struct tty_struct *tty, } } -static dev_link_t *mgslpc_attach(void) +static int mgslpc_attach(struct pcmcia_device *p_dev) { MGSLPC_INFO *info; dev_link_t *link; - client_reg_t client_reg; - int ret; if (debug_level >= DEBUG_LEVEL_INFO) printk("mgslpc_attach\n"); @@ -551,7 +544,7 @@ static dev_link_t *mgslpc_attach(void) info = (MGSLPC_INFO *)kmalloc(sizeof(MGSLPC_INFO), GFP_KERNEL); if (!info) { printk("Error can't allocate device instance data\n"); - return NULL; + return -ENOMEM; } memset(info, 0, sizeof(MGSLPC_INFO)); @@ -586,23 +579,15 @@ static dev_link_t *mgslpc_attach(void) link->conf.Vcc = 50; link->conf.IntType = INT_MEMORY_AND_IO; - /* Register with Card Services */ - link->next = NULL; + link->handle = p_dev; + p_dev->instance = link; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != CS_SUCCESS) { - cs_error(link->handle, RegisterClient, ret); - mgslpc_detach(link->handle); - return NULL; - } + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + mgslpc_config(link); mgslpc_add_device(info); - return link; + return 0; } /* Card has been inserted. @@ -778,23 +763,6 @@ static int mgslpc_resume(struct pcmcia_device *dev) } -static int mgslpc_event(event_t event, int priority, - event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - if (debug_level >= DEBUG_LEVEL_INFO) - printk("mgslpc_event(0x%06x)\n", event); - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - mgslpc_config(link); - break; - } - return 0; -} - static inline int mgslpc_paranoia_check(MGSLPC_INFO *info, char *name, const char *routine) { @@ -3071,8 +3039,7 @@ static struct pcmcia_driver mgslpc_driver = { .drv = { .name = "synclink_cs", }, - .attach = mgslpc_attach, - .event = mgslpc_event, + .probe = mgslpc_attach, .remove = mgslpc_detach, .id_table = mgslpc_ids, .suspend = mgslpc_suspend, diff --git a/drivers/ide/legacy/ide-cs.c b/drivers/ide/legacy/ide-cs.c index c83068dd42a0..e36e6fbbf9e0 100644 --- a/drivers/ide/legacy/ide-cs.c +++ b/drivers/ide/legacy/ide-cs.c @@ -88,12 +88,8 @@ typedef struct ide_info_t { } ide_info_t; static void ide_release(dev_link_t *); -static int ide_event(event_t event, int priority, - event_callback_args_t *args); +static void ide_config(dev_link_t *); -static dev_info_t dev_info = "ide-cs"; - -static dev_link_t *ide_attach(void); static void ide_detach(struct pcmcia_device *p_dev); @@ -107,18 +103,17 @@ static void ide_detach(struct pcmcia_device *p_dev); ======================================================================*/ -static dev_link_t *ide_attach(void) +static int ide_attach(struct pcmcia_device *p_dev) { ide_info_t *info; dev_link_t *link; - client_reg_t client_reg; - int ret; - + DEBUG(0, "ide_attach()\n"); /* Create new ide device */ info = kzalloc(sizeof(*info), GFP_KERNEL); - if (!info) return NULL; + if (!info) + return -ENOMEM; link = &info->link; link->priv = info; link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; @@ -129,20 +124,14 @@ static dev_link_t *ide_attach(void) link->conf.Attributes = CONF_ENABLE_IRQ; link->conf.Vcc = 50; link->conf.IntType = INT_MEMORY_AND_IO; - - /* Register with Card Services */ - link->next = NULL; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != CS_SUCCESS) { - cs_error(link->handle, RegisterClient, ret); - ide_detach(link->handle); - return NULL; - } - - return link; + + link->handle = p_dev; + p_dev->instance = link; + + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + ide_config(link); + + return 0; } /* ide_attach */ /*====================================================================== @@ -421,22 +410,6 @@ static int ide_resume(struct pcmcia_device *dev) ======================================================================*/ -int ide_event(event_t event, int priority, - event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - DEBUG(1, "ide_event(0x%06x)\n", event); - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - ide_config(link); - break; - } - return 0; -} /* ide_event */ - static struct pcmcia_device_id ide_ids[] = { PCMCIA_DEVICE_FUNC_ID(4), PCMCIA_DEVICE_MANF_CARD(0x0032, 0x0704), @@ -481,8 +454,7 @@ static struct pcmcia_driver ide_cs_driver = { .drv = { .name = "ide-cs", }, - .attach = ide_attach, - .event = ide_event, + .probe = ide_attach, .remove = ide_detach, .id_table = ide_ids, .suspend = ide_suspend, diff --git a/drivers/isdn/hardware/avm/avm_cs.c b/drivers/isdn/hardware/avm/avm_cs.c index 0a8c1da10b4b..2a2b03ff096b 100644 --- a/drivers/isdn/hardware/avm/avm_cs.c +++ b/drivers/isdn/hardware/avm/avm_cs.c @@ -53,8 +53,6 @@ MODULE_LICENSE("GPL"); static void avmcs_config(dev_link_t *link); static void avmcs_release(dev_link_t *link); -static int avmcs_event(event_t event, int priority, - event_callback_args_t *args); /* The attach() and detach() entry points are used to create and destroy @@ -62,17 +60,8 @@ static int avmcs_event(event_t event, int priority, needed to manage one actual PCMCIA card. */ -static dev_link_t *avmcs_attach(void); static void avmcs_detach(struct pcmcia_device *p_dev); -/* - 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 = "avm_cs"; - /* A linked list of "instances" of the skeleton device. Each actual PCMCIA card corresponds to one device instance, and is described @@ -110,13 +99,11 @@ typedef struct local_info_t { ======================================================================*/ -static dev_link_t *avmcs_attach(void) +static int avmcs_attach(struct pcmcia_device *p_dev) { - client_reg_t client_reg; dev_link_t *link; local_info_t *local; - int ret; - + /* Initialize the dev_link_t structure */ link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL); if (!link) @@ -147,24 +134,19 @@ static dev_link_t *avmcs_attach(void) goto err_kfree; memset(local, 0, sizeof(local_info_t)); link->priv = local; - - /* Register with Card Services */ - link->next = NULL; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != 0) { - cs_error(link->handle, RegisterClient, ret); - avmcs_detach(link->handle); - goto err; - } - return link; + + link->handle = p_dev; + p_dev->instance = link; + + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + avmcs_config(link); + + return 0; err_kfree: kfree(link); err: - return NULL; + return -EINVAL; } /* avmcs_attach */ /*====================================================================== @@ -433,19 +415,6 @@ static int avmcs_resume(struct pcmcia_device *dev) ======================================================================*/ -static int avmcs_event(event_t event, int priority, - event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - avmcs_config(link); - break; - } - return 0; -} /* avmcs_event */ static struct pcmcia_device_id avmcs_ids[] = { PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN-Controller B1", 0x95d42008, 0x845dc335), @@ -460,8 +429,7 @@ static struct pcmcia_driver avmcs_driver = { .drv = { .name = "avm_cs", }, - .attach = avmcs_attach, - .event = avmcs_event, + .probe = avmcs_attach, .remove = avmcs_detach, .id_table = avmcs_ids, .suspend= avmcs_suspend, diff --git a/drivers/isdn/hisax/avma1_cs.c b/drivers/isdn/hisax/avma1_cs.c index b6ea653f881e..969da40c4248 100644 --- a/drivers/isdn/hisax/avma1_cs.c +++ b/drivers/isdn/hisax/avma1_cs.c @@ -69,8 +69,6 @@ module_param(isdnprot, int, 0); static void avma1cs_config(dev_link_t *link); static void avma1cs_release(dev_link_t *link); -static int avma1cs_event(event_t event, int priority, - event_callback_args_t *args); /* The attach() and detach() entry points are used to create and destroy @@ -78,16 +76,8 @@ static int avma1cs_event(event_t event, int priority, needed to manage one actual PCMCIA card. */ -static dev_link_t *avma1cs_attach(void); static void avma1cs_detach(struct pcmcia_device *p_dev); -/* - 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 = "avma1_cs"; /* A linked list of "instances" of the skeleton device. Each actual @@ -126,26 +116,24 @@ typedef struct local_info_t { ======================================================================*/ -static dev_link_t *avma1cs_attach(void) +static int avma1cs_attach(struct pcmcia_device *p_dev) { - client_reg_t client_reg; dev_link_t *link; local_info_t *local; - int ret; - + DEBUG(0, "avma1cs_attach()\n"); /* Initialize the dev_link_t structure */ link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL); if (!link) - return NULL; + return -ENOMEM; memset(link, 0, sizeof(struct dev_link_t)); /* Allocate space for private device-specific data */ local = kmalloc(sizeof(local_info_t), GFP_KERNEL); if (!local) { kfree(link); - return NULL; + return -ENOMEM; } memset(local, 0, sizeof(local_info_t)); link->priv = local; @@ -170,19 +158,13 @@ static dev_link_t *avma1cs_attach(void) link->conf.ConfigIndex = 1; link->conf.Present = PRESENT_OPTION; - /* Register with Card Services */ - link->next = NULL; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != 0) { - cs_error(link->handle, RegisterClient, ret); - avma1cs_detach(link->handle); - return NULL; - } + link->handle = p_dev; + p_dev->instance = link; - return link; + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + avma1cs_config(link); + + return 0; } /* avma1cs_attach */ /*====================================================================== @@ -430,35 +412,6 @@ static int avma1cs_resume(struct pcmcia_device *dev) return 0; } -/*====================================================================== - - 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 avma1cs_event(event_t event, int priority, - event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - DEBUG(1, "avma1cs_event(0x%06x)\n", event); - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - avma1cs_config(link); - break; - } - return 0; -} /* avma1cs_event */ static struct pcmcia_device_id avma1cs_ids[] = { PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN A", 0x95d42008, 0xadc9d4bb), @@ -472,8 +425,7 @@ static struct pcmcia_driver avma1cs_driver = { .drv = { .name = "avma1_cs", }, - .attach = avma1cs_attach, - .event = avma1cs_event, + .probe = avma1cs_attach, .remove = avma1cs_detach, .id_table = avma1cs_ids, .suspend = avma1cs_suspend, diff --git a/drivers/isdn/hisax/elsa_cs.c b/drivers/isdn/hisax/elsa_cs.c index a0c5bad7bc6b..062fb8f0739f 100644 --- a/drivers/isdn/hisax/elsa_cs.c +++ b/drivers/isdn/hisax/elsa_cs.c @@ -96,8 +96,6 @@ module_param(protocol, int, 0); static void elsa_cs_config(dev_link_t *link); static void elsa_cs_release(dev_link_t *link); -static int elsa_cs_event(event_t event, int priority, - event_callback_args_t *args); /* The attach() and detach() entry points are used to create and destroy @@ -105,27 +103,8 @@ static int elsa_cs_event(event_t event, int priority, needed to manage one actual PCMCIA card. */ -static dev_link_t *elsa_cs_attach(void); static void elsa_cs_detach(struct pcmcia_device *p_dev); -/* - 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 = "elsa_cs"; - -/* - A linked list of "instances" of the elsa_cs device. Each actual - PCMCIA card corresponds to one device instance, and is described - by one dev_link_t structure (defined in ds.h). - - You may not want to use a linked list for this -- for example, the - memory card driver uses an array of dev_link_t pointers, where minor - device numbers are used to derive the corresponding array index. -*/ - /* A driver needs to provide a dev_node_t structure for each device on a card. In some cases, there is only one device per card (for @@ -160,18 +139,16 @@ typedef struct local_info_t { ======================================================================*/ -static dev_link_t *elsa_cs_attach(void) +static int elsa_cs_attach(struct pcmcia_device *p_dev) { - client_reg_t client_reg; dev_link_t *link; local_info_t *local; - int ret; DEBUG(0, "elsa_cs_attach()\n"); /* Allocate space for private device-specific data */ local = kmalloc(sizeof(local_info_t), GFP_KERNEL); - if (!local) return NULL; + if (!local) return -ENOMEM; memset(local, 0, sizeof(local_info_t)); local->cardnr = -1; link = &local->link; link->priv = local; @@ -196,19 +173,13 @@ static dev_link_t *elsa_cs_attach(void) link->conf.Vcc = 50; link->conf.IntType = INT_MEMORY_AND_IO; - /* Register with Card Services */ - link->next = NULL; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != CS_SUCCESS) { - cs_error(link->handle, RegisterClient, ret); - elsa_cs_detach(link->handle); - return NULL; - } + link->handle = p_dev; + p_dev->instance = link; - return link; + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + elsa_cs_config(link); + + return 0; } /* elsa_cs_attach */ /*====================================================================== @@ -447,36 +418,6 @@ static int elsa_resume(struct pcmcia_device *p_dev) return 0; } -/*====================================================================== - - 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 elsa_cs_event(event_t event, int priority, - event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - DEBUG(1, "elsa_cs_event(%d)\n", event); - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - elsa_cs_config(link); - break; - } - return 0; -} /* elsa_cs_event */ - static struct pcmcia_device_id elsa_ids[] = { PCMCIA_DEVICE_PROD_ID12("ELSA AG (Aachen, Germany)", "MicroLink ISDN/MC ", 0x983de2c4, 0x333ba257), PCMCIA_DEVICE_PROD_ID12("ELSA GmbH, Aachen", "MicroLink ISDN/MC ", 0x639e5718, 0x333ba257), @@ -489,8 +430,7 @@ static struct pcmcia_driver elsa_cs_driver = { .drv = { .name = "elsa_cs", }, - .attach = elsa_cs_attach, - .event = elsa_cs_event, + .probe = elsa_cs_attach, .remove = elsa_cs_detach, .id_table = elsa_ids, .suspend = elsa_suspend, diff --git a/drivers/isdn/hisax/sedlbauer_cs.c b/drivers/isdn/hisax/sedlbauer_cs.c index 814b32a9ef3b..6f5213a18a8d 100644 --- a/drivers/isdn/hisax/sedlbauer_cs.c +++ b/drivers/isdn/hisax/sedlbauer_cs.c @@ -97,8 +97,6 @@ module_param(protocol, int, 0); static void sedlbauer_config(dev_link_t *link); static void sedlbauer_release(dev_link_t *link); -static int sedlbauer_event(event_t event, int priority, - event_callback_args_t *args); /* The attach() and detach() entry points are used to create and destroy @@ -106,7 +104,6 @@ static int sedlbauer_event(event_t event, int priority, needed to manage one actual PCMCIA card. */ -static dev_link_t *sedlbauer_attach(void); static void sedlbauer_detach(struct pcmcia_device *p_dev); /* @@ -116,24 +113,6 @@ static void sedlbauer_detach(struct pcmcia_device *p_dev); less on other parts of the kernel. */ -/* - 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 = "sedlbauer_cs"; - -/* - A linked list of "instances" of the sedlbauer device. Each actual - PCMCIA card corresponds to one device instance, and is described - by one dev_link_t structure (defined in ds.h). - - You may not want to use a linked list for this -- for example, the - memory card driver uses an array of dev_link_t pointers, where minor - device numbers are used to derive the corresponding array index. -*/ - /* A driver needs to provide a dev_node_t structure for each device on a card. In some cases, there is only one device per card (for @@ -169,18 +148,16 @@ typedef struct local_info_t { ======================================================================*/ -static dev_link_t *sedlbauer_attach(void) +static int sedlbauer_attach(struct pcmcia_device *p_dev) { local_info_t *local; dev_link_t *link; - client_reg_t client_reg; - int ret; DEBUG(0, "sedlbauer_attach()\n"); /* Allocate space for private device-specific data */ local = kmalloc(sizeof(local_info_t), GFP_KERNEL); - if (!local) return NULL; + if (!local) return -ENOMEM; memset(local, 0, sizeof(local_info_t)); local->cardnr = -1; link = &local->link; link->priv = local; @@ -210,19 +187,13 @@ static dev_link_t *sedlbauer_attach(void) link->conf.Vcc = 50; link->conf.IntType = INT_MEMORY_AND_IO; - /* Register with Card Services */ - link->next = NULL; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != CS_SUCCESS) { - cs_error(link->handle, RegisterClient, ret); - sedlbauer_detach(link->handle); - return NULL; - } + link->handle = p_dev; + p_dev->instance = link; - return link; + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + sedlbauer_config(link); + + return 0; } /* sedlbauer_attach */ /*====================================================================== @@ -541,33 +512,6 @@ static int sedlbauer_resume(struct pcmcia_device *p_dev) return 0; } -/*====================================================================== - - The card status event handler. Mostly, this schedules other - stuff to run after an event is received. - - When a CARD_REMOVAL event is received, we immediately set a - private 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 sedlbauer_event(event_t event, int priority, - event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - DEBUG(1, "sedlbauer_event(0x%06x)\n", event); - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - sedlbauer_config(link); - break; - } - return 0; -} /* sedlbauer_event */ static struct pcmcia_device_id sedlbauer_ids[] = { PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "speed star II", "V 3.1", 0x81fb79f5, 0xf3612e1d, 0x6b95c78a), @@ -586,8 +530,7 @@ static struct pcmcia_driver sedlbauer_driver = { .drv = { .name = "sedlbauer_cs", }, - .attach = sedlbauer_attach, - .event = sedlbauer_event, + .probe = sedlbauer_attach, .remove = sedlbauer_detach, .id_table = sedlbauer_ids, .suspend = sedlbauer_suspend, diff --git a/drivers/isdn/hisax/teles_cs.c b/drivers/isdn/hisax/teles_cs.c index f956fceb9db2..4e5c14c7240e 100644 --- a/drivers/isdn/hisax/teles_cs.c +++ b/drivers/isdn/hisax/teles_cs.c @@ -77,8 +77,6 @@ module_param(protocol, int, 0); static void teles_cs_config(dev_link_t *link); static void teles_cs_release(dev_link_t *link); -static int teles_cs_event(event_t event, int priority, - event_callback_args_t *args); /* The attach() and detach() entry points are used to create and destroy @@ -86,17 +84,8 @@ static int teles_cs_event(event_t event, int priority, needed to manage one actual PCMCIA card. */ -static dev_link_t *teles_attach(void); static void teles_detach(struct pcmcia_device *p_dev); -/* - 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 = "teles_cs"; - /* A linked list of "instances" of the teles_cs device. Each actual PCMCIA card corresponds to one device instance, and is described @@ -141,18 +130,16 @@ typedef struct local_info_t { ======================================================================*/ -static dev_link_t *teles_attach(void) +static int teles_attach(struct pcmcia_device *p_dev) { - client_reg_t client_reg; dev_link_t *link; local_info_t *local; - int ret; DEBUG(0, "teles_attach()\n"); /* Allocate space for private device-specific data */ local = kmalloc(sizeof(local_info_t), GFP_KERNEL); - if (!local) return NULL; + if (!local) return -ENOMEM; memset(local, 0, sizeof(local_info_t)); local->cardnr = -1; link = &local->link; link->priv = local; @@ -177,19 +164,13 @@ static dev_link_t *teles_attach(void) link->conf.Vcc = 50; link->conf.IntType = INT_MEMORY_AND_IO; - /* Register with Card Services */ - link->next = NULL; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != CS_SUCCESS) { - cs_error(link->handle, RegisterClient, ret); - teles_detach(link->handle); - return NULL; - } + link->handle = p_dev; + p_dev->instance = link; - return link; + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + teles_cs_config(link); + + return 0; } /* teles_attach */ /*====================================================================== @@ -428,35 +409,6 @@ static int teles_resume(struct pcmcia_device *p_dev) return 0; } -/*====================================================================== - - 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 teles_cs_event(event_t event, int priority, - event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - DEBUG(1, "teles_cs_event(%d)\n", event); - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - teles_cs_config(link); - break; - } - return 0; -} /* teles_cs_event */ static struct pcmcia_device_id teles_ids[] = { PCMCIA_DEVICE_PROD_ID12("TELES", "S0/PC", 0x67b50eae, 0xe9e70119), @@ -469,8 +421,7 @@ static struct pcmcia_driver teles_cs_driver = { .drv = { .name = "teles_cs", }, - .attach = teles_attach, - .event = teles_cs_event, + .probe = teles_attach, .remove = teles_detach, .id_table = teles_ids, .suspend = teles_suspend, diff --git a/drivers/mtd/maps/pcmciamtd.c b/drivers/mtd/maps/pcmciamtd.c index 93c05dfa030d..f0f8916da7ad 100644 --- a/drivers/mtd/maps/pcmciamtd.c +++ b/drivers/mtd/maps/pcmciamtd.c @@ -66,8 +66,6 @@ struct pcmciamtd_dev { }; -static dev_info_t dev_info = "pcmciamtd"; - /* Module parameters */ /* 2 = do 16-bit transfers, 1 = do 8-bit transfers */ @@ -708,30 +706,6 @@ static int pcmciamtd_resume(struct pcmcia_device *dev) return 0; } -/* 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 driver from trying - * to talk to the card any more. - */ - -static int pcmciamtd_event(event_t event, int priority, - event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - DEBUG(1, "event=0x%06x", event); - switch (event) { - case CS_EVENT_CARD_INSERTION: - DEBUG(2, "EVENT_CARD_INSERTION"); - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - pcmciamtd_config(link); - break; - default: - DEBUG(2, "Unknown event %d", event); - } - return 0; -} - /* This deletes a driver "instance". The device is de-registered * with Card Services. If it has been released, all local data @@ -762,16 +736,14 @@ static void pcmciamtd_detach(struct pcmcia_device *p_dev) * with Card Services. */ -static dev_link_t *pcmciamtd_attach(void) +static int pcmciamtd_attach(struct pcmcia_device *p_dev) { struct pcmciamtd_dev *dev; dev_link_t *link; - client_reg_t client_reg; - int ret; /* Create new memory card device */ dev = kmalloc(sizeof(*dev), GFP_KERNEL); - if (!dev) return NULL; + if (!dev) return -ENOMEM; DEBUG(1, "dev=0x%p", dev); memset(dev, 0, sizeof(*dev)); @@ -782,20 +754,13 @@ static dev_link_t *pcmciamtd_attach(void) link->conf.IntType = INT_MEMORY; link->next = NULL; + link->handle = p_dev; + p_dev->instance = link; - /* Register with Card Services */ - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - DEBUG(2, "Calling RegisterClient"); - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != 0) { - cs_error(link->handle, RegisterClient, ret); - pcmciamtd_detach(link->handle); - return NULL; - } - DEBUG(2, "link = %p", link); - return link; + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + pcmciamtd_config(link); + + return 0; } static struct pcmcia_device_id pcmciamtd_ids[] = { @@ -829,8 +794,7 @@ static struct pcmcia_driver pcmciamtd_driver = { .drv = { .name = "pcmciamtd" }, - .attach = pcmciamtd_attach, - .event = pcmciamtd_event, + .probe = pcmciamtd_attach, .remove = pcmciamtd_detach, .owner = THIS_MODULE, .id_table = pcmciamtd_ids, diff --git a/drivers/net/pcmcia/3c574_cs.c b/drivers/net/pcmcia/3c574_cs.c index 8fcb63698ef1..48774efeec71 100644 --- a/drivers/net/pcmcia/3c574_cs.c +++ b/drivers/net/pcmcia/3c574_cs.c @@ -227,8 +227,6 @@ static char mii_preamble_required = 0; static void tc574_config(dev_link_t *link); static void tc574_release(dev_link_t *link); -static int tc574_event(event_t event, int priority, - event_callback_args_t *args); static void mdio_sync(kio_addr_t ioaddr, int bits); static int mdio_read(kio_addr_t ioaddr, int phy_id, int location); @@ -250,9 +248,6 @@ static int el3_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); static struct ethtool_ops netdev_ethtool_ops; static void set_rx_mode(struct net_device *dev); -static dev_info_t dev_info = "3c574_cs"; - -static dev_link_t *tc574_attach(void); static void tc574_detach(struct pcmcia_device *p_dev); /* @@ -261,20 +256,18 @@ static void tc574_detach(struct pcmcia_device *p_dev); with Card Services. */ -static dev_link_t *tc574_attach(void) +static int tc574_attach(struct pcmcia_device *p_dev) { struct el3_private *lp; - client_reg_t client_reg; dev_link_t *link; struct net_device *dev; - int ret; DEBUG(0, "3c574_attach()\n"); /* Create the PC card device object. */ dev = alloc_etherdev(sizeof(struct el3_private)); if (!dev) - return NULL; + return -ENOMEM; lp = netdev_priv(dev); link = &lp->link; link->priv = dev; @@ -305,19 +298,13 @@ static dev_link_t *tc574_attach(void) dev->watchdog_timeo = TX_TIMEOUT; #endif - /* Register with Card Services */ - link->next = NULL; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != 0) { - cs_error(link->handle, RegisterClient, ret); - tc574_detach(link->handle); - return NULL; - } + link->handle = p_dev; + p_dev->instance = link; - return link; + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + tc574_config(link); + + return 0; } /* tc574_attach */ /* @@ -565,29 +552,6 @@ static int tc574_resume(struct pcmcia_device *p_dev) return 0; } -/* - 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. -*/ - -static int tc574_event(event_t event, int priority, - event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - DEBUG(1, "3c574_event(0x%06x)\n", event); - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - tc574_config(link); - break; - } - return 0; -} /* tc574_event */ - static void dump_status(struct net_device *dev) { kio_addr_t ioaddr = dev->base_addr; @@ -1282,8 +1246,7 @@ static struct pcmcia_driver tc574_driver = { .drv = { .name = "3c574_cs", }, - .attach = tc574_attach, - .event = tc574_event, + .probe = tc574_attach, .remove = tc574_detach, .id_table = tc574_ids, .suspend = tc574_suspend, diff --git a/drivers/net/pcmcia/3c589_cs.c b/drivers/net/pcmcia/3c589_cs.c index 3516c02b9c89..1c3c9c666f74 100644 --- a/drivers/net/pcmcia/3c589_cs.c +++ b/drivers/net/pcmcia/3c589_cs.c @@ -143,8 +143,6 @@ DRV_NAME ".c " DRV_VERSION " 2001/10/13 00:08:50 (David Hinds)"; static void tc589_config(dev_link_t *link); static void tc589_release(dev_link_t *link); -static int tc589_event(event_t event, int priority, - event_callback_args_t *args); static u16 read_eeprom(kio_addr_t ioaddr, int index); static void tc589_reset(struct net_device *dev); @@ -161,9 +159,6 @@ static void el3_tx_timeout(struct net_device *dev); static void set_multicast_list(struct net_device *dev); static struct ethtool_ops netdev_ethtool_ops; -static dev_info_t dev_info = "3c589_cs"; - -static dev_link_t *tc589_attach(void); static void tc589_detach(struct pcmcia_device *p_dev); /*====================================================================== @@ -174,20 +169,18 @@ static void tc589_detach(struct pcmcia_device *p_dev); ======================================================================*/ -static dev_link_t *tc589_attach(void) +static int tc589_attach(struct pcmcia_device *p_dev) { struct el3_private *lp; - client_reg_t client_reg; dev_link_t *link; struct net_device *dev; - int ret; DEBUG(0, "3c589_attach()\n"); - + /* Create new ethernet device */ dev = alloc_etherdev(sizeof(struct el3_private)); if (!dev) - return NULL; + return -ENOMEM; lp = netdev_priv(dev); link = &lp->link; link->priv = dev; @@ -204,7 +197,7 @@ static dev_link_t *tc589_attach(void) link->conf.IntType = INT_MEMORY_AND_IO; link->conf.ConfigIndex = 1; link->conf.Present = PRESENT_OPTION; - + /* The EL3-specific entries in the device structure. */ SET_MODULE_OWNER(dev); dev->hard_start_xmit = &el3_start_xmit; @@ -219,19 +212,13 @@ static dev_link_t *tc589_attach(void) #endif SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops); - /* Register with Card Services */ - link->next = NULL; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != 0) { - cs_error(link->handle, RegisterClient, ret); - tc589_detach(link->handle); - return NULL; - } - - return link; + link->handle = p_dev; + p_dev->instance = link; + + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + tc589_config(link); + + return 0; } /* tc589_attach */ /*====================================================================== @@ -439,31 +426,6 @@ static int tc589_resume(struct pcmcia_device *p_dev) return 0; } -/*====================================================================== - - 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. - -======================================================================*/ - -static int tc589_event(event_t event, int priority, - event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - DEBUG(1, "3c589_event(0x%06x)\n", event); - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - tc589_config(link); - break; - } - return 0; -} /* tc589_event */ - /*====================================================================*/ /* @@ -1057,8 +1019,7 @@ static struct pcmcia_driver tc589_driver = { .drv = { .name = "3c589_cs", }, - .attach = tc589_attach, - .event = tc589_event, + .probe = tc589_attach, .remove = tc589_detach, .id_table = tc589_ids, .suspend = tc589_suspend, diff --git a/drivers/net/pcmcia/axnet_cs.c b/drivers/net/pcmcia/axnet_cs.c index 3d36207d3332..01ddfc8cce3f 100644 --- a/drivers/net/pcmcia/axnet_cs.c +++ b/drivers/net/pcmcia/axnet_cs.c @@ -87,8 +87,6 @@ static char *version = static void axnet_config(dev_link_t *link); static void axnet_release(dev_link_t *link); -static int axnet_event(event_t event, int priority, - event_callback_args_t *args); static int axnet_open(struct net_device *dev); static int axnet_close(struct net_device *dev); static int axnet_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); @@ -107,11 +105,8 @@ static void block_input(struct net_device *dev, int count, static void block_output(struct net_device *dev, int count, const u_char *buf, const int start_page); -static dev_link_t *axnet_attach(void); static void axnet_detach(struct pcmcia_device *p_dev); -static dev_info_t dev_info = "axnet_cs"; - static void axdev_setup(struct net_device *dev); static void AX88190_init(struct net_device *dev, int startp); static int ax_open(struct net_device *dev); @@ -146,13 +141,11 @@ static inline axnet_dev_t *PRIV(struct net_device *dev) ======================================================================*/ -static dev_link_t *axnet_attach(void) +static int axnet_attach(struct pcmcia_device *p_dev) { axnet_dev_t *info; dev_link_t *link; struct net_device *dev; - client_reg_t client_reg; - int ret; DEBUG(0, "axnet_attach()\n"); @@ -160,7 +153,7 @@ static dev_link_t *axnet_attach(void) "eth%d", axdev_setup); if (!dev) - return NULL; + return -ENOMEM; info = PRIV(dev); link = &info->link; @@ -175,19 +168,13 @@ static dev_link_t *axnet_attach(void) dev->do_ioctl = &axnet_ioctl; SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops); - /* Register with Card Services */ - link->next = NULL; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != CS_SUCCESS) { - cs_error(link->handle, RegisterClient, ret); - axnet_detach(link->handle); - return NULL; - } + link->handle = p_dev; + p_dev->instance = link; - return link; + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + axnet_config(link); + + return 0; } /* axnet_attach */ /*====================================================================== @@ -511,31 +498,6 @@ static int axnet_resume(struct pcmcia_device *p_dev) } -/*====================================================================== - - 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. - -======================================================================*/ - -static int axnet_event(event_t event, int priority, - event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - DEBUG(2, "axnet_event(0x%06x)\n", event); - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - axnet_config(link); - break; - } - return 0; -} /* axnet_event */ - /*====================================================================== MII interface support @@ -608,7 +570,7 @@ static int axnet_open(struct net_device *dev) link->open++; - request_irq(dev->irq, ei_irq_wrapper, SA_SHIRQ, dev_info, dev); + request_irq(dev->irq, ei_irq_wrapper, SA_SHIRQ, "axnet_cs", dev); info->link_status = 0x00; init_timer(&info->watchdog); @@ -869,8 +831,7 @@ static struct pcmcia_driver axnet_cs_driver = { .drv = { .name = "axnet_cs", }, - .attach = axnet_attach, - .event = axnet_event, + .probe = axnet_attach, .remove = axnet_detach, .id_table = axnet_ids, .suspend = axnet_suspend, diff --git a/drivers/net/pcmcia/com20020_cs.c b/drivers/net/pcmcia/com20020_cs.c index d48dbd3e153a..2827a48ea37c 100644 --- a/drivers/net/pcmcia/com20020_cs.c +++ b/drivers/net/pcmcia/com20020_cs.c @@ -120,12 +120,7 @@ MODULE_LICENSE("GPL"); static void com20020_config(dev_link_t *link); static void com20020_release(dev_link_t *link); -static int com20020_event(event_t event, int priority, - event_callback_args_t *args); -static dev_info_t dev_info = "com20020_cs"; - -static dev_link_t *com20020_attach(void); static void com20020_detach(struct pcmcia_device *p_dev); /*====================================================================*/ @@ -143,21 +138,19 @@ typedef struct com20020_dev_t { ======================================================================*/ -static dev_link_t *com20020_attach(void) +static int com20020_attach(struct pcmcia_device *p_dev) { - client_reg_t client_reg; dev_link_t *link; com20020_dev_t *info; struct net_device *dev; - int ret; struct arcnet_local *lp; - + DEBUG(0, "com20020_attach()\n"); /* Create new network device */ link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL); if (!link) - return NULL; + return -ENOMEM; info = kmalloc(sizeof(struct com20020_dev_t), GFP_KERNEL); if (!info) @@ -189,29 +182,19 @@ static dev_link_t *com20020_attach(void) link->conf.IntType = INT_MEMORY_AND_IO; link->conf.Present = PRESENT_OPTION; - link->irq.Instance = info->dev = dev; link->priv = info; - /* Register with Card Services */ - link->next = NULL; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != 0) { - cs_error(link->handle, RegisterClient, ret); - com20020_detach(link->handle); - return NULL; - } + link->state |= DEV_PRESENT; + com20020_config(link); - return link; + return 0; fail_alloc_dev: kfree(info); fail_alloc_info: kfree(link); - return NULL; + return -ENOMEM; } /* com20020_attach */ /*====================================================================== @@ -442,31 +425,6 @@ static int com20020_resume(struct pcmcia_device *p_dev) return 0; } -/*====================================================================== - - 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. - -======================================================================*/ - -static int com20020_event(event_t event, int priority, - event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - DEBUG(1, "com20020_event(0x%06x)\n", event); - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT; - com20020_config(link); - break; - } - return 0; -} /* com20020_event */ - static struct pcmcia_device_id com20020_ids[] = { PCMCIA_DEVICE_PROD_ID12("Contemporary Control Systems, Inc.", "PCM20 Arcnet Adapter", 0x59991666, 0x95dfffaf), PCMCIA_DEVICE_NULL @@ -478,8 +436,7 @@ static struct pcmcia_driver com20020_cs_driver = { .drv = { .name = "com20020_cs", }, - .attach = com20020_attach, - .event = com20020_event, + .probe = com20020_attach, .remove = com20020_detach, .id_table = com20020_ids, .suspend = com20020_suspend, diff --git a/drivers/net/pcmcia/fmvj18x_cs.c b/drivers/net/pcmcia/fmvj18x_cs.c index dad6393052ff..28fe2fb4d6c0 100644 --- a/drivers/net/pcmcia/fmvj18x_cs.c +++ b/drivers/net/pcmcia/fmvj18x_cs.c @@ -88,9 +88,6 @@ static void fmvj18x_config(dev_link_t *link); static int fmvj18x_get_hwinfo(dev_link_t *link, u_char *node_id); static int fmvj18x_setup_mfc(dev_link_t *link); static void fmvj18x_release(dev_link_t *link); -static int fmvj18x_event(event_t event, int priority, - event_callback_args_t *args); -static dev_link_t *fmvj18x_attach(void); static void fmvj18x_detach(struct pcmcia_device *p_dev); /* @@ -108,8 +105,6 @@ static void set_rx_mode(struct net_device *dev); static void fjn_tx_timeout(struct net_device *dev); static struct ethtool_ops netdev_ethtool_ops; -static dev_info_t dev_info = "fmvj18x_cs"; - /* card type */ @@ -233,20 +228,18 @@ typedef struct local_info_t { #define BANK_1U 0x24 /* bank 1 (CONFIG_1) */ #define BANK_2U 0x28 /* bank 2 (CONFIG_1) */ -static dev_link_t *fmvj18x_attach(void) +static int fmvj18x_attach(struct pcmcia_device *p_dev) { local_info_t *lp; dev_link_t *link; struct net_device *dev; - client_reg_t client_reg; - int ret; - + DEBUG(0, "fmvj18x_attach()\n"); /* Make up a FMVJ18x specific data structure */ dev = alloc_etherdev(sizeof(local_info_t)); if (!dev) - return NULL; + return -ENOMEM; lp = netdev_priv(dev); link = &lp->link; link->priv = dev; @@ -261,7 +254,7 @@ static dev_link_t *fmvj18x_attach(void) link->irq.IRQInfo1 = IRQ_LEVEL_ID; link->irq.Handler = &fjn_interrupt; link->irq.Instance = dev; - + /* General socket configuration */ link->conf.Attributes = CONF_ENABLE_IRQ; link->conf.Vcc = 50; @@ -280,20 +273,14 @@ static dev_link_t *fmvj18x_attach(void) dev->watchdog_timeo = TX_TIMEOUT; #endif SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops); - - /* Register with Card Services */ - link->next = NULL; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != 0) { - cs_error(link->handle, RegisterClient, ret); - fmvj18x_detach(link->handle); - return NULL; - } - return link; + link->handle = p_dev; + p_dev->instance = link; + + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + fmvj18x_config(link); + + return 0; } /* fmvj18x_attach */ /*====================================================================*/ @@ -734,22 +721,6 @@ static int fmvj18x_resume(struct pcmcia_device *p_dev) /*====================================================================*/ -static int fmvj18x_event(event_t event, int priority, - event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - DEBUG(1, "fmvj18x_event(0x%06x)\n", event); - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - fmvj18x_config(link); - break; - } - return 0; -} /* fmvj18x_event */ - static struct pcmcia_device_id fmvj18x_ids[] = { PCMCIA_DEVICE_MANF_CARD(0x0004, 0x0004), PCMCIA_DEVICE_PROD_ID12("EAGLE Technology", "NE200 ETHERNET LAN MBH10302 04", 0x528c88c4, 0x74f91e59), @@ -780,8 +751,7 @@ static struct pcmcia_driver fmvj18x_cs_driver = { .drv = { .name = "fmvj18x_cs", }, - .attach = fmvj18x_attach, - .event = fmvj18x_event, + .probe = fmvj18x_attach, .remove = fmvj18x_detach, .id_table = fmvj18x_ids, .suspend = fmvj18x_suspend, diff --git a/drivers/net/pcmcia/ibmtr_cs.c b/drivers/net/pcmcia/ibmtr_cs.c index 90da35d1f4a5..b9c7e39576f5 100644 --- a/drivers/net/pcmcia/ibmtr_cs.c +++ b/drivers/net/pcmcia/ibmtr_cs.c @@ -108,12 +108,6 @@ MODULE_LICENSE("GPL"); static void ibmtr_config(dev_link_t *link); static void ibmtr_hw_setup(struct net_device *dev, u_int mmiobase); static void ibmtr_release(dev_link_t *link); -static int ibmtr_event(event_t event, int priority, - event_callback_args_t *args); - -static dev_info_t dev_info = "ibmtr_cs"; - -static dev_link_t *ibmtr_attach(void); static void ibmtr_detach(struct pcmcia_device *p_dev); /*====================================================================*/ @@ -144,25 +138,23 @@ static struct ethtool_ops netdev_ethtool_ops = { ======================================================================*/ -static dev_link_t *ibmtr_attach(void) +static int ibmtr_attach(struct pcmcia_device *p_dev) { ibmtr_dev_t *info; dev_link_t *link; struct net_device *dev; - client_reg_t client_reg; - int ret; DEBUG(0, "ibmtr_attach()\n"); /* Create new token-ring device */ info = kmalloc(sizeof(*info), GFP_KERNEL); - if (!info) return NULL; + if (!info) return -ENOMEM; memset(info,0,sizeof(*info)); dev = alloc_trdev(sizeof(struct tok_info)); - if (!dev) { - kfree(info); - return NULL; - } + if (!dev) { + kfree(info); + return -ENOMEM; + } link = &info->link; link->priv = info; @@ -183,24 +175,13 @@ static dev_link_t *ibmtr_attach(void) SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops); - /* Register with Card Services */ - link->next = NULL; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != 0) { - cs_error(link->handle, RegisterClient, ret); - goto out_detach; - } + link->handle = p_dev; + p_dev->instance = link; -out: - return link; + link->state |= DEV_PRESENT; + ibmtr_config(link); -out_detach: - ibmtr_detach(link->handle); - link = NULL; - goto out; + return 0; } /* ibmtr_attach */ /*====================================================================== @@ -420,31 +401,6 @@ static int ibmtr_resume(struct pcmcia_device *p_dev) } -/*====================================================================== - - 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. - -======================================================================*/ - -static int ibmtr_event(event_t event, int priority, - event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - DEBUG(1, "ibmtr_event(0x%06x)\n", event); - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT; - ibmtr_config(link); - break; - } - return 0; -} /* ibmtr_event */ - /*====================================================================*/ static void ibmtr_hw_setup(struct net_device *dev, u_int mmiobase) @@ -500,8 +456,7 @@ static struct pcmcia_driver ibmtr_cs_driver = { .drv = { .name = "ibmtr_cs", }, - .attach = ibmtr_attach, - .event = ibmtr_event, + .probe = ibmtr_attach, .remove = ibmtr_detach, .id_table = ibmtr_ids, .suspend = ibmtr_suspend, diff --git a/drivers/net/pcmcia/nmclan_cs.c b/drivers/net/pcmcia/nmclan_cs.c index 0c9cb9f49a81..4a232254a497 100644 --- a/drivers/net/pcmcia/nmclan_cs.c +++ b/drivers/net/pcmcia/nmclan_cs.c @@ -388,8 +388,6 @@ static char *version = DRV_NAME " " DRV_VERSION " (Roger C. Pao)"; #endif -static dev_info_t dev_info="nmclan_cs"; - static char *if_names[]={ "Auto", "10baseT", "BNC", }; @@ -421,8 +419,6 @@ Function Prototypes static void nmclan_config(dev_link_t *link); static void nmclan_release(dev_link_t *link); -static int nmclan_event(event_t event, int priority, - event_callback_args_t *args); static void nmclan_reset(struct net_device *dev); static int mace_config(struct net_device *dev, struct ifmap *map); @@ -438,7 +434,6 @@ static void set_multicast_list(struct net_device *dev); static struct ethtool_ops netdev_ethtool_ops; -static dev_link_t *nmclan_attach(void); static void nmclan_detach(struct pcmcia_device *p_dev); /* ---------------------------------------------------------------------------- @@ -448,13 +443,11 @@ nmclan_attach Services. ---------------------------------------------------------------------------- */ -static dev_link_t *nmclan_attach(void) +static int nmclan_attach(struct pcmcia_device *p_dev) { mace_private *lp; dev_link_t *link; struct net_device *dev; - client_reg_t client_reg; - int ret; DEBUG(0, "nmclan_attach()\n"); DEBUG(1, "%s\n", rcsid); @@ -462,7 +455,7 @@ static dev_link_t *nmclan_attach(void) /* Create new ethernet device */ dev = alloc_etherdev(sizeof(mace_private)); if (!dev) - return NULL; + return -ENOMEM; lp = netdev_priv(dev); link = &lp->link; link->priv = dev; @@ -496,19 +489,13 @@ static dev_link_t *nmclan_attach(void) dev->watchdog_timeo = TX_TIMEOUT; #endif - /* Register with Card Services */ - link->next = NULL; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != 0) { - cs_error(link->handle, RegisterClient, ret); - nmclan_detach(link->handle); - return NULL; - } + link->handle = p_dev; + p_dev->instance = link; - return link; + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + nmclan_config(link); + + return 0; } /* nmclan_attach */ /* ---------------------------------------------------------------------------- @@ -821,31 +808,6 @@ static int nmclan_resume(struct pcmcia_device *p_dev) return 0; } -/* ---------------------------------------------------------------------------- -nmclan_event - 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. ----------------------------------------------------------------------------- */ -static int nmclan_event(event_t event, int priority, - event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - DEBUG(1, "nmclan_event(0x%06x)\n", event); - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - nmclan_config(link); - break; - case CS_EVENT_RESET_REQUEST: - return 1; - break; - } - return 0; -} /* nmclan_event */ /* ---------------------------------------------------------------------------- nmclan_reset @@ -1673,8 +1635,7 @@ static struct pcmcia_driver nmclan_cs_driver = { .drv = { .name = "nmclan_cs", }, - .attach = nmclan_attach, - .event = nmclan_event, + .probe = nmclan_attach, .remove = nmclan_detach, .id_table = nmclan_ids, .suspend = nmclan_suspend, diff --git a/drivers/net/pcmcia/pcnet_cs.c b/drivers/net/pcmcia/pcnet_cs.c index b35c951fc6fa..d85b758f3efa 100644 --- a/drivers/net/pcmcia/pcnet_cs.c +++ b/drivers/net/pcmcia/pcnet_cs.c @@ -105,8 +105,6 @@ module_param_array(hw_addr, int, NULL, 0); static void mii_phy_probe(struct net_device *dev); static void pcnet_config(dev_link_t *link); static void pcnet_release(dev_link_t *link); -static int pcnet_event(event_t event, int priority, - event_callback_args_t *args); static int pcnet_open(struct net_device *dev); static int pcnet_close(struct net_device *dev); static int ei_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); @@ -120,7 +118,6 @@ static int setup_shmem_window(dev_link_t *link, int start_pg, static int setup_dma_config(dev_link_t *link, int start_pg, int stop_pg); -static dev_link_t *pcnet_attach(void); static void pcnet_detach(struct pcmcia_device *p_dev); static dev_info_t dev_info = "pcnet_cs"; @@ -243,19 +240,17 @@ static inline pcnet_dev_t *PRIV(struct net_device *dev) ======================================================================*/ -static dev_link_t *pcnet_attach(void) +static int pcnet_probe(struct pcmcia_device *p_dev) { pcnet_dev_t *info; dev_link_t *link; struct net_device *dev; - client_reg_t client_reg; - int ret; DEBUG(0, "pcnet_attach()\n"); /* Create new ethernet device */ dev = __alloc_ei_netdev(sizeof(pcnet_dev_t)); - if (!dev) return NULL; + if (!dev) return -ENOMEM; info = PRIV(dev); link = &info->link; link->priv = dev; @@ -270,19 +265,13 @@ static dev_link_t *pcnet_attach(void) dev->stop = &pcnet_close; dev->set_config = &set_config; - /* Register with Card Services */ - link->next = NULL; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != CS_SUCCESS) { - cs_error(link->handle, RegisterClient, ret); - pcnet_detach(link->handle); - return NULL; - } + link->handle = p_dev; + p_dev->instance = link; - return link; + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + pcnet_config(link); + + return 0; } /* pcnet_attach */ /*====================================================================== @@ -800,21 +789,6 @@ static int pcnet_resume(struct pcmcia_device *p_dev) return 0; } -static int pcnet_event(event_t event, int priority, - event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - DEBUG(2, "pcnet_event(0x%06x)\n", event); - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - pcnet_config(link); - break; - } - return 0; -} /* pcnet_event */ /*====================================================================== @@ -1835,8 +1809,7 @@ static struct pcmcia_driver pcnet_driver = { .drv = { .name = "pcnet_cs", }, - .attach = pcnet_attach, - .event = pcnet_event, + .probe = pcnet_probe, .remove = pcnet_detach, .owner = THIS_MODULE, .id_table = pcnet_ids, diff --git a/drivers/net/pcmcia/smc91c92_cs.c b/drivers/net/pcmcia/smc91c92_cs.c index 9eb5cecfb2f5..0122415dfeef 100644 --- a/drivers/net/pcmcia/smc91c92_cs.c +++ b/drivers/net/pcmcia/smc91c92_cs.c @@ -102,8 +102,6 @@ static const char *version = currently have room for another Tx packet. */ #define MEMORY_WAIT_TIME 8 -static dev_info_t dev_info = "smc91c92_cs"; - struct smc_private { dev_link_t link; spinlock_t lock; @@ -279,12 +277,9 @@ enum RxCfg { RxAllMulti = 0x0004, RxPromisc = 0x0002, /*====================================================================*/ -static dev_link_t *smc91c92_attach(void); static void smc91c92_detach(struct pcmcia_device *p_dev); static void smc91c92_config(dev_link_t *link); static void smc91c92_release(dev_link_t *link); -static int smc91c92_event(event_t event, int priority, - event_callback_args_t *args); static int smc_open(struct net_device *dev); static int smc_close(struct net_device *dev); @@ -313,20 +308,18 @@ static struct ethtool_ops ethtool_ops; ======================================================================*/ -static dev_link_t *smc91c92_attach(void) +static int smc91c92_attach(struct pcmcia_device *p_dev) { - client_reg_t client_reg; struct smc_private *smc; dev_link_t *link; struct net_device *dev; - int ret; DEBUG(0, "smc91c92_attach()\n"); /* Create new ethernet device */ dev = alloc_etherdev(sizeof(struct smc_private)); if (!dev) - return NULL; + return -ENOMEM; smc = netdev_priv(dev); link = &smc->link; link->priv = dev; @@ -364,19 +357,13 @@ static dev_link_t *smc91c92_attach(void) smc->mii_if.phy_id_mask = 0x1f; smc->mii_if.reg_num_mask = 0x1f; - /* Register with Card Services */ - link->next = NULL; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != 0) { - cs_error(link->handle, RegisterClient, ret); - smc91c92_detach(link->handle); - return NULL; - } + link->handle = p_dev; + p_dev->instance = link; - return link; + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + smc91c92_config(link); + + return 0; } /* smc91c92_attach */ /*====================================================================== @@ -1210,31 +1197,6 @@ static void smc91c92_release(dev_link_t *link) link->state &= ~DEV_CONFIG; } -/*====================================================================== - - 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. - -======================================================================*/ - -static int smc91c92_event(event_t event, int priority, - event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - DEBUG(1, "smc91c92_event(0x%06x)\n", event); - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - smc91c92_config(link); - break; - } - return 0; -} /* smc91c92_event */ - /*====================================================================== MII interface support for SMC91cXX based cards @@ -2349,8 +2311,7 @@ static struct pcmcia_driver smc91c92_cs_driver = { .drv = { .name = "smc91c92_cs", }, - .attach = smc91c92_attach, - .event = smc91c92_event, + .probe = smc91c92_attach, .remove = smc91c92_detach, .id_table = smc91c92_ids, .suspend = smc91c92_suspend, diff --git a/drivers/net/pcmcia/xirc2ps_cs.c b/drivers/net/pcmcia/xirc2ps_cs.c index 8c8cc40bbb7d..049c34b37067 100644 --- a/drivers/net/pcmcia/xirc2ps_cs.c +++ b/drivers/net/pcmcia/xirc2ps_cs.c @@ -292,8 +292,6 @@ static void mii_wr(kio_addr_t ioaddr, u_char phyaddr, u_char phyreg, static int has_ce2_string(dev_link_t * link); static void xirc2ps_config(dev_link_t * link); static void xirc2ps_release(dev_link_t * link); -static int xirc2ps_event(event_t event, int priority, - event_callback_args_t * args); /**************** * The attach() and detach() entry points are used to create and destroy @@ -301,7 +299,6 @@ static int xirc2ps_event(event_t event, int priority, * needed to manage one actual PCMCIA card. */ -static dev_link_t *xirc2ps_attach(void); static void xirc2ps_detach(struct pcmcia_device *p_dev); /**************** @@ -313,14 +310,6 @@ static void xirc2ps_detach(struct pcmcia_device *p_dev); static irqreturn_t xirc2ps_interrupt(int irq, void *dev_id, struct pt_regs *regs); -/* - * 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 = "xirc2ps_cs"; - /**************** * A linked list of "instances" of the device. Each actual * PCMCIA card corresponds to one device instance, and is described @@ -563,21 +552,19 @@ mii_wr(kio_addr_t ioaddr, u_char phyaddr, u_char phyreg, unsigned data, int len) * card insertion event. */ -static dev_link_t * -xirc2ps_attach(void) +static int +xirc2ps_attach(struct pcmcia_device *p_dev) { - client_reg_t client_reg; dev_link_t *link; struct net_device *dev; local_info_t *local; - int err; DEBUG(0, "attach()\n"); /* Allocate the device structure */ dev = alloc_etherdev(sizeof(local_info_t)); if (!dev) - return NULL; + return -ENOMEM; local = netdev_priv(dev); link = &local->link; link->priv = dev; @@ -606,18 +593,13 @@ xirc2ps_attach(void) dev->watchdog_timeo = TX_TIMEOUT; #endif - /* Register with Card Services */ - link->next = NULL; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - if ((err = pcmcia_register_client(&link->handle, &client_reg))) { - cs_error(link->handle, RegisterClient, err); - xirc2ps_detach(link->handle); - return NULL; - } + link->handle = p_dev; + p_dev->instance = link; - return link; + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + xirc2ps_config(link); + + return 0; } /* xirc2ps_attach */ /**************** @@ -1162,34 +1144,6 @@ static int xirc2ps_resume(struct pcmcia_device *p_dev) return 0; } -/**************** - * 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 -xirc2ps_event(event_t event, int priority, - event_callback_args_t * args) -{ - dev_link_t *link = args->client_data; - - DEBUG(0, "event(%d)\n", (int)event); - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - xirc2ps_config(link); - break; - } - return 0; -} /* xirc2ps_event */ /*====================================================================*/ @@ -1981,8 +1935,7 @@ static struct pcmcia_driver xirc2ps_cs_driver = { .drv = { .name = "xirc2ps_cs", }, - .attach = xirc2ps_attach, - .event = xirc2ps_event, + .probe = xirc2ps_attach, .remove = xirc2ps_detach, .id_table = xirc2ps_ids, .suspend = xirc2ps_suspend, diff --git a/drivers/net/wireless/airo_cs.c b/drivers/net/wireless/airo_cs.c index 88805a4c29f1..a496460ce224 100644 --- a/drivers/net/wireless/airo_cs.c +++ b/drivers/net/wireless/airo_cs.c @@ -82,8 +82,6 @@ MODULE_SUPPORTED_DEVICE("Aironet 4500, 4800 and Cisco 340 PCMCIA cards"); static void airo_config(dev_link_t *link); static void airo_release(dev_link_t *link); -static int airo_event(event_t event, int priority, - event_callback_args_t *args); /* The attach() and detach() entry points are used to create and destroy @@ -91,7 +89,6 @@ static int airo_event(event_t event, int priority, needed to manage one actual PCMCIA card. */ -static dev_link_t *airo_attach(void); static void airo_detach(struct pcmcia_device *p_dev); /* @@ -101,14 +98,6 @@ static void airo_detach(struct pcmcia_device *p_dev); less on other parts of the kernel. */ -/* - 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 = "airo_cs"; - /* A linked list of "instances" of the aironet device. Each actual PCMCIA card corresponds to one device instance, and is described @@ -152,20 +141,18 @@ typedef struct local_info_t { ======================================================================*/ -static dev_link_t *airo_attach(void) +static int airo_attach(struct pcmcia_device *p_dev) { - client_reg_t client_reg; dev_link_t *link; local_info_t *local; - int ret; - + DEBUG(0, "airo_attach()\n"); /* Initialize the dev_link_t structure */ link = kzalloc(sizeof(struct dev_link_t), GFP_KERNEL); if (!link) { printk(KERN_ERR "airo_cs: no memory for new device\n"); - return NULL; + return -ENOMEM; } /* Interrupt setup */ @@ -189,23 +176,17 @@ static dev_link_t *airo_attach(void) if (!local) { printk(KERN_ERR "airo_cs: no memory for new device\n"); kfree (link); - return NULL; + return -ENOMEM; } link->priv = local; - - /* Register with Card Services */ - link->next = NULL; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != 0) { - cs_error(link->handle, RegisterClient, ret); - airo_detach(link->handle); - return NULL; - } - - return link; + + link->handle = p_dev; + p_dev->instance = link; + + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + airo_config(link); + + return 0; } /* airo_attach */ /*====================================================================== @@ -497,34 +478,6 @@ static int airo_resume(struct pcmcia_device *p_dev) return 0; } -/*====================================================================== - - The card status event handler. Mostly, this schedules other - stuff to run after an event is received. - - When a CARD_REMOVAL event is received, we immediately set a - private 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 airo_event(event_t event, int priority, - event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - DEBUG(1, "airo_event(0x%06x)\n", event); - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - airo_config(link); - break; - } - return 0; -} /* airo_event */ - static struct pcmcia_device_id airo_ids[] = { PCMCIA_DEVICE_MANF_CARD(0x015f, 0x000a), PCMCIA_DEVICE_MANF_CARD(0x015f, 0x0005), @@ -539,8 +492,7 @@ static struct pcmcia_driver airo_driver = { .drv = { .name = "airo_cs", }, - .attach = airo_attach, - .event = airo_event, + .probe = airo_attach, .remove = airo_detach, .id_table = airo_ids, .suspend = airo_suspend, diff --git a/drivers/net/wireless/atmel_cs.c b/drivers/net/wireless/atmel_cs.c index 32f009709355..d6f4a5a3e55a 100644 --- a/drivers/net/wireless/atmel_cs.c +++ b/drivers/net/wireless/atmel_cs.c @@ -93,8 +93,6 @@ MODULE_SUPPORTED_DEVICE("Atmel at76c50x PCMCIA cards"); static void atmel_config(dev_link_t *link); static void atmel_release(dev_link_t *link); -static int atmel_event(event_t event, int priority, - event_callback_args_t *args); /* The attach() and detach() entry points are used to create and destroy @@ -102,7 +100,6 @@ static int atmel_event(event_t event, int priority, needed to manage one actual PCMCIA card. */ -static dev_link_t *atmel_attach(void); static void atmel_detach(struct pcmcia_device *p_dev); /* @@ -112,14 +109,6 @@ static void atmel_detach(struct pcmcia_device *p_dev); less on other parts of the kernel. */ -/* - 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 = "atmel_cs"; - /* A linked list of "instances" of the atmelnet device. Each actual PCMCIA card corresponds to one device instance, and is described @@ -163,27 +152,25 @@ typedef struct local_info_t { ======================================================================*/ -static dev_link_t *atmel_attach(void) +static int atmel_attach(struct pcmcia_device *p_dev) { - client_reg_t client_reg; dev_link_t *link; local_info_t *local; - int ret; - + DEBUG(0, "atmel_attach()\n"); /* Initialize the dev_link_t structure */ link = kzalloc(sizeof(struct dev_link_t), GFP_KERNEL); if (!link) { printk(KERN_ERR "atmel_cs: no memory for new device\n"); - return NULL; + return -ENOMEM; } - + /* Interrupt setup */ link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; link->irq.IRQInfo1 = IRQ_LEVEL_ID; link->irq.Handler = NULL; - + /* General socket configuration defaults can go here. In this client, we assume very little, and rely on the CIS for almost @@ -194,29 +181,23 @@ static dev_link_t *atmel_attach(void) link->conf.Attributes = 0; link->conf.Vcc = 50; link->conf.IntType = INT_MEMORY_AND_IO; - + /* Allocate space for private device-specific data */ local = kzalloc(sizeof(local_info_t), GFP_KERNEL); if (!local) { printk(KERN_ERR "atmel_cs: no memory for new device\n"); kfree (link); - return NULL; + return -ENOMEM; } link->priv = local; - - /* Register with Card Services */ - link->next = NULL; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != 0) { - cs_error(link->handle, RegisterClient, ret); - atmel_detach(link->handle); - return NULL; - } - - return link; + + link->handle = p_dev; + p_dev->instance = link; + + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + atmel_config(link); + + return 0; } /* atmel_attach */ /*====================================================================== @@ -485,34 +466,6 @@ static int atmel_resume(struct pcmcia_device *dev) return 0; } -/*====================================================================== - - The card status event handler. Mostly, this schedules other - stuff to run after an event is received. - - When a CARD_REMOVAL event is received, we immediately set a - private 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 atmel_event(event_t event, int priority, - event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - DEBUG(1, "atmel_event(0x%06x)\n", event); - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - atmel_config(link); - break; - } - return 0; -} /* atmel_event */ - /*====================================================================*/ /* We use the driver_info field to store the correct firmware type for a card. */ @@ -562,8 +515,7 @@ static struct pcmcia_driver atmel_driver = { .drv = { .name = "atmel_cs", }, - .attach = atmel_attach, - .event = atmel_event, + .probe = atmel_attach, .remove = atmel_detach, .id_table = atmel_ids, .suspend = atmel_suspend, diff --git a/drivers/net/wireless/hostap/hostap_cs.c b/drivers/net/wireless/hostap/hostap_cs.c index 195a5bf3d725..8bc0b528548f 100644 --- a/drivers/net/wireless/hostap/hostap_cs.c +++ b/drivers/net/wireless/hostap/hostap_cs.c @@ -204,8 +204,7 @@ static int hfa384x_to_bap(struct net_device *dev, u16 bap, void *buf, int len) static void prism2_detach(struct pcmcia_device *p_dev); static void prism2_release(u_long arg); -static int prism2_event(event_t event, int priority, - event_callback_args_t *args); +static int prism2_config(dev_link_t *link); static int prism2_pccard_card_present(local_info_t *local) @@ -502,15 +501,13 @@ static struct prism2_helper_functions prism2_pccard_funcs = /* allocate local data and register with CardServices * initialize dev_link structure, but do not configure the card yet */ -static dev_link_t *prism2_attach(void) +static int prism2_attach(struct pcmcia_device *p_dev) { dev_link_t *link; - client_reg_t client_reg; - int ret; link = kmalloc(sizeof(dev_link_t), GFP_KERNEL); if (link == NULL) - return NULL; + return -ENOMEM; memset(link, 0, sizeof(dev_link_t)); @@ -518,18 +515,14 @@ static dev_link_t *prism2_attach(void) link->conf.Vcc = 33; link->conf.IntType = INT_MEMORY_AND_IO; - /* register with CardServices */ - link->next = NULL; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != CS_SUCCESS) { - cs_error(link->handle, RegisterClient, ret); - prism2_detach(link->handle); - return NULL; - } - return link; + link->handle = p_dev; + p_dev->instance = link; + + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + if (prism2_config(link)) + PDEBUG(DEBUG_EXTRA, "prism2_config() failed\n"); + + return 0; } @@ -878,29 +871,6 @@ static int hostap_cs_resume(struct pcmcia_device *p_dev) return 0; } -static int prism2_event(event_t event, int priority, - event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - switch (event) { - case CS_EVENT_CARD_INSERTION: - PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_CARD_INSERTION\n", dev_info); - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - if (prism2_config(link)) { - PDEBUG(DEBUG_EXTRA, "prism2_config() failed\n"); - } - break; - - default: - PDEBUG(DEBUG_EXTRA, "%s: prism2_event() - unknown event %d\n", - dev_info, event); - break; - } - return 0; -} - - static struct pcmcia_device_id hostap_cs_ids[] = { PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7100), PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7300), @@ -959,10 +929,9 @@ static struct pcmcia_driver hostap_driver = { .drv = { .name = "hostap_cs", }, - .attach = prism2_attach, + .probe = prism2_attach, .remove = prism2_detach, .owner = THIS_MODULE, - .event = prism2_event, .id_table = hostap_cs_ids, .suspend = hostap_cs_suspend, .resume = hostap_cs_resume, diff --git a/drivers/net/wireless/netwave_cs.c b/drivers/net/wireless/netwave_cs.c index af9a32d8d22d..bf6271ee387a 100644 --- a/drivers/net/wireless/netwave_cs.c +++ b/drivers/net/wireless/netwave_cs.c @@ -166,8 +166,6 @@ static char *version = #define DEBUG(n, args...) #endif -static dev_info_t dev_info = "netwave_cs"; - /*====================================================================*/ /* Parameters that can be set with 'insmod' */ @@ -195,11 +193,8 @@ module_param(mem_speed, int, 0); /* PCMCIA (Card Services) related functions */ static void netwave_release(dev_link_t *link); /* Card removal */ -static int netwave_event(event_t event, int priority, - event_callback_args_t *args); static void netwave_pcmcia_config(dev_link_t *arg); /* Runs after card insertion */ -static dev_link_t *netwave_attach(void); /* Create instance */ static void netwave_detach(struct pcmcia_device *p_dev); /* Destroy instance */ /* Hardware configuration */ @@ -383,20 +378,18 @@ static struct iw_statistics *netwave_get_wireless_stats(struct net_device *dev) * configure the card at this point -- we wait until we receive a * card insertion event. */ -static dev_link_t *netwave_attach(void) +static int netwave_attach(struct pcmcia_device *p_dev) { - client_reg_t client_reg; dev_link_t *link; struct net_device *dev; netwave_private *priv; - int ret; - + DEBUG(0, "netwave_attach()\n"); - + /* Initialize the dev_link_t structure */ dev = alloc_etherdev(sizeof(netwave_private)); if (!dev) - return NULL; + return -ENOMEM; priv = netdev_priv(dev); link = &priv->link; link->priv = dev; @@ -438,20 +431,14 @@ static dev_link_t *netwave_attach(void) dev->open = &netwave_open; dev->stop = &netwave_close; link->irq.Instance = dev; - - /* Register with Card Services */ - link->next = NULL; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != 0) { - cs_error(link->handle, RegisterClient, ret); - netwave_detach(link->handle); - return NULL; - } - return link; + link->handle = p_dev; + p_dev->instance = link; + + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + netwave_pcmcia_config( link); + + return 0; } /* netwave_attach */ /* @@ -934,36 +921,6 @@ static int netwave_resume(struct pcmcia_device *p_dev) } -/* - * Function netwave_event (event, priority, args) - * - * 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 netwave_event(event_t event, int priority, - event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - DEBUG(1, "netwave_event(0x%06x)\n", event); - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - netwave_pcmcia_config( link); - break; - } - return 0; -} /* netwave_event */ - /* * Function netwave_doreset (ioBase, ramBase) * @@ -1456,8 +1413,7 @@ static struct pcmcia_driver netwave_driver = { .drv = { .name = "netwave_cs", }, - .attach = netwave_attach, - .event = netwave_event, + .probe = netwave_attach, .remove = netwave_detach, .id_table = netwave_ids, .suspend = netwave_suspend, diff --git a/drivers/net/wireless/orinoco_cs.c b/drivers/net/wireless/orinoco_cs.c index bfeeef49f0b3..b664708481cc 100644 --- a/drivers/net/wireless/orinoco_cs.c +++ b/drivers/net/wireless/orinoco_cs.c @@ -42,17 +42,6 @@ static int ignore_cis_vcc; /* = 0 */ module_param(ignore_cis_vcc, int, 0); MODULE_PARM_DESC(ignore_cis_vcc, "Allow voltage mismatch between card and socket"); -/********************************************************************/ -/* Magic constants */ -/********************************************************************/ - -/* - * 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 = DRIVER_NAME; - /********************************************************************/ /* Data structures */ /********************************************************************/ @@ -74,6 +63,7 @@ struct orinoco_pccard { /* Function prototypes */ /********************************************************************/ +static void orinoco_cs_config(dev_link_t *link); static void orinoco_cs_release(dev_link_t *link); static void orinoco_cs_detach(struct pcmcia_device *p_dev); @@ -113,19 +103,17 @@ orinoco_cs_hard_reset(struct orinoco_private *priv) * 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. */ -static dev_link_t * -orinoco_cs_attach(void) +static int +orinoco_cs_attach(struct pcmcia_device *p_dev) { struct net_device *dev; struct orinoco_private *priv; struct orinoco_pccard *card; dev_link_t *link; - client_reg_t client_reg; - int ret; dev = alloc_orinocodev(sizeof(*card), orinoco_cs_hard_reset); if (! dev) - return NULL; + return -ENOMEM; priv = netdev_priv(dev); card = priv->card; @@ -150,18 +138,13 @@ orinoco_cs_attach(void) /* Register with Card Services */ link->next = NULL; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; /* FIXME: what does this mean? */ - client_reg.event_callback_args.client_data = link; + link->handle = p_dev; + p_dev->instance = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != CS_SUCCESS) { - cs_error(link->handle, RegisterClient, ret); - orinoco_cs_detach(link->handle); - return NULL; - } + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + orinoco_cs_config(link); - return link; + return 0; } /* orinoco_cs_attach */ /* @@ -521,26 +504,6 @@ static int orinoco_cs_resume(struct pcmcia_device *p_dev) } -/* - * The card status event handler. Mostly, this schedules other stuff - * to run after an event is received. - */ -static int -orinoco_cs_event(event_t event, int priority, - event_callback_args_t * args) -{ - dev_link_t *link = args->client_data; - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - orinoco_cs_config(link); - break; - } - - return 0; -} /* orinoco_cs_event */ - /********************************************************************/ /* Module initialization */ /********************************************************************/ @@ -640,9 +603,8 @@ static struct pcmcia_driver orinoco_driver = { .drv = { .name = DRIVER_NAME, }, - .attach = orinoco_cs_attach, + .probe = orinoco_cs_attach, .remove = orinoco_cs_detach, - .event = orinoco_cs_event, .id_table = orinoco_cs_ids, .suspend = orinoco_cs_suspend, .resume = orinoco_cs_resume, diff --git a/drivers/net/wireless/ray_cs.c b/drivers/net/wireless/ray_cs.c index 33a89e292126..319180ca7e71 100644 --- a/drivers/net/wireless/ray_cs.c +++ b/drivers/net/wireless/ray_cs.c @@ -92,8 +92,6 @@ module_param(pc_debug, int, 0); /** Prototypes based on PCMCIA skeleton driver *******************************/ static void ray_config(dev_link_t *link); static void ray_release(dev_link_t *link); -static int ray_event(event_t event, int priority, event_callback_args_t *args); -static dev_link_t *ray_attach(void); static void ray_detach(struct pcmcia_device *p_dev); /***** Prototypes indicated by device structure ******************************/ @@ -192,12 +190,6 @@ static int bc; static char *phy_addr = NULL; -/* 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 = "ray_cs"; - /* A linked list of "instances" of the ray device. Each actual PCMCIA card corresponds to one device instance, and is described by one dev_link_t structure (defined in ds.h). @@ -314,12 +306,10 @@ static char rcsid[] = "Raylink/WebGear wireless LAN - Corey stop = &ray_dev_close; netif_stop_queue(dev); - /* Register with Card Services */ - link->next = dev_list; - dev_list = link; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - - DEBUG(2,"ray_cs ray_attach calling pcmcia_register_client(...)\n"); - init_timer(&local->timer); - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != 0) { - printk("ray_cs ray_attach RegisterClient unhappy - detaching\n"); - cs_error(link->handle, RegisterClient, ret); - ray_detach(link->handle); - return NULL; - } - DEBUG(2,"ray_cs ray_attach ending\n"); - return link; + link->handle = p_dev; + p_dev->instance = link; + + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + ray_config(link); + + return 0; fail_alloc_dev: kfree(link); - return NULL; + return -ENOMEM; } /* ray_attach */ /*============================================================================= This deletes a driver "instance". The device is de-registered @@ -924,32 +903,6 @@ static int ray_resume(struct pcmcia_device *p_dev) return 0; } -/*============================================================================= - 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 ray_event(event_t event, int priority, - event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - DEBUG(1, "ray_event(0x%06x)\n", event); - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - ray_config(link); - break; - } - return 0; - DEBUG(2,"ray_event ending\n"); -} /* ray_event */ /*===========================================================================*/ int ray_dev_init(struct net_device *dev) { @@ -2945,8 +2898,7 @@ static struct pcmcia_driver ray_driver = { .drv = { .name = "ray_cs", }, - .attach = ray_attach, - .event = ray_event, + .probe = ray_attach, .remove = ray_detach, .id_table = ray_ids, .suspend = ray_suspend, diff --git a/drivers/net/wireless/spectrum_cs.c b/drivers/net/wireless/spectrum_cs.c index 1933250dad1a..fee4be1ce810 100644 --- a/drivers/net/wireless/spectrum_cs.c +++ b/drivers/net/wireless/spectrum_cs.c @@ -56,17 +56,6 @@ static int ignore_cis_vcc; /* = 0 */ module_param(ignore_cis_vcc, int, 0); MODULE_PARM_DESC(ignore_cis_vcc, "Allow voltage mismatch between card and socket"); -/********************************************************************/ -/* Magic constants */ -/********************************************************************/ - -/* - * 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 = DRIVER_NAME; - /********************************************************************/ /* Data structures */ /********************************************************************/ @@ -82,8 +71,8 @@ struct orinoco_pccard { /* Function prototypes */ /********************************************************************/ +static void spectrum_cs_config(dev_link_t *link); static void spectrum_cs_release(dev_link_t *link); -static void spectrum_cs_detach(struct pcmcia_device *p_dev); /********************************************************************/ /* Firmware downloader */ @@ -594,19 +583,17 @@ spectrum_cs_hard_reset(struct orinoco_private *priv) * 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. */ -static dev_link_t * -spectrum_cs_attach(void) +static int +spectrum_cs_attach(struct pcmcia_device *p_dev) { struct net_device *dev; struct orinoco_private *priv; struct orinoco_pccard *card; dev_link_t *link; - client_reg_t client_reg; - int ret; dev = alloc_orinocodev(sizeof(*card), spectrum_cs_hard_reset); if (! dev) - return NULL; + return -ENOMEM; priv = netdev_priv(dev); card = priv->card; @@ -628,22 +615,13 @@ spectrum_cs_attach(void) link->conf.Attributes = 0; link->conf.IntType = INT_MEMORY_AND_IO; - /* Register with Card Services */ - /* FIXME: need a lock? */ - link->next = NULL; /* not needed */ + link->handle = p_dev; + p_dev->instance = link; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; /* FIXME: what does this mean? */ - client_reg.event_callback_args.client_data = link; + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + spectrum_cs_config(link); - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != CS_SUCCESS) { - cs_error(link->handle, RegisterClient, ret); - spectrum_cs_detach(link->handle); - return NULL; - } - - return link; + return 0; } /* spectrum_cs_attach */ /* @@ -977,26 +955,6 @@ spectrum_cs_resume(struct pcmcia_device *p_dev) return 0; } -/* - * The card status event handler. Mostly, this schedules other stuff - * to run after an event is received. - */ -static int -spectrum_cs_event(event_t event, int priority, - event_callback_args_t * args) -{ - dev_link_t *link = args->client_data; - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - spectrum_cs_config(link); - break; - - } - - return 0; -} /* spectrum_cs_event */ /********************************************************************/ /* Module initialization */ @@ -1021,11 +979,10 @@ static struct pcmcia_driver orinoco_driver = { .drv = { .name = DRIVER_NAME, }, - .attach = spectrum_cs_attach, + .probe = spectrum_cs_attach, .remove = spectrum_cs_detach, .suspend = spectrum_cs_suspend, .resume = spectrum_cs_resume, - .event = spectrum_cs_event, .id_table = spectrum_cs_ids, }; diff --git a/drivers/net/wireless/wavelan_cs.c b/drivers/net/wireless/wavelan_cs.c index 196e827fc846..7e2039f52c49 100644 --- a/drivers/net/wireless/wavelan_cs.c +++ b/drivers/net/wireless/wavelan_cs.c @@ -4594,14 +4594,12 @@ wavelan_close(struct net_device * dev) * configure the card at this point -- we wait until we receive a * card insertion event. */ -static dev_link_t * -wavelan_attach(void) +static int +wavelan_attach(struct pcmcia_device *p_dev) { - client_reg_t client_reg; /* Register with cardmgr */ dev_link_t * link; /* Info for cardmgr */ struct net_device * dev; /* Interface generic data */ net_local * lp; /* Interface specific data */ - int ret; #ifdef DEBUG_CALLBACK_TRACE printk(KERN_DEBUG "-> wavelan_attach()\n"); @@ -4609,7 +4607,7 @@ wavelan_attach(void) /* Initialize the dev_link_t structure */ link = kzalloc(sizeof(struct dev_link_t), GFP_KERNEL); - if (!link) return NULL; + if (!link) return -ENOMEM; /* The io structure describes IO port mapping */ link->io.NumPorts1 = 8; @@ -4633,7 +4631,7 @@ wavelan_attach(void) dev = alloc_etherdev(sizeof(net_local)); if (!dev) { kfree(link); - return NULL; + return -ENOMEM; } link->priv = link->irq.Instance = dev; @@ -4678,28 +4676,21 @@ wavelan_attach(void) /* Other specific data */ dev->mtu = WAVELAN_MTU; - /* Register with Card Services */ - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; + link->handle = p_dev; + p_dev->instance = link; -#ifdef DEBUG_CONFIG_INFO - printk(KERN_DEBUG "wavelan_attach(): almost done, calling pcmcia_register_client\n"); -#endif - - ret = pcmcia_register_client(&link->handle, &client_reg); - if(ret != 0) - { - cs_error(link->handle, RegisterClient, ret); - wavelan_detach(link->handle); - return NULL; - } + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + if(wv_pcmcia_config(link) && + wv_hw_config(dev)) + wv_init_info(dev); + else + dev->irq = 0; #ifdef DEBUG_CALLBACK_TRACE printk(KERN_DEBUG "<- wavelan_attach()\n"); #endif - return link; + return 0; } /*------------------------------------------------------------------*/ @@ -4801,52 +4792,6 @@ static int wavelan_resume(struct pcmcia_device *p_dev) } -/*------------------------------------------------------------------*/ -/* - * 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. - */ -static int -wavelan_event(event_t event, /* The event received */ - int priority, - event_callback_args_t * args) -{ - dev_link_t * link = (dev_link_t *) args->client_data; - struct net_device * dev = (struct net_device *) link->priv; - -#ifdef DEBUG_CALLBACK_TRACE - printk(KERN_DEBUG "->wavelan_event(): %s\n", - ((event == CS_EVENT_REGISTRATION_COMPLETE)?"registration complete" : - ((event == CS_EVENT_CARD_REMOVAL) ? "card removal" : - ((event == CS_EVENT_CARD_INSERTION) ? "card insertion" : - ((event == CS_EVENT_PM_SUSPEND) ? "pm suspend" : - ((event == CS_EVENT_RESET_PHYSICAL) ? "physical reset" : - ((event == CS_EVENT_PM_RESUME) ? "pm resume" : - ((event == CS_EVENT_CARD_RESET) ? "card reset" : - "unknown")))))))); -#endif - - switch(event) - { - case CS_EVENT_CARD_INSERTION: - /* Reset and configure the card */ - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - if(wv_pcmcia_config(link) && - wv_hw_config(dev)) - wv_init_info(dev); - else - dev->irq = 0; - break; - } - -#ifdef DEBUG_CALLBACK_TRACE - printk(KERN_DEBUG "<-wavelan_event()\n"); -#endif - return 0; -} - static struct pcmcia_device_id wavelan_ids[] = { PCMCIA_DEVICE_PROD_ID12("AT&T","WaveLAN/PCMCIA", 0xe7c5affd, 0x1bc50975), PCMCIA_DEVICE_PROD_ID12("Digital", "RoamAbout/DS", 0x9999ab35, 0x00d05e06), @@ -4861,8 +4806,7 @@ static struct pcmcia_driver wavelan_driver = { .drv = { .name = "wavelan_cs", }, - .attach = wavelan_attach, - .event = wavelan_event, + .probe = wavelan_attach, .remove = wavelan_detach, .id_table = wavelan_ids, .suspend = wavelan_suspend, diff --git a/drivers/net/wireless/wavelan_cs.p.h b/drivers/net/wireless/wavelan_cs.p.h index a1a19177c5cd..f2d597568151 100644 --- a/drivers/net/wireless/wavelan_cs.p.h +++ b/drivers/net/wireless/wavelan_cs.p.h @@ -754,19 +754,11 @@ static void static int wavelan_open(struct net_device *), /* Open the device */ wavelan_close(struct net_device *); /* Close the device */ -static dev_link_t * - wavelan_attach(void); /* Create a new device */ static void wavelan_detach(struct pcmcia_device *p_dev); /* Destroy a removed device */ -static int - wavelan_event(event_t, /* Manage pcmcia events */ - int, - event_callback_args_t *); /**************************** VARIABLES ****************************/ -static dev_info_t dev_info = "wavelan_cs"; - /* * Parameters that can be set with 'insmod' * The exact syntax is 'insmod wavelan_cs.o =' diff --git a/drivers/net/wireless/wl3501_cs.c b/drivers/net/wireless/wl3501_cs.c index 21e498fe7b14..48e10b0c7e74 100644 --- a/drivers/net/wireless/wl3501_cs.c +++ b/drivers/net/wireless/wl3501_cs.c @@ -105,7 +105,6 @@ module_param(pc_debug, int, 0); */ static void wl3501_config(dev_link_t *link); static void wl3501_release(dev_link_t *link); -static int wl3501_event(event_t event, int pri, event_callback_args_t *args); /* * The dev_info variable is the "key" that is used to match up this @@ -1954,18 +1953,16 @@ static const struct iw_handler_def wl3501_handler_def = { * 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. */ -static dev_link_t *wl3501_attach(void) +static int wl3501_attach(struct pcmcia_device *p_dev) { - client_reg_t client_reg; dev_link_t *link; struct net_device *dev; struct wl3501_card *this; - int ret; /* Initialize the dev_link_t structure */ link = kzalloc(sizeof(*link), GFP_KERNEL); if (!link) - goto out; + return -ENOMEM; /* The io structure describes IO port mapping */ link->io.NumPorts1 = 16; @@ -2001,24 +1998,17 @@ static dev_link_t *wl3501_attach(void) netif_stop_queue(dev); link->priv = link->irq.Instance = dev; - /* Register with Card Services */ - link->next = wl3501_dev_list; - wl3501_dev_list = link; - client_reg.dev_info = &wl3501_dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret) { - cs_error(link->handle, RegisterClient, ret); - wl3501_detach(link->handle); - link = NULL; - } -out: - return link; + link->handle = p_dev; + p_dev->instance = link; + + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + wl3501_config(link); + + return 0; out_link: kfree(link); link = NULL; - goto out; + return -ENOMEM; } #define CS_CHECK(fn, ret) \ @@ -2206,33 +2196,6 @@ static int wl3501_resume(struct pcmcia_device *p_dev) } -/** - * wl3501_event - The card status event handler - * @event - event - * @pri - priority - * @args - arguments for this event - * - * 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 wl3501_event(event_t event, int pri, event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - wl3501_config(link); - break; - } - return 0; -} - static struct pcmcia_device_id wl3501_ids[] = { PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0001), PCMCIA_DEVICE_NULL @@ -2244,8 +2207,7 @@ static struct pcmcia_driver wl3501_driver = { .drv = { .name = "wl3501_cs", }, - .attach = wl3501_attach, - .event = wl3501_event, + .probe = wl3501_attach, .remove = wl3501_detach, .id_table = wl3501_ids, .suspend = wl3501_suspend, diff --git a/drivers/parport/parport_cs.c b/drivers/parport/parport_cs.c index 763f91a79085..158d92563259 100644 --- a/drivers/parport/parport_cs.c +++ b/drivers/parport/parport_cs.c @@ -87,14 +87,9 @@ typedef struct parport_info_t { struct parport *port; } parport_info_t; -static dev_link_t *parport_attach(void); static void parport_detach(struct pcmcia_device *p_dev); static void parport_config(dev_link_t *link); static void parport_cs_release(dev_link_t *); -static int parport_event(event_t event, int priority, - event_callback_args_t *args); - -static dev_info_t dev_info = "parport_cs"; /*====================================================================== @@ -104,18 +99,16 @@ static dev_info_t dev_info = "parport_cs"; ======================================================================*/ -static dev_link_t *parport_attach(void) +static int parport_attach(struct pcmcia_device *p_dev) { parport_info_t *info; dev_link_t *link; - client_reg_t client_reg; - int ret; - + DEBUG(0, "parport_attach()\n"); /* Create new parport device */ info = kmalloc(sizeof(*info), GFP_KERNEL); - if (!info) return NULL; + if (!info) return -ENOMEM; memset(info, 0, sizeof(*info)); link = &info->link; link->priv = info; @@ -126,20 +119,14 @@ static dev_link_t *parport_attach(void) link->conf.Attributes = CONF_ENABLE_IRQ; link->conf.Vcc = 50; link->conf.IntType = INT_MEMORY_AND_IO; - - /* Register with Card Services */ - link->next = NULL; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != CS_SUCCESS) { - cs_error(link->handle, RegisterClient, ret); - parport_detach(link->handle); - return NULL; - } - - return link; + + link->handle = p_dev; + p_dev->instance = link; + + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + parport_config(link); + + return 0; } /* parport_attach */ /*====================================================================== @@ -329,29 +316,6 @@ static int parport_resume(struct pcmcia_device *dev) return 0; } -/*====================================================================== - - The card status event handler. Mostly, this schedules other - stuff to run after an event is received. - -======================================================================*/ - -int parport_event(event_t event, int priority, - event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - DEBUG(1, "parport_event(0x%06x)\n", event); - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - parport_config(link); - break; - } - return 0; -} /* parport_event */ - static struct pcmcia_device_id parport_ids[] = { PCMCIA_DEVICE_FUNC_ID(3), PCMCIA_DEVICE_MANF_CARD(0x0137, 0x0003), @@ -364,8 +328,7 @@ static struct pcmcia_driver parport_cs_driver = { .drv = { .name = "parport_cs", }, - .attach = parport_attach, - .event = parport_event, + .probe = parport_attach, .remove = parport_detach, .id_table = parport_ids, .suspend = parport_suspend, diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index 8eff55b6c9e9..0fc61dd1d4d0 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -203,7 +203,7 @@ static void pcmcia_check_driver(struct pcmcia_driver *p_drv) unsigned int i; u32 hash; - if (!p_drv->attach || !p_drv->event || !p_drv->remove) + if (!p_drv->probe || !p_drv->remove) printk(KERN_DEBUG "pcmcia: %s lacks a requisite callback " "function\n", p_drv->drv.name); @@ -361,6 +361,7 @@ static int pcmcia_device_probe(struct device * dev) { struct pcmcia_device *p_dev; struct pcmcia_driver *p_drv; + struct pcmcia_socket *s; int ret = 0; dev = get_device(dev); @@ -369,25 +370,39 @@ static int pcmcia_device_probe(struct device * dev) p_dev = to_pcmcia_dev(dev); p_drv = to_pcmcia_drv(dev->driver); + s = p_dev->socket; - if (!try_module_get(p_drv->owner)) { + if ((!p_drv->probe) || (!try_module_get(p_drv->owner))) { ret = -EINVAL; goto put_dev; } - if (p_drv->attach) { - p_dev->instance = p_drv->attach(); - if ((!p_dev->instance) || (p_dev->state & CLIENT_UNBOUND)) { - printk(KERN_NOTICE "ds: unable to create instance " - "of '%s'!\n", p_drv->drv.name); - ret = -EINVAL; + p_dev->state &= ~CLIENT_UNBOUND; + + /* set up the device configuration, if it hasn't been done before */ + if (!s->functions) { + cistpl_longlink_mfc_t mfc; + if (pccard_read_tuple(s, p_dev->func, CISTPL_LONGLINK_MFC, + &mfc) == CS_SUCCESS) + s->functions = mfc.nfn; + else + s->functions = 1; + s->config = kmalloc(sizeof(config_t) * s->functions, + GFP_KERNEL); + if (!s->config) { + ret = -ENOMEM; + goto put_module; } + memset(s->config, 0, sizeof(config_t) * s->functions); } + ret = p_drv->probe(p_dev); + + put_module: if (ret) module_put(p_drv->owner); put_dev: - if ((ret) || !(p_drv->attach)) + if (ret) put_device(dev); return (ret); } @@ -418,11 +433,8 @@ static int pcmcia_device_remove(struct device * dev) printk(KERN_INFO "pcmcia: driver %s did not release windows properly\n", p_drv->drv.name); - /* undo pcmcia_register_client */ - p_dev->state = CLIENT_UNBOUND; - pcmcia_put_dev(p_dev); - /* references from pcmcia_probe_device */ + p_dev->state = CLIENT_UNBOUND; pcmcia_put_dev(p_dev); module_put(p_drv->owner); @@ -1042,49 +1054,6 @@ static int pcmcia_bus_suspend(struct pcmcia_socket *skt) ======================================================================*/ -struct send_event_data { - struct pcmcia_socket *skt; - event_t event; - int priority; -}; - -static int send_event_callback(struct device *dev, void * _data) -{ - struct pcmcia_device *p_dev = to_pcmcia_dev(dev); - struct pcmcia_driver *p_drv; - struct send_event_data *data = _data; - - /* we get called for all sockets, but may only pass the event - * for drivers _on the affected socket_ */ - if (p_dev->socket != data->skt) - return 0; - - p_drv = to_pcmcia_drv(p_dev->dev.driver); - if (!p_drv) - return 0; - - if (p_dev->state & (CLIENT_UNBOUND|CLIENT_STALE)) - return 0; - - if (p_drv->event) - return p_drv->event(data->event, data->priority, - &p_dev->event_callback_args); - - return 0; -} - -static int send_event(struct pcmcia_socket *s, event_t event, int priority) -{ - struct send_event_data private; - - private.skt = s; - private.event = event; - private.priority = priority; - - return bus_for_each_dev(&pcmcia_bus_type, NULL, &private, send_event_callback); -} /* send_event */ - - /* Normally, the event is passed to individual drivers after * informing userspace. Only for CS_EVENT_CARD_REMOVAL this * is inversed to maintain historic compatibility. @@ -1093,20 +1062,17 @@ static int send_event(struct pcmcia_socket *s, event_t event, int priority) static int ds_event(struct pcmcia_socket *skt, event_t event, int priority) { struct pcmcia_socket *s = pcmcia_get_socket(skt); - int ret = 0; ds_dbg(1, "ds_event(0x%06x, %d, 0x%p)\n", event, priority, skt); - - switch (event) { + switch (event) { case CS_EVENT_CARD_REMOVAL: s->pcmcia_state.present = 0; - send_event(skt, event, priority); pcmcia_card_remove(skt); handle_event(skt, event); break; - + case CS_EVENT_CARD_INSERTION: s->pcmcia_state.present = 1; pcmcia_card_add(skt); @@ -1114,19 +1080,14 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority) break; case CS_EVENT_EJECTION_REQUEST: - ret = send_event(skt, event, priority); break; case CS_EVENT_PM_SUSPEND: case CS_EVENT_PM_RESUME: case CS_EVENT_RESET_PHYSICAL: case CS_EVENT_CARD_RESET: - handle_event(skt, event); - break; - default: handle_event(skt, event); - send_event(skt, event, priority); break; } @@ -1136,90 +1097,6 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority) } /* ds_event */ - -int pcmcia_register_client(struct pcmcia_device **handle, client_reg_t *req) -{ - struct pcmcia_socket *s = NULL; - struct pcmcia_device *p_dev = NULL; - struct pcmcia_driver *p_drv = NULL; - - /* Look for unbound client with matching dev_info */ - down_read(&pcmcia_socket_list_rwsem); - list_for_each_entry(s, &pcmcia_socket_list, socket_list) { - unsigned long flags; - - if (s->state & SOCKET_CARDBUS) - continue; - - s = pcmcia_get_socket(s); - if (!s) - continue; - spin_lock_irqsave(&pcmcia_dev_list_lock, flags); - list_for_each_entry(p_dev, &s->devices_list, socket_device_list) { - p_dev = pcmcia_get_dev(p_dev); - if (!p_dev) - continue; - if (!(p_dev->state & CLIENT_UNBOUND) || - (!p_dev->dev.driver)) { - pcmcia_put_dev(p_dev); - continue; - } - p_drv = to_pcmcia_drv(p_dev->dev.driver); - if (!strncmp(p_drv->drv.name, (char *)req->dev_info, DEV_NAME_LEN)) { - spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); - goto found; - } - pcmcia_put_dev(p_dev); - } - spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); - pcmcia_put_socket(s); - } - found: - up_read(&pcmcia_socket_list_rwsem); - if (!p_dev) - return -ENODEV; - - pcmcia_put_socket(s); /* safe, as we already hold a reference from bind_device */ - - *handle = p_dev; - p_dev->state &= ~CLIENT_UNBOUND; - p_dev->event_callback_args = req->event_callback_args; - p_dev->event_callback_args.client_handle = p_dev; - - - if (!s->functions) { - cistpl_longlink_mfc_t mfc; - if (pccard_read_tuple(s, p_dev->func, CISTPL_LONGLINK_MFC, &mfc) - == CS_SUCCESS) - s->functions = mfc.nfn; - else - s->functions = 1; - s->config = kmalloc(sizeof(config_t) * s->functions, - GFP_KERNEL); - if (!s->config) - goto out_no_resource; - memset(s->config, 0, sizeof(config_t) * s->functions); - } - - ds_dbg(1, "register_client(): client 0x%p, dev %s\n", - p_dev, p_dev->dev.bus_id); - - if ((s->state & (SOCKET_PRESENT|SOCKET_CARDBUS)) == SOCKET_PRESENT) { - if (p_drv->event) - p_drv->event(CS_EVENT_CARD_INSERTION, CS_EVENT_PRI_LOW, - &p_dev->event_callback_args); - - } - - return CS_SUCCESS; - - out_no_resource: - pcmcia_put_dev(p_dev); - return CS_OUT_OF_RESOURCE; -} /* register_client */ -EXPORT_SYMBOL(pcmcia_register_client); - - static struct pcmcia_callback pcmcia_bus_callback = { .owner = THIS_MODULE, .event = ds_event, diff --git a/drivers/scsi/pcmcia/aha152x_stub.c b/drivers/scsi/pcmcia/aha152x_stub.c index 3128ba8c57a9..0c9edb7051f4 100644 --- a/drivers/scsi/pcmcia/aha152x_stub.c +++ b/drivers/scsi/pcmcia/aha152x_stub.c @@ -95,27 +95,21 @@ typedef struct scsi_info_t { } scsi_info_t; static void aha152x_release_cs(dev_link_t *link); -static int aha152x_event(event_t event, int priority, - event_callback_args_t *args); - -static dev_link_t *aha152x_attach(void); static void aha152x_detach(struct pcmcia_device *p_dev); +static void aha152x_config_cs(dev_link_t *link); static dev_link_t *dev_list; -static dev_info_t dev_info = "aha152x_cs"; -static dev_link_t *aha152x_attach(void) +static int aha152x_attach(struct pcmcia_device *p_dev) { scsi_info_t *info; - client_reg_t client_reg; dev_link_t *link; - int ret; DEBUG(0, "aha152x_attach()\n"); /* Create new SCSI device */ info = kmalloc(sizeof(*info), GFP_KERNEL); - if (!info) return NULL; + if (!info) return -ENOMEM; memset(info, 0, sizeof(*info)); link = &info->link; link->priv = info; @@ -129,20 +123,13 @@ static dev_link_t *aha152x_attach(void) link->conf.IntType = INT_MEMORY_AND_IO; link->conf.Present = PRESENT_OPTION; - /* Register with Card Services */ - link->next = dev_list; - dev_list = link; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != 0) { - cs_error(link->handle, RegisterClient, ret); - aha152x_detach(link->handle); - return NULL; - } - - return link; + link->handle = p_dev; + p_dev->instance = link; + + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + aha152x_config_cs(link); + + return 0; } /* aha152x_attach */ /*====================================================================*/ @@ -297,22 +284,6 @@ static int aha152x_resume(struct pcmcia_device *dev) return 0; } -static int aha152x_event(event_t event, int priority, - event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - DEBUG(0, "aha152x_event(0x%06x)\n", event); - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - aha152x_config_cs(link); - break; - } - return 0; -} - static struct pcmcia_device_id aha152x_ids[] = { PCMCIA_DEVICE_PROD_ID123("New Media", "SCSI", "Bus Toaster", 0xcdf7e4cc, 0x35f26476, 0xa8851d6e), PCMCIA_DEVICE_PROD_ID123("NOTEWORTHY", "SCSI", "Bus Toaster", 0xad89c6e8, 0x35f26476, 0xa8851d6e), @@ -328,8 +299,7 @@ static struct pcmcia_driver aha152x_cs_driver = { .drv = { .name = "aha152x_cs", }, - .attach = aha152x_attach, - .event = aha152x_event, + .probe = aha152x_attach, .remove = aha152x_detach, .id_table = aha152x_ids, .suspend = aha152x_suspend, diff --git a/drivers/scsi/pcmcia/fdomain_stub.c b/drivers/scsi/pcmcia/fdomain_stub.c index 538fedb97924..788c58d805f3 100644 --- a/drivers/scsi/pcmcia/fdomain_stub.c +++ b/drivers/scsi/pcmcia/fdomain_stub.c @@ -80,27 +80,19 @@ typedef struct scsi_info_t { static void fdomain_release(dev_link_t *link); -static int fdomain_event(event_t event, int priority, - event_callback_args_t *args); - -static dev_link_t *fdomain_attach(void); static void fdomain_detach(struct pcmcia_device *p_dev); +static void fdomain_config(dev_link_t *link); - -static dev_info_t dev_info = "fdomain_cs"; - -static dev_link_t *fdomain_attach(void) +static int fdomain_attach(struct pcmcia_device *p_dev) { scsi_info_t *info; - client_reg_t client_reg; dev_link_t *link; - int ret; - + DEBUG(0, "fdomain_attach()\n"); /* Create new SCSI device */ info = kmalloc(sizeof(*info), GFP_KERNEL); - if (!info) return NULL; + if (!info) return -ENOMEM; memset(info, 0, sizeof(*info)); link = &info->link; link->priv = info; link->io.NumPorts1 = 0x10; @@ -113,19 +105,13 @@ static dev_link_t *fdomain_attach(void) link->conf.IntType = INT_MEMORY_AND_IO; link->conf.Present = PRESENT_OPTION; - /* Register with Card Services */ - link->next = NULL; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != 0) { - cs_error(link->handle, RegisterClient, ret); - fdomain_detach(link->handle); - return NULL; - } - - return link; + link->handle = p_dev; + p_dev->instance = link; + + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + fdomain_config(link); + + return 0; } /* fdomain_attach */ /*====================================================================*/ @@ -265,23 +251,6 @@ static int fdomain_resume(struct pcmcia_device *dev) return 0; } -static int fdomain_event(event_t event, int priority, - event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - DEBUG(1, "fdomain_event(0x%06x)\n", event); - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - fdomain_config(link); - break; - } - return 0; -} /* fdomain_event */ - - static struct pcmcia_device_id fdomain_ids[] = { PCMCIA_DEVICE_PROD_ID12("IBM Corp.", "SCSI PCMCIA Card", 0xe3736c88, 0x859cad20), PCMCIA_DEVICE_PROD_ID1("SCSI PCMCIA Adapter Card", 0x8dacb57e), @@ -295,8 +264,7 @@ static struct pcmcia_driver fdomain_cs_driver = { .drv = { .name = "fdomain_cs", }, - .attach = fdomain_attach, - .event = fdomain_event, + .probe = fdomain_attach, .remove = fdomain_detach, .id_table = fdomain_ids, .suspend = fdomain_suspend, diff --git a/drivers/scsi/pcmcia/nsp_cs.c b/drivers/scsi/pcmcia/nsp_cs.c index e48e9fb3c58c..9e3ab3fd5355 100644 --- a/drivers/scsi/pcmcia/nsp_cs.c +++ b/drivers/scsi/pcmcia/nsp_cs.c @@ -104,8 +104,6 @@ static struct scsi_host_template nsp_driver_template = { #endif }; -static dev_info_t dev_info = {"nsp_cs"}; - static nsp_hw_data nsp_data_base; /* attach <-> detect glue */ @@ -1595,19 +1593,17 @@ static int nsp_eh_host_reset(Scsi_Cmnd *SCpnt) configure the card at this point -- we wait until we receive a card insertion event. ======================================================================*/ -static dev_link_t *nsp_cs_attach(void) +static int nsp_cs_attach(struct pcmcia_device *p_dev) { scsi_info_t *info; - client_reg_t client_reg; dev_link_t *link; - int ret; nsp_hw_data *data = &nsp_data_base; nsp_dbg(NSP_DEBUG_INIT, "in"); /* Create new SCSI device */ info = kmalloc(sizeof(*info), GFP_KERNEL); - if (info == NULL) { return NULL; } + if (info == NULL) { return -ENOMEM; } memset(info, 0, sizeof(*info)); link = &info->link; link->priv = info; @@ -1635,22 +1631,14 @@ static dev_link_t *nsp_cs_attach(void) link->conf.IntType = INT_MEMORY_AND_IO; link->conf.Present = PRESENT_OPTION; + link->handle = p_dev; + p_dev->instance = link; - /* Register with Card Services */ - link->next = NULL; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != CS_SUCCESS) { - cs_error(link->handle, RegisterClient, ret); - nsp_cs_detach(link->handle); - return NULL; - } - + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + nsp_cs_config(link); nsp_dbg(NSP_DEBUG_INIT, "link=0x%p", link); - return link; + return 0; } /* nsp_cs_attach */ @@ -2056,44 +2044,6 @@ static int nsp_cs_resume(struct pcmcia_device *dev) return 0; } -/*====================================================================== - - 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 nsp_cs_event(event_t event, - int priority, - event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - nsp_dbg(NSP_DEBUG_INIT, "in, event=0x%08x", event); - - switch (event) { - case CS_EVENT_CARD_INSERTION: - nsp_dbg(NSP_DEBUG_INIT, "event: insert"); - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,68)) - info->bus = args->bus; -#endif - nsp_cs_config(link); - break; - default: - nsp_dbg(NSP_DEBUG_INIT, "event: unknown"); - break; - } - nsp_dbg(NSP_DEBUG_INIT, "end"); - return 0; -} /* nsp_cs_event */ - /*======================================================================* * module entry point *====================================================================*/ @@ -2115,8 +2065,7 @@ static struct pcmcia_driver nsp_driver = { .drv = { .name = "nsp_cs", }, - .attach = nsp_cs_attach, - .event = nsp_cs_event, + .probe = nsp_cs_attach, .remove = nsp_cs_detach, .id_table = nsp_cs_ids, .suspend = nsp_cs_suspend, diff --git a/drivers/scsi/pcmcia/nsp_cs.h b/drivers/scsi/pcmcia/nsp_cs.h index d276c469edf1..b66b140a745e 100644 --- a/drivers/scsi/pcmcia/nsp_cs.h +++ b/drivers/scsi/pcmcia/nsp_cs.h @@ -296,11 +296,9 @@ typedef struct _nsp_hw_data { */ /* Card service functions */ -static dev_link_t *nsp_cs_attach (void); static void nsp_cs_detach (struct pcmcia_device *p_dev); static void nsp_cs_release(dev_link_t *link); static void nsp_cs_config (dev_link_t *link); -static int nsp_cs_event (event_t event, int priority, event_callback_args_t *args); /* Linux SCSI subsystem specific functions */ static struct Scsi_Host *nsp_detect (struct scsi_host_template *sht); diff --git a/drivers/scsi/pcmcia/qlogic_stub.c b/drivers/scsi/pcmcia/qlogic_stub.c index e10281a6e5f9..dce7e687fd4a 100644 --- a/drivers/scsi/pcmcia/qlogic_stub.c +++ b/drivers/scsi/pcmcia/qlogic_stub.c @@ -98,13 +98,8 @@ typedef struct scsi_info_t { } scsi_info_t; static void qlogic_release(dev_link_t *link); -static int qlogic_event(event_t event, int priority, event_callback_args_t * args); - -static dev_link_t *qlogic_attach(void); static void qlogic_detach(struct pcmcia_device *p_dev); - - -static dev_info_t dev_info = "qlogic_cs"; +static void qlogic_config(dev_link_t * link); static struct Scsi_Host *qlogic_detect(struct scsi_host_template *host, dev_link_t *link, int qbase, int qlirq) @@ -161,19 +156,17 @@ free_scsi_host: err: return NULL; } -static dev_link_t *qlogic_attach(void) +static int qlogic_attach(struct pcmcia_device *p_dev) { scsi_info_t *info; - client_reg_t client_reg; dev_link_t *link; - int ret; DEBUG(0, "qlogic_attach()\n"); /* Create new SCSI device */ info = kmalloc(sizeof(*info), GFP_KERNEL); if (!info) - return NULL; + return -ENOMEM; memset(info, 0, sizeof(*info)); link = &info->link; link->priv = info; @@ -187,19 +180,13 @@ static dev_link_t *qlogic_attach(void) link->conf.IntType = INT_MEMORY_AND_IO; link->conf.Present = PRESENT_OPTION; - /* Register with Card Services */ - link->next = NULL; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != 0) { - cs_error(link->handle, RegisterClient, ret); - qlogic_detach(link->handle); - return NULL; - } + link->handle = p_dev; + p_dev->instance = link; - return link; + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + qlogic_config(link); + + return 0; } /* qlogic_attach */ /*====================================================================*/ @@ -368,21 +355,6 @@ static int qlogic_resume(struct pcmcia_device *dev) return 0; } -static int qlogic_event(event_t event, int priority, event_callback_args_t * args) -{ - dev_link_t *link = args->client_data; - - DEBUG(1, "qlogic_event(0x%06x)\n", event); - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - qlogic_config(link); - break; - } - return 0; -} /* qlogic_event */ - static struct pcmcia_device_id qlogic_ids[] = { PCMCIA_DEVICE_PROD_ID12("EIger Labs", "PCMCIA-to-SCSI Adapter", 0x88395fa7, 0x33b7a5e6), PCMCIA_DEVICE_PROD_ID12("EPSON", "SCSI-2 PC Card SC200", 0xd361772f, 0x299d1751), @@ -410,8 +382,7 @@ static struct pcmcia_driver qlogic_cs_driver = { .drv = { .name = "qlogic_cs", }, - .attach = qlogic_attach, - .event = qlogic_event, + .probe = qlogic_attach, .remove = qlogic_detach, .id_table = qlogic_ids, .suspend = qlogic_suspend, diff --git a/drivers/scsi/pcmcia/sym53c500_cs.c b/drivers/scsi/pcmcia/sym53c500_cs.c index 87d50b33475e..3a4dd6f5b81f 100644 --- a/drivers/scsi/pcmcia/sym53c500_cs.c +++ b/drivers/scsi/pcmcia/sym53c500_cs.c @@ -228,14 +228,6 @@ enum Phase { /* ================================================================== */ -/* -* Global (within this module) variables other than -* sym53c500_driver_template (the scsi_host_template). -*/ -static dev_info_t dev_info = "sym53c500_cs"; - -/* ================================================================== */ - static void chip_init(int io_port) { @@ -909,22 +901,6 @@ static int sym53c500_resume(struct pcmcia_device *dev) return 0; } -static int -SYM53C500_event(event_t event, int priority, event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - DEBUG(1, "SYM53C500_event(0x%06x)\n", event); - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - SYM53C500_config(link); - break; - } - return 0; -} /* SYM53C500_event */ - static void SYM53C500_detach(struct pcmcia_device *p_dev) { @@ -939,20 +915,18 @@ SYM53C500_detach(struct pcmcia_device *p_dev) link->priv = NULL; } /* SYM53C500_detach */ -static dev_link_t * -SYM53C500_attach(void) +static int +SYM53C500_attach(struct pcmcia_device *p_dev) { struct scsi_info_t *info; - client_reg_t client_reg; dev_link_t *link; - int ret; DEBUG(0, "SYM53C500_attach()\n"); /* Create new SCSI device */ info = kmalloc(sizeof(*info), GFP_KERNEL); if (!info) - return NULL; + return -ENOMEM; memset(info, 0, sizeof(*info)); link = &info->link; link->priv = info; @@ -966,19 +940,13 @@ SYM53C500_attach(void) link->conf.IntType = INT_MEMORY_AND_IO; link->conf.Present = PRESENT_OPTION; - /* Register with Card Services */ - link->next = NULL; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != 0) { - cs_error(link->handle, RegisterClient, ret); - SYM53C500_detach(link->handle); - return NULL; - } + link->handle = p_dev; + p_dev->instance = link; - return link; + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + SYM53C500_config(link); + + return 0; } /* SYM53C500_attach */ MODULE_AUTHOR("Bob Tracy "); @@ -998,8 +966,7 @@ static struct pcmcia_driver sym53c500_cs_driver = { .drv = { .name = "sym53c500_cs", }, - .attach = SYM53C500_attach, - .event = SYM53C500_event, + .probe = SYM53C500_attach, .remove = SYM53C500_detach, .id_table = sym53c500_ids, .suspend = sym53c500_suspend, diff --git a/drivers/serial/serial_cs.c b/drivers/serial/serial_cs.c index 6e7a1a0ae015..96969cb960a9 100644 --- a/drivers/serial/serial_cs.c +++ b/drivers/serial/serial_cs.c @@ -114,13 +114,7 @@ struct serial_cfg_mem { static void serial_config(dev_link_t * link); -static int serial_event(event_t event, int priority, - event_callback_args_t * args); -static dev_info_t dev_info = "serial_cs"; - -static dev_link_t *serial_attach(void); -static void serial_detach(struct pcmcia_device *p_dev); /*====================================================================== @@ -203,19 +197,17 @@ static int serial_resume(struct pcmcia_device *dev) ======================================================================*/ -static dev_link_t *serial_attach(void) +static int serial_probe(struct pcmcia_device *p_dev) { struct serial_info *info; - client_reg_t client_reg; dev_link_t *link; - int ret; DEBUG(0, "serial_attach()\n"); /* Create new serial device */ info = kmalloc(sizeof (*info), GFP_KERNEL); if (!info) - return NULL; + return -ENOMEM; memset(info, 0, sizeof (*info)); link = &info->link; link->priv = info; @@ -231,19 +223,12 @@ static dev_link_t *serial_attach(void) } link->conf.IntType = INT_MEMORY_AND_IO; - /* Register with Card Services */ - link->next = NULL; /* not needed */ - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != CS_SUCCESS) { - cs_error(link->handle, RegisterClient, ret); - serial_detach(link->handle); - return NULL; - } + link->handle = p_dev; + p_dev->instance = link; + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + serial_config(link); - return link; + return 0; } /*====================================================================== @@ -706,32 +691,6 @@ void serial_config(dev_link_t * link) kfree(cfg_mem); } -/*====================================================================== - - 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 serial drivers from - talking to the ports. - -======================================================================*/ - -static int -serial_event(event_t event, int priority, event_callback_args_t * args) -{ - dev_link_t *link = args->client_data; - - DEBUG(1, "serial_event(0x%06x)\n", event); - - switch (event) { - - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - serial_config(link); - break; - } - return 0; -} - static struct pcmcia_device_id serial_ids[] = { PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0057, 0x0021), PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0089, 0x110a), @@ -843,8 +802,7 @@ static struct pcmcia_driver serial_cs_driver = { .drv = { .name = "serial_cs", }, - .attach = serial_attach, - .event = serial_event, + .probe = serial_probe, .remove = serial_detach, .id_table = serial_ids, .suspend = serial_suspend, diff --git a/drivers/telephony/ixj_pcmcia.c b/drivers/telephony/ixj_pcmcia.c index 6b992985d782..d3a7b0c3d38b 100644 --- a/drivers/telephony/ixj_pcmcia.c +++ b/drivers/telephony/ixj_pcmcia.c @@ -34,23 +34,19 @@ typedef struct ixj_info_t { struct ixj *port; } ixj_info_t; -static dev_link_t *ixj_attach(void); static void ixj_detach(struct pcmcia_device *p_dev); static void ixj_config(dev_link_t * link); static void ixj_cs_release(dev_link_t * link); -static int ixj_event(event_t event, int priority, event_callback_args_t * args); -static dev_info_t dev_info = "ixj_cs"; -static dev_link_t *ixj_attach(void) +static int ixj_attach(struct pcmcia_device *p_dev) { - client_reg_t client_reg; dev_link_t *link; - int ret; + DEBUG(0, "ixj_attach()\n"); /* Create new ixj device */ link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL); if (!link) - return NULL; + return -ENOMEM; memset(link, 0, sizeof(struct dev_link_t)); link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; link->io.Attributes2 = IO_DATA_PATH_WIDTH_8; @@ -60,21 +56,17 @@ static dev_link_t *ixj_attach(void) link->priv = kmalloc(sizeof(struct ixj_info_t), GFP_KERNEL); if (!link->priv) { kfree(link); - return NULL; + return -ENOMEM; } memset(link->priv, 0, sizeof(struct ixj_info_t)); - /* Register with Card Services */ - link->next = NULL; - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != CS_SUCCESS) { - cs_error(link->handle, RegisterClient, ret); - ixj_detach(link->handle); - return NULL; - } - return link; + + link->handle = p_dev; + p_dev->instance = link; + + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + ixj_config(link); + + return 0; } static void ixj_detach(struct pcmcia_device *p_dev) @@ -265,19 +257,6 @@ static int ixj_resume(struct pcmcia_device *dev) return 0; } -static int ixj_event(event_t event, int priority, event_callback_args_t * args) -{ - dev_link_t *link = args->client_data; - DEBUG(1, "ixj_event(0x%06x)\n", event); - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - ixj_config(link); - break; - } - return 0; -} - static struct pcmcia_device_id ixj_ids[] = { PCMCIA_DEVICE_MANF_CARD(0x0257, 0x0600), PCMCIA_DEVICE_NULL @@ -289,8 +268,7 @@ static struct pcmcia_driver ixj_driver = { .drv = { .name = "ixj_cs", }, - .attach = ixj_attach, - .event = ixj_event, + .probe = ixj_attach, .remove = ixj_detach, .id_table = ixj_ids, .suspend = ixj_suspend, diff --git a/drivers/usb/host/sl811_cs.c b/drivers/usb/host/sl811_cs.c index 439709670d0b..466384d7c79f 100644 --- a/drivers/usb/host/sl811_cs.c +++ b/drivers/usb/host/sl811_cs.c @@ -325,32 +325,14 @@ static int sl811_resume(struct pcmcia_device *dev) return 0; } -static int -sl811_cs_event(event_t event, int priority, event_callback_args_t *args) -{ - dev_link_t *link = args->client_data; - - DBG(1, "sl811_cs_event(0x%06x)\n", event); - - switch (event) { - case CS_EVENT_CARD_INSERTION: - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - sl811_cs_config(link); - break; - } - return 0; -} - -static dev_link_t *sl811_cs_attach(void) +static int sl811_cs_attach(struct pcmcia_device *p_dev) { local_info_t *local; dev_link_t *link; - client_reg_t client_reg; - int ret; local = kmalloc(sizeof(local_info_t), GFP_KERNEL); if (!local) - return NULL; + return -ENOMEM; memset(local, 0, sizeof(local_info_t)); link = &local->link; link->priv = local; @@ -364,20 +346,13 @@ static dev_link_t *sl811_cs_attach(void) link->conf.Vcc = 33; link->conf.IntType = INT_MEMORY_AND_IO; - /* Register with Card Services */ - link->next = NULL; - client_reg.dev_info = (dev_info_t *) &driver_name; - client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != CS_SUCCESS) { - cs_error(link->handle, RegisterClient, ret); - sl811_cs_detach(link->handle); - return NULL; - } + link->handle = p_dev; + p_dev->instance = link; - return link; + link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; + sl811_cs_config(link); + + return 0; } static struct pcmcia_device_id sl811_ids[] = { @@ -391,8 +366,7 @@ static struct pcmcia_driver sl811_cs_driver = { .drv = { .name = (char *)driver_name, }, - .attach = sl811_cs_attach, - .event = sl811_cs_event, + .probe = sl811_cs_attach, .remove = sl811_cs_detach, .id_table = sl811_ids, .suspend = sl811_suspend, diff --git a/include/pcmcia/cs.h b/include/pcmcia/cs.h index a751251efdc8..52660f32663d 100644 --- a/include/pcmcia/cs.h +++ b/include/pcmcia/cs.h @@ -389,7 +389,6 @@ int pcmcia_get_status(struct pcmcia_device *p_dev, cs_status_t *status); int pcmcia_get_mem_page(window_handle_t win, memreq_t *req); int pcmcia_map_mem_page(window_handle_t win, memreq_t *req); int pcmcia_modify_configuration(struct pcmcia_device *p_dev, modconf_t *mod); -int pcmcia_register_client(client_handle_t *handle, client_reg_t *req); int pcmcia_release_configuration(struct pcmcia_device *p_dev); int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req); int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req); diff --git a/include/pcmcia/ds.h b/include/pcmcia/ds.h index c53a0604e441..8e2a96396478 100644 --- a/include/pcmcia/ds.h +++ b/include/pcmcia/ds.h @@ -133,10 +133,7 @@ typedef struct dev_link_t { struct pcmcia_socket; struct pcmcia_driver { - dev_link_t *(*attach)(void); - int (*event) (event_t event, int priority, - event_callback_args_t *); - + int (*probe) (struct pcmcia_device *dev); void (*remove) (struct pcmcia_device *dev); int (*suspend) (struct pcmcia_device *dev); @@ -169,7 +166,6 @@ struct pcmcia_device { /* deprecated, a cleaned up version will be moved into this struct soon */ dev_link_t *instance; - event_callback_args_t event_callback_args; u_int state; /* information about this device */ From efe3cd105f2a19e72ce9280bb22c7c80752e4314 Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Fri, 6 Jan 2006 00:27:16 +0100 Subject: [PATCH 37/48] [PATCH] pcmcia: fix sound drivers Update the PCMCIA sound drivers to handle the recent changes to the PCMCIA core. A part of this merge was done by Takashi Iwai . Signed-off-by: Dominik Brodowski --- sound/pcmcia/pdaudiocf/pdaudiocf.c | 156 +++++++++++----------------- sound/pcmcia/vx/vxpocket.c | 159 +++++++++++------------------ 2 files changed, 118 insertions(+), 197 deletions(-) diff --git a/sound/pcmcia/pdaudiocf/pdaudiocf.c b/sound/pcmcia/pdaudiocf/pdaudiocf.c index a7cd2d4df757..77caf43a3109 100644 --- a/sound/pcmcia/pdaudiocf/pdaudiocf.c +++ b/sound/pcmcia/pdaudiocf/pdaudiocf.c @@ -52,16 +52,13 @@ MODULE_PARM_DESC(enable, "Enable " CARD_NAME " soundcard."); /* */ -static dev_info_t dev_info = "snd-pdaudiocf"; static struct snd_card *card_list[SNDRV_CARDS]; -static dev_link_t *dev_list; /* * prototypes */ static void pdacf_config(dev_link_t *link); -static int pdacf_event(event_t event, int priority, event_callback_args_t *args); -static void snd_pdacf_detach(dev_link_t *link); +static void snd_pdacf_detach(struct pcmcia_device *p_dev); static void pdacf_release(dev_link_t *link) { @@ -83,10 +80,6 @@ static int snd_pdacf_free(struct snd_pdacf *pdacf) pdacf_release(link); - /* Break the link with Card Services */ - if (link->handle) - pcmcia_deregister_client(link->handle); - card_list[pdacf->index] = NULL; pdacf->card = NULL; @@ -103,11 +96,10 @@ static int snd_pdacf_dev_free(struct snd_device *device) /* * snd_pdacf_attach - attach callback for cs */ -static dev_link_t *snd_pdacf_attach(void) +static int snd_pdacf_attach(struct pcmcia_device *p_dev) { - client_reg_t client_reg; /* Register with cardmgr */ - dev_link_t *link; /* Info for cardmgr */ - int i, ret; + int i; + dev_link_t *link; /* Info for cardmgr */ struct snd_pdacf *pdacf; struct snd_card *card; static struct snd_device_ops ops = { @@ -122,26 +114,26 @@ static dev_link_t *snd_pdacf_attach(void) } if (i >= SNDRV_CARDS) { snd_printk(KERN_ERR "pdacf: too many cards found\n"); - return NULL; + return -EINVAL; } if (! enable[i]) - return NULL; /* disabled explicitly */ + return -ENODEV; /* disabled explicitly */ /* ok, create a card instance */ card = snd_card_new(index[i], id[i], THIS_MODULE, 0); if (card == NULL) { snd_printk(KERN_ERR "pdacf: cannot create a card instance\n"); - return NULL; + return -ENOMEM; } pdacf = snd_pdacf_create(card); if (! pdacf) - return NULL; + return -EIO; if (snd_device_new(card, SNDRV_DEV_LOWLEVEL, pdacf, &ops) < 0) { kfree(pdacf); snd_card_free(card); - return NULL; + return -ENODEV; } pdacf->index = i; @@ -165,22 +157,12 @@ static dev_link_t *snd_pdacf_attach(void) link->conf.Present = PRESENT_OPTION; /* Chain drivers */ - link->next = dev_list; - dev_list = link; + link->next = NULL; - /* Register with Card Services */ - client_reg.dev_info = &dev_info; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; + link->handle = p_dev; + pdacf_config(link); - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != CS_SUCCESS) { - cs_error(link->handle, RegisterClient, ret); - snd_pdacf_detach(link); - return NULL; - } - - return link; + return 0; } @@ -227,21 +209,13 @@ static int snd_pdacf_assign_resources(struct snd_pdacf *pdacf, int port, int irq /* * snd_pdacf_detach - detach callback for cs */ -static void snd_pdacf_detach(dev_link_t *link) +static void snd_pdacf_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); struct snd_pdacf *chip = link->priv; snd_printdd(KERN_DEBUG "pdacf_detach called\n"); - /* Remove the interface data from the linked list */ - { - dev_link_t **linkp; - /* Locate device structure */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) - break; - if (*linkp) - *linkp = link->next; - } + if (chip->chip_status & PDAUDIOCF_STAT_IS_CONFIGURED) snd_pdacf_powerdown(chip); chip->chip_status |= PDAUDIOCF_STAT_IS_STALE; /* to be sure */ @@ -310,62 +284,51 @@ failed: pcmcia_release_irq(link->handle, &link->irq); } -/* - * event callback - */ -static int pdacf_event(event_t event, int priority, event_callback_args_t *args) +#ifdef CONFIG_PM + +static int pdacf_suspend(struct pcmcia_device *dev) { - dev_link_t *link = args->client_data; + dev_link_t *link = dev_to_instance(dev); struct snd_pdacf *chip = link->priv; - switch (event) { - case CS_EVENT_CARD_REMOVAL: - snd_printdd(KERN_DEBUG "CARD_REMOVAL..\n"); - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) { - chip->chip_status |= PDAUDIOCF_STAT_IS_STALE; - } - break; - case CS_EVENT_CARD_INSERTION: - snd_printdd(KERN_DEBUG "CARD_INSERTION..\n"); - link->state |= DEV_PRESENT; - pdacf_config(link); - break; -#ifdef CONFIG_PM - case CS_EVENT_PM_SUSPEND: - snd_printdd(KERN_DEBUG "SUSPEND\n"); - link->state |= DEV_SUSPEND; - if (chip) { - snd_printdd(KERN_DEBUG "snd_pdacf_suspend calling\n"); - snd_pdacf_suspend(chip, PMSG_SUSPEND); - } - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - snd_printdd(KERN_DEBUG "RESET_PHYSICAL\n"); - if (link->state & DEV_CONFIG) - pcmcia_release_configuration(link->handle); - break; - case CS_EVENT_PM_RESUME: - snd_printdd(KERN_DEBUG "RESUME\n"); - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - snd_printdd(KERN_DEBUG "CARD_RESET\n"); - if (DEV_OK(link)) { - snd_printdd(KERN_DEBUG "requestconfig...\n"); - pcmcia_request_configuration(link->handle, &link->conf); - if (chip) { - snd_printdd(KERN_DEBUG "calling snd_pdacf_resume\n"); - snd_pdacf_resume(chip); - } - } - snd_printdd(KERN_DEBUG "resume done!\n"); - break; -#endif + snd_printdd(KERN_DEBUG "SUSPEND\n"); + link->state |= DEV_SUSPEND; + if (chip) { + snd_printdd(KERN_DEBUG "snd_pdacf_suspend calling\n"); + snd_pdacf_suspend(chip, PMSG_SUSPEND); } + + snd_printdd(KERN_DEBUG "RESET_PHYSICAL\n"); + if (link->state & DEV_CONFIG) + pcmcia_release_configuration(link->handle); + return 0; } +static int pdacf_resume(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + struct snd_pdacf *chip = link->priv; + + snd_printdd(KERN_DEBUG "RESUME\n"); + link->state &= ~DEV_SUSPEND; + + snd_printdd(KERN_DEBUG "CARD_RESET\n"); + if (DEV_OK(link)) { + snd_printdd(KERN_DEBUG "requestconfig...\n"); + pcmcia_request_configuration(link->handle, &link->conf); + if (chip) { + snd_printdd(KERN_DEBUG "calling snd_pdacf_resume\n"); + snd_pdacf_resume(chip); + } + } + snd_printdd(KERN_DEBUG "resume done!\n"); + + return 0; +} + +#endif + /* * Module entry points */ @@ -380,10 +343,14 @@ static struct pcmcia_driver pdacf_cs_driver = { .drv = { .name = "snd-pdaudiocf", }, - .attach = snd_pdacf_attach, - .event = pdacf_event, - .detach = snd_pdacf_detach, + .probe = snd_pdacf_attach, + .remove = snd_pdacf_detach, .id_table = snd_pdacf_ids, +#ifdef CONFIG_PM + .suspend = pdacf_suspend, + .resume = pdacf_resume, +#endif + }; static int __init init_pdacf(void) @@ -394,7 +361,6 @@ static int __init init_pdacf(void) static void __exit exit_pdacf(void) { pcmcia_unregister_driver(&pdacf_cs_driver); - BUG_ON(dev_list != NULL); } module_init(init_pdacf); diff --git a/sound/pcmcia/vx/vxpocket.c b/sound/pcmcia/vx/vxpocket.c index 5bb079d17959..66900d20a42f 100644 --- a/sound/pcmcia/vx/vxpocket.c +++ b/sound/pcmcia/vx/vxpocket.c @@ -55,11 +55,6 @@ MODULE_PARM_DESC(ibl, "Capture IBL size for VXPocket soundcard."); */ static unsigned int card_alloc; -static dev_link_t *dev_list; /* Linked list of devices */ -static dev_info_t dev_info = "snd-vxpocket"; - - -static int vxpocket_event(event_t event, int priority, event_callback_args_t *args); /* @@ -73,11 +68,6 @@ static void vxpocket_release(dev_link_t *link) pcmcia_release_irq(link->handle, &link->irq); link->state &= ~DEV_CONFIG; } - if (link->handle) { - /* Break the link with Card Services */ - pcmcia_deregister_client(link->handle); - link->handle = NULL; - } } /* @@ -144,11 +134,9 @@ static struct snd_vx_hardware vxp440_hw = { */ static struct snd_vxpocket *snd_vxpocket_new(struct snd_card *card, int ibl) { - client_reg_t client_reg; /* Register with cardmgr */ dev_link_t *link; /* Info for cardmgr */ struct vx_core *chip; struct snd_vxpocket *vxp; - int ret; static struct snd_device_ops ops = { .dev_free = snd_vxpocket_dev_free, }; @@ -184,26 +172,6 @@ static struct snd_vxpocket *snd_vxpocket_new(struct snd_card *card, int ibl) link->conf.ConfigIndex = 1; link->conf.Present = PRESENT_OPTION; - /* Register with Card Services */ - memset(&client_reg, 0, sizeof(client_reg)); - client_reg.dev_info = &dev_info; - client_reg.EventMask = - CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL -#ifdef CONFIG_PM - | CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET - | CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME -#endif - ; - client_reg.event_handler = &vxpocket_event; - client_reg.Version = 0x0210; - client_reg.event_callback_args.client_data = link; - - ret = pcmcia_register_client(&link->handle, &client_reg); - if (ret != CS_SUCCESS) { - cs_error(link->handle, RegisterClient, ret); - return NULL; - } - return vxp; } @@ -317,67 +285,55 @@ failed: kfree(parse); } +#ifdef CONFIG_PM -/* - * event callback - */ -static int vxpocket_event(event_t event, int priority, event_callback_args_t *args) +static int vxp_suspend(struct pcmcia_device *dev) { - dev_link_t *link = args->client_data; + dev_link_t *link = dev_to_instance(dev); struct vx_core *chip = link->priv; - switch (event) { - case CS_EVENT_CARD_REMOVAL: - snd_printdd(KERN_DEBUG "CARD_REMOVAL..\n"); - link->state &= ~DEV_PRESENT; - if (link->state & DEV_CONFIG) - chip->chip_status |= VX_STAT_IS_STALE; - break; - case CS_EVENT_CARD_INSERTION: - snd_printdd(KERN_DEBUG "CARD_INSERTION..\n"); - link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; - vxpocket_config(link); - break; -#ifdef CONFIG_PM - case CS_EVENT_PM_SUSPEND: - snd_printdd(KERN_DEBUG "SUSPEND\n"); - link->state |= DEV_SUSPEND; - if (chip) { - snd_printdd(KERN_DEBUG "snd_vx_suspend calling\n"); - snd_vx_suspend(chip, PMSG_SUSPEND); - } - /* Fall through... */ - case CS_EVENT_RESET_PHYSICAL: - snd_printdd(KERN_DEBUG "RESET_PHYSICAL\n"); - if (link->state & DEV_CONFIG) - pcmcia_release_configuration(link->handle); - break; - case CS_EVENT_PM_RESUME: - snd_printdd(KERN_DEBUG "RESUME\n"); - link->state &= ~DEV_SUSPEND; - /* Fall through... */ - case CS_EVENT_CARD_RESET: - snd_printdd(KERN_DEBUG "CARD_RESET\n"); - if (DEV_OK(link)) { - //struct snd_vxpocket *vxp = (struct snd_vxpocket *)chip; - snd_printdd(KERN_DEBUG "requestconfig...\n"); - pcmcia_request_configuration(link->handle, &link->conf); - if (chip) { - snd_printdd(KERN_DEBUG "calling snd_vx_resume\n"); - snd_vx_resume(chip); - } - } - snd_printdd(KERN_DEBUG "resume done!\n"); - break; -#endif + snd_printdd(KERN_DEBUG "SUSPEND\n"); + link->state |= DEV_SUSPEND; + if (chip) { + snd_printdd(KERN_DEBUG "snd_vx_suspend calling\n"); + snd_vx_suspend(chip, PMSG_SUSPEND); } + snd_printdd(KERN_DEBUG "RESET_PHYSICAL\n"); + if (link->state & DEV_CONFIG) + pcmcia_release_configuration(link->handle); + return 0; } +static int vxp_resume(struct pcmcia_device *dev) +{ + dev_link_t *link = dev_to_instance(dev); + struct vx_core *chip = link->priv; + + snd_printdd(KERN_DEBUG "RESUME\n"); + link->state &= ~DEV_SUSPEND; + + snd_printdd(KERN_DEBUG "CARD_RESET\n"); + if (DEV_OK(link)) { + //struct snd_vxpocket *vxp = (struct snd_vxpocket *)chip; + snd_printdd(KERN_DEBUG "requestconfig...\n"); + pcmcia_request_configuration(link->handle, &link->conf); + if (chip) { + snd_printdd(KERN_DEBUG "calling snd_vx_resume\n"); + snd_vx_resume(chip); + } + } + snd_printdd(KERN_DEBUG "resume done!\n"); + + return 0; +} + +#endif + /* */ -static dev_link_t *vxpocket_attach(void) +static int vxpocket_attach(struct pcmcia_device *p_dev) { struct snd_card *card; struct snd_vxpocket *vxp; @@ -390,22 +346,22 @@ static dev_link_t *vxpocket_attach(void) } if (i >= SNDRV_CARDS) { snd_printk(KERN_ERR "vxpocket: too many cards found\n"); - return NULL; + return -EINVAL; } if (! enable[i]) - return NULL; /* disabled explicitly */ + return -ENODEV; /* disabled explicitly */ /* ok, create a card instance */ card = snd_card_new(index[i], id[i], THIS_MODULE, 0); if (card == NULL) { snd_printk(KERN_ERR "vxpocket: cannot create a card instance\n"); - return NULL; + return -ENOMEM; } vxp = snd_vxpocket_new(card, ibl[i]); if (! vxp) { snd_card_free(card); - return NULL; + return -ENODEV; } card->private_data = vxp; @@ -413,17 +369,21 @@ static dev_link_t *vxpocket_attach(void) card_alloc |= 1 << i; /* Chain drivers */ - vxp->link.next = dev_list; - dev_list = &vxp->link; + vxp->link.next = NULL; - return &vxp->link; + vxp->link.handle = p_dev; + vxp->link.state |= DEV_PRESENT | DEV_CONFIG_PENDING; + p_dev->instance = &vxp->link; + vxpocket_config(&vxp->link); + + return 0; } -static void vxpocket_detach(dev_link_t *link) +static void vxpocket_detach(struct pcmcia_device *p_dev) { + dev_link_t *link = dev_to_instance(p_dev); struct snd_vxpocket *vxp; struct vx_core *chip; - dev_link_t **linkp; if (! link) return; @@ -432,13 +392,6 @@ static void vxpocket_detach(dev_link_t *link) chip = (struct vx_core *)vxp; card_alloc &= ~(1 << vxp->index); - /* Remove the interface data from the linked list */ - for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) - if (*linkp == link) { - *linkp = link->next; - break; - } - chip->chip_status |= VX_STAT_IS_STALE; /* to be sure */ snd_card_disconnect(chip->card); vxpocket_release(link); @@ -460,10 +413,13 @@ static struct pcmcia_driver vxp_cs_driver = { .drv = { .name = "snd-vxpocket", }, - .attach = vxpocket_attach, - .detach = vxpocket_detach, - .event = vxpocket_event, + .probe = vxpocket_attach, + .remove = vxpocket_detach, .id_table = vxp_ids, +#ifdef CONFIG_PM + .suspend = vxp_suspend, + .resume = vxp_resume, +#endif }; static int __init init_vxpocket(void) @@ -474,7 +430,6 @@ static int __init init_vxpocket(void) static void __exit exit_vxpocket(void) { pcmcia_unregister_driver(&vxp_cs_driver); - BUG_ON(dev_list != NULL); } module_init(init_vxpocket); From 3b27e9421a1433689704fe0a02e926d4ba971121 Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Wed, 7 Dec 2005 12:32:20 +0100 Subject: [PATCH 38/48] [PATCH] pcmcia: properly handle static mem, but dynamic io sockets Some PCMCIA sockets have statically mapped memory windows, but dynamically mapped IO windows. Using the "nonstatic" socket library is inpractical for them, as they do neither need a resource database (as we can trust the kernel resource database on m68k and ppc) nor lots of other features of that library. Let them get a small "iodyn" socket library (105 lines of code) instead. Signed-off-by: Dominik Brodowski --- drivers/pcmcia/Kconfig | 5 +- drivers/pcmcia/m8xx_pcmcia.c | 2 +- drivers/pcmcia/rsrc_mgr.c | 102 +++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+), 2 deletions(-) diff --git a/drivers/pcmcia/Kconfig b/drivers/pcmcia/Kconfig index ea00b1f3cb44..df93df64c9f3 100644 --- a/drivers/pcmcia/Kconfig +++ b/drivers/pcmcia/Kconfig @@ -182,7 +182,7 @@ config TCIC config PCMCIA_M8XX tristate "MPC8xx PCMCIA support" depends on PCMCIA && PPC && 8xx - select PCCARD_NONSTATIC + select PCCARD_IODYN help Say Y here to include support for PowerPC 8xx series PCMCIA controller. @@ -266,6 +266,9 @@ config OMAP_CF config PCCARD_NONSTATIC tristate +config PCCARD_IODYN + bool + endif # PCCARD endmenu diff --git a/drivers/pcmcia/m8xx_pcmcia.c b/drivers/pcmcia/m8xx_pcmcia.c index a7f27c3dfc24..570e4e868b24 100644 --- a/drivers/pcmcia/m8xx_pcmcia.c +++ b/drivers/pcmcia/m8xx_pcmcia.c @@ -1232,7 +1232,7 @@ static int __init m8xx_init(void) socket[i].socket.io_offset = 0; socket[i].socket.pci_irq = i ? 7 : 9; socket[i].socket.ops = &m8xx_services; - socket[i].socket.resource_ops = &pccard_nonstatic_ops; + socket[i].socket.resource_ops = &pccard_iodyn_ops; socket[i].socket.cb_dev = NULL; socket[i].socket.dev.dev = &m8xx_device.dev; } diff --git a/drivers/pcmcia/rsrc_mgr.c b/drivers/pcmcia/rsrc_mgr.c index b02598a5a912..514609369836 100644 --- a/drivers/pcmcia/rsrc_mgr.c +++ b/drivers/pcmcia/rsrc_mgr.c @@ -166,3 +166,105 @@ struct pccard_resource_ops pccard_static_ops = { .exit = NULL, }; EXPORT_SYMBOL(pccard_static_ops); + + +#ifdef CONFIG_PCCARD_IODYN + +static struct resource * +make_resource(unsigned long b, unsigned long n, int flags, char *name) +{ + struct resource *res = kzalloc(sizeof(*res), GFP_KERNEL); + + if (res) { + res->name = name; + res->start = b; + res->end = b + n - 1; + res->flags = flags; + } + return res; +} + +struct pcmcia_align_data { + unsigned long mask; + unsigned long offset; +}; + +static void pcmcia_align(void *align_data, struct resource *res, + unsigned long size, unsigned long align) +{ + struct pcmcia_align_data *data = align_data; + unsigned long start; + + start = (res->start & ~data->mask) + data->offset; + if (start < res->start) + start += data->mask + 1; + res->start = start; + +#ifdef CONFIG_X86 + if (res->flags & IORESOURCE_IO) { + if (start & 0x300) { + start = (start + 0x3ff) & ~0x3ff; + res->start = start; + } + } +#endif + +#ifdef CONFIG_M68K + if (res->flags & IORESOURCE_IO) { + if ((res->start + size - 1) >= 1024) + res->start = res->end; + } +#endif +} + + +static int iodyn_adjust_io_region(struct resource *res, unsigned long r_start, + unsigned long r_end, struct pcmcia_socket *s) +{ + return adjust_resource(res, r_start, r_end - r_start + 1); +} + + +static struct resource *iodyn_find_io_region(unsigned long base, int num, + unsigned long align, struct pcmcia_socket *s) +{ + struct resource *res = make_resource(0, num, IORESOURCE_IO, + s->dev.class_id); + struct pcmcia_align_data data; + unsigned long min = base; + int ret; + + if (align == 0) + align = 0x10000; + + data.mask = align - 1; + data.offset = base & data.mask; + +#ifdef CONFIG_PCI + if (s->cb_dev) { + ret = pci_bus_alloc_resource(s->cb_dev->bus, res, num, 1, + min, 0, pcmcia_align, &data); + } else +#endif + ret = allocate_resource(&ioport_resource, res, num, min, ~0UL, + 1, pcmcia_align, &data); + + if (ret != 0) { + kfree(res); + res = NULL; + } + return res; +} + +struct pccard_resource_ops pccard_iodyn_ops = { + .validate_mem = NULL, + .adjust_io_region = iodyn_adjust_io_region, + .find_io = iodyn_find_io_region, + .find_mem = NULL, + .adjust_resource = NULL, + .init = static_init, + .exit = NULL, +}; +EXPORT_SYMBOL(pccard_iodyn_ops); + +#endif /* CONFIG_PCCARD_IODYN */ From a94515fa1f1609249dbebcfb93181ad0ba4b285a Mon Sep 17 00:00:00 2001 From: Vitaly Bordug Date: Thu, 8 Dec 2005 13:53:20 -0200 Subject: [PATCH 39/48] [PATCH] m8xx_pcmcia: support MAP_AUTOSZ required for CF cards This fixes misconfiguration that could result in odd work of some old CF cards. Signed-off-by: Vitaly Bordug Signed-off-by: Marcelo Tosatti Signed-off-by: Dominik Brodowski --- drivers/pcmcia/m8xx_pcmcia.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/pcmcia/m8xx_pcmcia.c b/drivers/pcmcia/m8xx_pcmcia.c index 570e4e868b24..ddaab13d21bd 100644 --- a/drivers/pcmcia/m8xx_pcmcia.c +++ b/drivers/pcmcia/m8xx_pcmcia.c @@ -1012,8 +1012,7 @@ static int m8xx_set_io_map(struct pcmcia_socket *sock, struct pccard_io_map *io) if(io->flags & MAP_WRPROT) reg |= M8XX_PCMCIA_POR_WRPROT; - /*if(io->flags & (MAP_16BIT | MAP_AUTOSZ))*/ - if(io->flags & MAP_16BIT) + if(io->flags & (MAP_16BIT | MAP_AUTOSZ)) reg |= M8XX_PCMCIA_POR_16BIT; if(io->flags & MAP_ACTIVE) From 1371d3be045a6a1a8b828b838069b5fe6e0ab4c6 Mon Sep 17 00:00:00 2001 From: Vitaly Bordug Date: Thu, 8 Dec 2005 13:56:12 -0200 Subject: [PATCH 40/48] [PATCH] 8xx PCMCIA: support for MPC885ADS and MPC866ADS This adds PCMCIA support for both MPC885ADS and MPC866ADS. This is established not together with FADS, because 885 does not have io_block_mapping() for BCSR area. Also, some cleanups done both for 885ADS and MBX. Signed-off-by: Vitaly Bordug Signed-off-by: Marcelo Tosatti Signed-off-by: Dominik Brodowski --- drivers/pcmcia/m8xx_pcmcia.c | 97 +++++++++++++++++++++++++++++++++--- 1 file changed, 91 insertions(+), 6 deletions(-) diff --git a/drivers/pcmcia/m8xx_pcmcia.c b/drivers/pcmcia/m8xx_pcmcia.c index ddaab13d21bd..0e07d9535116 100644 --- a/drivers/pcmcia/m8xx_pcmcia.c +++ b/drivers/pcmcia/m8xx_pcmcia.c @@ -9,6 +9,9 @@ * * Further fixes, v2.6 kernel port * + * + * Some fixes, additions (C) 2005 Montavista Software, Inc. + * * * "The ExCA standard specifies that socket controllers should provide * two IO and five memory windows per socket, which can be independently @@ -97,6 +100,11 @@ MODULE_LICENSE("Dual MPL/GPL"); #endif #endif +#if defined(CONFIG_MPC885ADS) +#define CONFIG_PCMCIA_SLOT_A +#define PCMCIA_GLITCHY_CD +#endif + /* Cyclades ACS uses both slots */ #ifdef CONFIG_PRxK #define CONFIG_PCMCIA_SLOT_A @@ -374,10 +382,10 @@ static int voltage_set(int slot, int vcc, int vpp) } /* first, turn off all power */ - out_be32(&((u32 *)BCSR1), in_be32(&((u32 *)BCSR1)) & ~(BCSR1_PCCVCC_MASK | BCSR1_PCCVPP_MASK)); + out_be32((u32 *)BCSR1, in_be32((u32 *)BCSR1) & ~(BCSR1_PCCVCC_MASK | BCSR1_PCCVPP_MASK)); /* enable new powersettings */ - out_be32(&((u32 *)BCSR1), in_be32(&((u32 *)BCSR1)) | reg); + out_be32((u32 *)BCSR1, in_be32((u32 *)BCSR1) | reg); return 0; } @@ -386,12 +394,89 @@ static int voltage_set(int slot, int vcc, int vpp) static void hardware_enable(int slot) { - out_be32(&((u32 *)BCSR1), in_be32(&((u32 *)BCSR1)) & ~BCSR1_PCCEN); + out_be32((u32 *)BCSR1, in_be32((u32 *)BCSR1) & ~BCSR1_PCCEN); } static void hardware_disable(int slot) { - out_be32(&((u32 *)BCSR1), in_be32(&((u32 *)BCSR1)) | BCSR1_PCCEN); + out_be32((u32 *)BCSR1, in_be32((u32 *)BCSR1) | BCSR1_PCCEN); +} + +#endif + +/* MPC885ADS Boards */ + +#if defined(CONFIG_MPC885ADS) + +#define PCMCIA_BOARD_MSG "MPC885ADS" + +static int voltage_set(int slot, int vcc, int vpp) +{ + u32 reg = 0; + unsigned *bcsr_io; + + bcsr_io = ioremap(BCSR1, sizeof(unsigned long)); + + switch(vcc) { + case 0: + break; + case 33: + reg |= BCSR1_PCCVCC0; + break; + case 50: + reg |= BCSR1_PCCVCC1; + break; + default: + return 1; + } + + switch(vpp) { + case 0: + break; + case 33: + case 50: + if(vcc == vpp) + reg |= BCSR1_PCCVPP1; + else + return 1; + break; + case 120: + if ((vcc == 33) || (vcc == 50)) + reg |= BCSR1_PCCVPP0; + else + return 1; + default: + return 1; + } + + /* first, turn off all power */ + out_be32(bcsr_io, in_be32(bcsr_io) & ~(BCSR1_PCCVCC_MASK | BCSR1_PCCVPP_MASK)); + + /* enable new powersettings */ + out_be32(bcsr_io, in_be32(bcsr_io) | reg); + + iounmap(bcsr_io); + return 0; +} + +#define socket_get(_slot_) PCMCIA_SOCKET_KEY_5V + +static void hardware_enable(int slot) +{ + unsigned *bcsr_io; + + bcsr_io = ioremap(BCSR1, sizeof(unsigned long)); + out_be32(bcsr_io, in_be32(bcsr_io) & ~BCSR1_PCCEN); + iounmap(bcsr_io); +} + +static void hardware_disable(int slot) +{ + unsigned *bcsr_io; + + bcsr_io = ioremap(BCSR1, sizeof(unsigned long)); + out_be32(bcsr_io, in_be32(bcsr_io) | BCSR1_PCCEN); + iounmap(bcsr_io); } #endif @@ -440,10 +525,10 @@ static int voltage_set(int slot, int vcc, int vpp) } /* first, turn off all power */ - out_8(&((u8 *)MBX_CSR2_ADDR), in_8(&((u8 *)MBX_CSR2_ADDR)) & ~(CSR2_VCC_MASK | CSR2_VPP_MASK)); + out_8((u8 *)MBX_CSR2_ADDR, in_8((u8 *)MBX_CSR2_ADDR) & ~(CSR2_VCC_MASK | CSR2_VPP_MASK)); /* enable new powersettings */ - out_8(&((u8 *)MBX_CSR2_ADDR), in_8(&((u8 *)MBX_CSR2_ADDR)) | reg); + out_8((u8 *)MBX_CSR2_ADDR, in_8((u8 *)MBX_CSR2_ADDR) | reg); return 0; } From 002dbb2d0d42b4a2c1eef2012c2fe7af48163b3c Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Thu, 8 Dec 2005 23:50:36 +0100 Subject: [PATCH 41/48] [PATCH] pcmcia: export stored values in sysfs Export the stored values instead of re-reading everything in the socket information sysfs files, and make them accessible to all users, not only to root. Signed-off-by: Dominik Brodowski --- drivers/pcmcia/socket_sysfs.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/drivers/pcmcia/socket_sysfs.c b/drivers/pcmcia/socket_sysfs.c index 4a3150a7854c..e074bc1f101f 100644 --- a/drivers/pcmcia/socket_sysfs.c +++ b/drivers/pcmcia/socket_sysfs.c @@ -42,35 +42,28 @@ static ssize_t pccard_show_type(struct class_device *dev, char *buf) { - int val; struct pcmcia_socket *s = to_socket(dev); if (!(s->state & SOCKET_PRESENT)) return -ENODEV; - s->ops->get_status(s, &val); - if (val & SS_CARDBUS) + if (s->state & SOCKET_CARDBUS) return sprintf(buf, "32-bit\n"); - if (val & SS_DETECT) - return sprintf(buf, "16-bit\n"); - return sprintf(buf, "invalid\n"); + return sprintf(buf, "16-bit\n"); } -static CLASS_DEVICE_ATTR(card_type, 0400, pccard_show_type, NULL); +static CLASS_DEVICE_ATTR(card_type, 0444, pccard_show_type, NULL); static ssize_t pccard_show_voltage(struct class_device *dev, char *buf) { - int val; struct pcmcia_socket *s = to_socket(dev); if (!(s->state & SOCKET_PRESENT)) return -ENODEV; - s->ops->get_status(s, &val); - if (val & SS_3VCARD) - return sprintf(buf, "3.3V\n"); - if (val & SS_XVCARD) - return sprintf(buf, "X.XV\n"); - return sprintf(buf, "5.0V\n"); + if (s->socket.Vcc) + return sprintf(buf, "%d.%dV\n", s->socket.Vcc / 10, + s->socket.Vcc % 10); + return sprintf(buf, "X.XV\n"); } -static CLASS_DEVICE_ATTR(card_voltage, 0400, pccard_show_voltage, NULL); +static CLASS_DEVICE_ATTR(card_voltage, 0444, pccard_show_voltage, NULL); static ssize_t pccard_show_vpp(struct class_device *dev, char *buf) { @@ -79,7 +72,7 @@ static ssize_t pccard_show_vpp(struct class_device *dev, char *buf) return -ENODEV; return sprintf(buf, "%d.%dV\n", s->socket.Vpp / 10, s->socket.Vpp % 10); } -static CLASS_DEVICE_ATTR(card_vpp, 0400, pccard_show_vpp, NULL); +static CLASS_DEVICE_ATTR(card_vpp, 0444, pccard_show_vpp, NULL); static ssize_t pccard_show_vcc(struct class_device *dev, char *buf) { @@ -88,7 +81,7 @@ static ssize_t pccard_show_vcc(struct class_device *dev, char *buf) return -ENODEV; return sprintf(buf, "%d.%dV\n", s->socket.Vcc / 10, s->socket.Vcc % 10); } -static CLASS_DEVICE_ATTR(card_vcc, 0400, pccard_show_vcc, NULL); +static CLASS_DEVICE_ATTR(card_vcc, 0444, pccard_show_vcc, NULL); static ssize_t pccard_store_insert(struct class_device *dev, const char *buf, size_t count) From 6423efaacbf0bce6372897e793d8450c1c08ec8d Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sun, 11 Dec 2005 20:47:44 +0100 Subject: [PATCH 42/48] [PATCH] pcmcia: no probing of ioports on PARISC Do not wildly probe the IO ports we're trying to use on PARISC. Signed-off-by: Dominik Brodowski --- drivers/pcmcia/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pcmcia/Kconfig b/drivers/pcmcia/Kconfig index df93df64c9f3..1f4ad0e7836e 100644 --- a/drivers/pcmcia/Kconfig +++ b/drivers/pcmcia/Kconfig @@ -225,7 +225,7 @@ config PCMCIA_PXA2XX config PCMCIA_PROBE bool - default y if ISA && !ARCH_SA1100 && !ARCH_CLPS711X + default y if ISA && !ARCH_SA1100 && !ARCH_CLPS711X && !PARISC config M32R_PCC bool "M32R PCMCIA I/F" From 8084b372adac9c24ff7abdd939b2e8816e7b88a3 Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sun, 11 Dec 2005 21:18:26 +0100 Subject: [PATCH 43/48] [PATCH] pcmcia: kzalloc conversion Convert users of kmalloc and memset to kzalloc Signed-off-by: Dominik Brodowski --- drivers/pcmcia/au1000_generic.c | 3 +-- drivers/pcmcia/ds.c | 10 +++------- drivers/pcmcia/pd6729.c | 4 +--- drivers/pcmcia/pxa2xx_mainstone.c | 3 +-- drivers/pcmcia/pxa2xx_sharpsl.c | 3 +-- drivers/pcmcia/rsrc_nonstatic.c | 9 +++------ drivers/pcmcia/soc_common.c | 3 +-- drivers/pcmcia/socket_sysfs.c | 3 +-- drivers/pcmcia/yenta_socket.c | 3 +-- 9 files changed, 13 insertions(+), 28 deletions(-) diff --git a/drivers/pcmcia/au1000_generic.c b/drivers/pcmcia/au1000_generic.c index 0868b72c3996..971a35281649 100644 --- a/drivers/pcmcia/au1000_generic.c +++ b/drivers/pcmcia/au1000_generic.c @@ -354,13 +354,12 @@ int au1x00_pcmcia_socket_probe(struct device *dev, struct pcmcia_low_level *ops, struct skt_dev_info *sinfo; int ret, i; - sinfo = kmalloc(sizeof(struct skt_dev_info), GFP_KERNEL); + sinfo = kzalloc(sizeof(struct skt_dev_info), GFP_KERNEL); if (!sinfo) { ret = -ENOMEM; goto out; } - memset(sinfo, 0, sizeof(struct skt_dev_info)); sinfo->nskt = nr; /* diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index 0fc61dd1d4d0..0252582b91cd 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -264,12 +264,10 @@ static int pcmcia_load_firmware(struct pcmcia_device *dev, char * filename) if (fw->size >= CISTPL_MAX_CIS_SIZE) goto release; - cis = kmalloc(sizeof(cisdump_t), GFP_KERNEL); + cis = kzalloc(sizeof(cisdump_t), GFP_KERNEL); if (!cis) goto release; - memset(cis, 0, sizeof(cisdump_t)); - cis->Length = fw->size + 1; memcpy(cis->Data, fw->data, fw->size); @@ -387,13 +385,12 @@ static int pcmcia_device_probe(struct device * dev) s->functions = mfc.nfn; else s->functions = 1; - s->config = kmalloc(sizeof(config_t) * s->functions, + s->config = kzalloc(sizeof(config_t) * s->functions, GFP_KERNEL); if (!s->config) { ret = -ENOMEM; goto put_module; } - memset(s->config, 0, sizeof(config_t) * s->functions); } ret = p_drv->probe(p_dev); @@ -572,10 +569,9 @@ struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int f if (s->device_count == 2) goto err_put; - p_dev = kmalloc(sizeof(struct pcmcia_device), GFP_KERNEL); + p_dev = kzalloc(sizeof(struct pcmcia_device), GFP_KERNEL); if (!p_dev) goto err_put; - memset(p_dev, 0, sizeof(struct pcmcia_device)); p_dev->socket = s; p_dev->device_no = (s->device_count++); diff --git a/drivers/pcmcia/pd6729.c b/drivers/pcmcia/pd6729.c index e7a6d9ac5ed8..f2789afb22b2 100644 --- a/drivers/pcmcia/pd6729.c +++ b/drivers/pcmcia/pd6729.c @@ -634,13 +634,11 @@ static int __devinit pd6729_pci_probe(struct pci_dev *dev, char configbyte; struct pd6729_socket *socket; - socket = kmalloc(sizeof(struct pd6729_socket) * MAX_SOCKETS, + socket = kzalloc(sizeof(struct pd6729_socket) * MAX_SOCKETS, GFP_KERNEL); if (!socket) return -ENOMEM; - memset(socket, 0, sizeof(struct pd6729_socket) * MAX_SOCKETS); - if ((ret = pci_enable_device(dev))) goto err_out_free_mem; diff --git a/drivers/pcmcia/pxa2xx_mainstone.c b/drivers/pcmcia/pxa2xx_mainstone.c index 5209d8c7764f..5d957dfe23d9 100644 --- a/drivers/pcmcia/pxa2xx_mainstone.c +++ b/drivers/pcmcia/pxa2xx_mainstone.c @@ -171,10 +171,9 @@ static int __init mst_pcmcia_init(void) { int ret; - mst_pcmcia_device = kmalloc(sizeof(*mst_pcmcia_device), GFP_KERNEL); + mst_pcmcia_device = kzalloc(sizeof(*mst_pcmcia_device), GFP_KERNEL); if (!mst_pcmcia_device) return -ENOMEM; - memset(mst_pcmcia_device, 0, sizeof(*mst_pcmcia_device)); mst_pcmcia_device->name = "pxa2xx-pcmcia"; mst_pcmcia_device->dev.platform_data = &mst_pcmcia_ops; diff --git a/drivers/pcmcia/pxa2xx_sharpsl.c b/drivers/pcmcia/pxa2xx_sharpsl.c index 56c58831e80e..b5fdeec20b15 100644 --- a/drivers/pcmcia/pxa2xx_sharpsl.c +++ b/drivers/pcmcia/pxa2xx_sharpsl.c @@ -264,11 +264,10 @@ static int __init sharpsl_pcmcia_init(void) int ret; sharpsl_pcmcia_ops.nr=platform_scoop_config->num_devs; - sharpsl_pcmcia_device = kmalloc(sizeof(*sharpsl_pcmcia_device), GFP_KERNEL); + sharpsl_pcmcia_device = kzalloc(sizeof(*sharpsl_pcmcia_device), GFP_KERNEL); if (!sharpsl_pcmcia_device) return -ENOMEM; - memset(sharpsl_pcmcia_device, 0, sizeof(*sharpsl_pcmcia_device)); sharpsl_pcmcia_device->name = "pxa2xx-pcmcia"; sharpsl_pcmcia_device->dev.platform_data = &sharpsl_pcmcia_ops; sharpsl_pcmcia_device->dev.parent=platform_scoop_config->devs[0].dev; diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c index 6b18092205b1..5301ac60358f 100644 --- a/drivers/pcmcia/rsrc_nonstatic.c +++ b/drivers/pcmcia/rsrc_nonstatic.c @@ -75,10 +75,9 @@ static DECLARE_MUTEX(rsrc_sem); static struct resource * make_resource(unsigned long b, unsigned long n, int flags, char *name) { - struct resource *res = kmalloc(sizeof(*res), GFP_KERNEL); + struct resource *res = kzalloc(sizeof(*res), GFP_KERNEL); if (res) { - memset(res, 0, sizeof(*res)); res->name = name; res->start = b; res->end = b + n - 1; @@ -200,12 +199,11 @@ static void do_io_probe(struct pcmcia_socket *s, kio_addr_t base, kio_addr_t num base, base+num-1); /* First, what does a floating port look like? */ - b = kmalloc(256, GFP_KERNEL); + b = kzalloc(256, GFP_KERNEL); if (!b) { printk(KERN_ERR "do_io_probe: unable to kmalloc 256 bytes"); return; } - memset(b, 0, 256); for (i = base, most = 0; i < base+num; i += 8) { res = claim_region(NULL, i, 8, IORESOURCE_IO, "PCMCIA IO probe"); if (!res) @@ -850,10 +848,9 @@ static int nonstatic_init(struct pcmcia_socket *s) { struct socket_data *data; - data = kmalloc(sizeof(struct socket_data), GFP_KERNEL); + data = kzalloc(sizeof(struct socket_data), GFP_KERNEL); if (!data) return -ENOMEM; - memset(data, 0, sizeof(struct socket_data)); data->mem_db.next = &data->mem_db; data->io_db.next = &data->io_db; diff --git a/drivers/pcmcia/soc_common.c b/drivers/pcmcia/soc_common.c index a563bd9a8898..ea7d9ca160b2 100644 --- a/drivers/pcmcia/soc_common.c +++ b/drivers/pcmcia/soc_common.c @@ -645,13 +645,12 @@ int soc_common_drv_pcmcia_probe(struct device *dev, struct pcmcia_low_level *ops down(&soc_pcmcia_sockets_lock); - sinfo = kmalloc(SKT_DEV_INFO_SIZE(nr), GFP_KERNEL); + sinfo = kzalloc(SKT_DEV_INFO_SIZE(nr), GFP_KERNEL); if (!sinfo) { ret = -ENOMEM; goto out; } - memset(sinfo, 0, SKT_DEV_INFO_SIZE(nr)); sinfo->nskt = nr; /* diff --git a/drivers/pcmcia/socket_sysfs.c b/drivers/pcmcia/socket_sysfs.c index e074bc1f101f..7a7744662d54 100644 --- a/drivers/pcmcia/socket_sysfs.c +++ b/drivers/pcmcia/socket_sysfs.c @@ -285,10 +285,9 @@ static ssize_t pccard_store_cis(struct kobject *kobj, char *buf, loff_t off, siz if (!(s->state & SOCKET_PRESENT)) return -ENODEV; - cis = kmalloc(sizeof(cisdump_t), GFP_KERNEL); + cis = kzalloc(sizeof(cisdump_t), GFP_KERNEL); if (!cis) return -ENOMEM; - memset(cis, 0, sizeof(cisdump_t)); cis->Length = count + 1; memcpy(cis->Data, buf, count); diff --git a/drivers/pcmcia/yenta_socket.c b/drivers/pcmcia/yenta_socket.c index 826e7e133269..4145eb83b9b6 100644 --- a/drivers/pcmcia/yenta_socket.c +++ b/drivers/pcmcia/yenta_socket.c @@ -1019,10 +1019,9 @@ static int __devinit yenta_probe (struct pci_dev *dev, const struct pci_device_i return -ENODEV; } - socket = kmalloc(sizeof(struct yenta_socket), GFP_KERNEL); + socket = kzalloc(sizeof(struct yenta_socket), GFP_KERNEL); if (!socket) return -ENOMEM; - memset(socket, 0, sizeof(*socket)); /* prepare pcmcia_socket */ socket->socket.ops = ¥ta_socket_operations; From 3cf89b185971bf186cec657911f08354e7701635 Mon Sep 17 00:00:00 2001 From: Alexey Dobriyan Date: Fri, 23 Dec 2005 23:51:08 +0300 Subject: [PATCH 44/48] [PATCH] drivers/pcmcia/cistpl.c: fix endian warnings Signed-off-by: Alexey Dobriyan Signed-off-by: Dominik Brodowski --- drivers/pcmcia/cistpl.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c index 55d7247b58e7..120fa8da6392 100644 --- a/drivers/pcmcia/cistpl.c +++ b/drivers/pcmcia/cistpl.c @@ -463,7 +463,7 @@ static int follow_link(struct pcmcia_socket *s, tuple_t *tuple) /* Get indirect link from the MFC tuple */ read_cis_cache(s, LINK_SPACE(tuple->Flags), tuple->LinkOffset, 5, link); - ofs = le32_to_cpu(*(u_int *)(link+1)); + ofs = le32_to_cpu(*(__le32 *)(link+1)); SPACE(tuple->Flags) = (link[0] == CISTPL_MFC_ATTR); /* Move to the next indirect link */ tuple->LinkOffset += 5; @@ -671,8 +671,8 @@ static int parse_checksum(tuple_t *tuple, cistpl_checksum_t *csum) if (tuple->TupleDataLen < 5) return CS_BAD_TUPLE; p = (u_char *)tuple->TupleData; - csum->addr = tuple->CISOffset+(short)le16_to_cpu(*(u_short *)p)-2; - csum->len = le16_to_cpu(*(u_short *)(p + 2)); + csum->addr = tuple->CISOffset+(short)le16_to_cpu(*(__le16 *)p)-2; + csum->len = le16_to_cpu(*(__le16 *)(p + 2)); csum->sum = *(p+4); return CS_SUCCESS; } @@ -683,7 +683,7 @@ static int parse_longlink(tuple_t *tuple, cistpl_longlink_t *link) { if (tuple->TupleDataLen < 4) return CS_BAD_TUPLE; - link->addr = le32_to_cpu(*(u_int *)tuple->TupleData); + link->addr = le32_to_cpu(*(__le32 *)tuple->TupleData); return CS_SUCCESS; } @@ -702,7 +702,7 @@ static int parse_longlink_mfc(tuple_t *tuple, return CS_BAD_TUPLE; for (i = 0; i < link->nfn; i++) { link->fn[i].space = *p; p++; - link->fn[i].addr = le32_to_cpu(*(u_int *)p); p += 4; + link->fn[i].addr = le32_to_cpu(*(__le32 *)p); p += 4; } return CS_SUCCESS; } @@ -789,10 +789,10 @@ static int parse_jedec(tuple_t *tuple, cistpl_jedec_t *jedec) static int parse_manfid(tuple_t *tuple, cistpl_manfid_t *m) { - u_short *p; + __le16 *p; if (tuple->TupleDataLen < 4) return CS_BAD_TUPLE; - p = (u_short *)tuple->TupleData; + p = (__le16 *)tuple->TupleData; m->manf = le16_to_cpu(p[0]); m->card = le16_to_cpu(p[1]); return CS_SUCCESS; @@ -1093,7 +1093,7 @@ static int parse_cftable_entry(tuple_t *tuple, break; case 0x20: entry->mem.nwin = 1; - entry->mem.win[0].len = le16_to_cpu(*(u_short *)p) << 8; + entry->mem.win[0].len = le16_to_cpu(*(__le16 *)p) << 8; entry->mem.win[0].card_addr = 0; entry->mem.win[0].host_addr = 0; p += 2; @@ -1101,9 +1101,9 @@ static int parse_cftable_entry(tuple_t *tuple, break; case 0x40: entry->mem.nwin = 1; - entry->mem.win[0].len = le16_to_cpu(*(u_short *)p) << 8; + entry->mem.win[0].len = le16_to_cpu(*(__le16 *)p) << 8; entry->mem.win[0].card_addr = - le16_to_cpu(*(u_short *)(p+2)) << 8; + le16_to_cpu(*(__le16 *)(p+2)) << 8; entry->mem.win[0].host_addr = 0; p += 4; if (p > q) return CS_BAD_TUPLE; @@ -1140,7 +1140,7 @@ static int parse_bar(tuple_t *tuple, cistpl_bar_t *bar) p = (u_char *)tuple->TupleData; bar->attr = *p; p += 2; - bar->size = le32_to_cpu(*(u_int *)p); + bar->size = le32_to_cpu(*(__le32 *)p); return CS_SUCCESS; } @@ -1153,7 +1153,7 @@ static int parse_config_cb(tuple_t *tuple, cistpl_config_t *config) return CS_BAD_TUPLE; config->last_idx = *(++p); p++; - config->base = le32_to_cpu(*(u_int *)p); + config->base = le32_to_cpu(*(__le32 *)p); config->subtuples = tuple->TupleDataLen - 6; return CS_SUCCESS; } @@ -1269,7 +1269,7 @@ static int parse_vers_2(tuple_t *tuple, cistpl_vers_2_t *v2) v2->vers = p[0]; v2->comply = p[1]; - v2->dindex = le16_to_cpu(*(u_short *)(p+2)); + v2->dindex = le16_to_cpu(*(__le16 *)(p+2)); v2->vspec8 = p[6]; v2->vspec9 = p[7]; v2->nhdr = p[8]; @@ -1310,8 +1310,8 @@ static int parse_format(tuple_t *tuple, cistpl_format_t *fmt) fmt->type = p[0]; fmt->edc = p[1]; - fmt->offset = le32_to_cpu(*(u_int *)(p+2)); - fmt->length = le32_to_cpu(*(u_int *)(p+6)); + fmt->offset = le32_to_cpu(*(__le32 *)(p+2)); + fmt->length = le32_to_cpu(*(__le32 *)(p+6)); return CS_SUCCESS; } From 6e493882726e762d0eb7a0a5fcae42a122ae75a5 Mon Sep 17 00:00:00 2001 From: Daniel Ritz Date: Fri, 30 Dec 2005 15:12:35 +0100 Subject: [PATCH 45/48] [PATCH] pcmcia: cleanup cs.c, reduce size kill the socket_shutdown()/shutdown_socket() confusion by making it one single function. move cs_socket_put() in there. nicer to read and smaller: original: text data bss dec hex filename 25181 1076 32 26289 66b1 drivers/pcmcia/pcmcia_core.ko patched: text data bss dec hex filename 24973 1076 32 26081 65e1 drivers/pcmcia/pcmcia_core.ko Signed-off-by: Daniel Ritz Signed-off-by: Dominik Brodowski --- drivers/pcmcia/cs.c | 88 ++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 49 deletions(-) diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c index 83d2753814c2..613f2f1fbfdd 100644 --- a/drivers/pcmcia/cs.c +++ b/drivers/pcmcia/cs.c @@ -309,41 +309,6 @@ struct pcmcia_socket * pcmcia_get_socket_by_nr(unsigned int nr) } EXPORT_SYMBOL(pcmcia_get_socket_by_nr); - -/** - * socket_setup() and shutdown_socket() are called by the main event - * handler when card insertion and removal events are received. - * socket_setup() turns on socket power and resets the socket, in two stages. - * shutdown_socket() unconfigures a socket and turns off socket power. - */ -static void shutdown_socket(struct pcmcia_socket *s) -{ - cs_dbg(s, 1, "shutdown_socket\n"); - - /* Blank out the socket state */ - s->socket = dead_socket; - s->ops->init(s); - s->ops->set_socket(s, &s->socket); - s->irq.AssignedIRQ = s->irq.Config = 0; - s->lock_count = 0; - destroy_cis_cache(s); -#ifdef CONFIG_CARDBUS - cb_free(s); -#endif - s->functions = 0; - kfree(s->config); - s->config = NULL; - - { - int status; - s->ops->get_status(s, &status); - if (status & SS_POWERON) { - printk(KERN_ERR "PCMCIA: socket %p: *** DANGER *** unable to remove socket power\n", s); - } - } -} /* shutdown_socket */ - - /** * The central event handler. Send_event() sends an event to the * 16-bit subsystem, which then calls the relevant device drivers. @@ -383,17 +348,6 @@ static void socket_remove_drivers(struct pcmcia_socket *skt) send_event(skt, CS_EVENT_CARD_REMOVAL, CS_EVENT_PRI_HIGH); } -static void socket_shutdown(struct pcmcia_socket *skt) -{ - cs_dbg(skt, 4, "shutdown\n"); - - socket_remove_drivers(skt); - skt->state &= SOCKET_INUSE|SOCKET_PRESENT; - msleep(shutdown_delay * 10); - skt->state &= SOCKET_INUSE; - shutdown_socket(skt); -} - static int socket_reset(struct pcmcia_socket *skt) { int status, i; @@ -424,6 +378,45 @@ static int socket_reset(struct pcmcia_socket *skt) return CS_GENERAL_FAILURE; } +/** + * socket_setup() and socket_shutdown() are called by the main event handler + * when card insertion and removal events are received. + * socket_setup() turns on socket power and resets the socket, in two stages. + * socket_shutdown() unconfigures a socket and turns off socket power. + */ +static void socket_shutdown(struct pcmcia_socket *s) +{ + int status; + + cs_dbg(s, 4, "shutdown\n"); + + socket_remove_drivers(s); + s->state &= SOCKET_INUSE | SOCKET_PRESENT; + msleep(shutdown_delay * 10); + s->state &= SOCKET_INUSE; + + /* Blank out the socket state */ + s->socket = dead_socket; + s->ops->init(s); + s->ops->set_socket(s, &s->socket); + s->irq.AssignedIRQ = s->irq.Config = 0; + s->lock_count = 0; + destroy_cis_cache(s); +#ifdef CONFIG_CARDBUS + cb_free(s); +#endif + s->functions = 0; + kfree(s->config); + s->config = NULL; + + s->ops->get_status(s, &status); + if (status & SS_POWERON) { + printk(KERN_ERR "PCMCIA: socket %p: *** DANGER *** unable to remove socket power\n", s); + } + + cs_socket_put(s); +} + static int socket_setup(struct pcmcia_socket *skt, int initial_delay) { int status, i; @@ -529,7 +522,6 @@ static int socket_insert(struct pcmcia_socket *skt) send_event(skt, CS_EVENT_CARD_INSERTION, CS_EVENT_PRI_LOW); } else { socket_shutdown(skt); - cs_socket_put(skt); } return ret; @@ -593,7 +585,6 @@ static int socket_resume(struct pcmcia_socket *skt) } } else { socket_shutdown(skt); - cs_socket_put(skt); } skt->state &= ~SOCKET_SUSPEND; @@ -605,7 +596,6 @@ static void socket_remove(struct pcmcia_socket *skt) { printk(KERN_NOTICE "pccard: card ejected from slot %d\n", skt->sock); socket_shutdown(skt); - cs_socket_put(skt); } /* From 725a6abfe37025975c125ace1c7da35f27ce5384 Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Thu, 5 Jan 2006 09:56:03 +0000 Subject: [PATCH 46/48] [PATCH] pcmcia: add some IDs for ide-cs and dtl1_cs Add some PCMCIA device IDs for the microdrive found in the Sharp Zaurus and a different revision of the Socket CF+ Bluetooth card. Signed-off-by: Richard Purdie Signed-off-by: Dominik Brodowski --- drivers/bluetooth/dtl1_cs.c | 1 + drivers/ide/legacy/ide-cs.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/drivers/bluetooth/dtl1_cs.c b/drivers/bluetooth/dtl1_cs.c index 787c5eb9950e..0449bc45ae5e 100644 --- a/drivers/bluetooth/dtl1_cs.c +++ b/drivers/bluetooth/dtl1_cs.c @@ -755,6 +755,7 @@ static int dtl1_resume(struct pcmcia_device *dev) static struct pcmcia_device_id dtl1_ids[] = { PCMCIA_DEVICE_PROD_ID12("Nokia Mobile Phones", "DTL-1", 0xe1bfdd64, 0xe168480d), PCMCIA_DEVICE_PROD_ID12("Socket", "CF", 0xb38bcc2e, 0x44ebf863), + PCMCIA_DEVICE_PROD_ID12("Socket", "CF+ Personal Network Card", 0xb38bcc2e, 0xe732bae3), PCMCIA_DEVICE_NULL }; MODULE_DEVICE_TABLE(pcmcia, dtl1_ids); diff --git a/drivers/ide/legacy/ide-cs.c b/drivers/ide/legacy/ide-cs.c index e36e6fbbf9e0..4c2af9020905 100644 --- a/drivers/ide/legacy/ide-cs.c +++ b/drivers/ide/legacy/ide-cs.c @@ -412,11 +412,13 @@ static int ide_resume(struct pcmcia_device *dev) static struct pcmcia_device_id ide_ids[] = { PCMCIA_DEVICE_FUNC_ID(4), + PCMCIA_DEVICE_MANF_CARD(0x0007, 0x0000), /* Hitachi */ PCMCIA_DEVICE_MANF_CARD(0x0032, 0x0704), PCMCIA_DEVICE_MANF_CARD(0x0045, 0x0401), PCMCIA_DEVICE_MANF_CARD(0x0098, 0x0000), /* Toshiba */ PCMCIA_DEVICE_MANF_CARD(0x00a4, 0x002d), PCMCIA_DEVICE_MANF_CARD(0x00ce, 0x0000), /* Samsung */ + PCMCIA_DEVICE_MANF_CARD(0x0319, 0x0000), /* Hitachi */ PCMCIA_DEVICE_MANF_CARD(0x2080, 0x0001), PCMCIA_DEVICE_MANF_CARD(0x4e01, 0x0200), /* Lexar */ PCMCIA_DEVICE_PROD_ID123("Caravelle", "PSC-IDE ", "PSC000", 0x8c36137c, 0xd0693ab8, 0x2768a9f0), @@ -431,6 +433,8 @@ static struct pcmcia_device_id ide_ids[] = { PCMCIA_DEVICE_PROD_ID12("EXP ", "CD-ROM", 0x0a5c52fd, 0x66536591), PCMCIA_DEVICE_PROD_ID12("EXP ", "PnPIDE", 0x0a5c52fd, 0x0c694728), PCMCIA_DEVICE_PROD_ID12("FREECOM", "PCCARD-IDE", 0x5714cbf7, 0x48e0ab8e), + PCMCIA_DEVICE_PROD_ID12("HITACHI", "FLASH", 0xf4f43949, 0x9eb86aae), + PCMCIA_DEVICE_PROD_ID12("HITACHI", "microdrive", 0xf4f43949, 0xa6d76178), PCMCIA_DEVICE_PROD_ID12("IBM", "IBM17JSSFP20", 0xb569a6e5, 0xf2508753), PCMCIA_DEVICE_PROD_ID12("IO DATA", "CBIDE2 ", 0x547e66dc, 0x8671043b), PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCIDE", 0x547e66dc, 0x5c5ab149), From e924283bf93989979f27ef4f1228c5925f584a0a Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Thu, 5 Jan 2006 14:57:36 -0800 Subject: [PATCH 47/48] [IPVS]: Another file needs linux/interrupt.h Signed-off-by: Andrew Morton Signed-off-by: David S. Miller --- net/ipv4/ipvs/ip_vs_conn.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/ipv4/ipvs/ip_vs_conn.c b/net/ipv4/ipvs/ip_vs_conn.c index 81d90354c928..87b83813cf2c 100644 --- a/net/ipv4/ipvs/ip_vs_conn.c +++ b/net/ipv4/ipvs/ip_vs_conn.c @@ -24,6 +24,7 @@ * */ +#include #include #include #include From 46f25dffbaba48c571d75f5f574f31978287b8d2 Mon Sep 17 00:00:00 2001 From: Kris Katterjohn Date: Thu, 5 Jan 2006 16:35:42 -0800 Subject: [PATCH 48/48] [NET]: Change 1500 to ETH_DATA_LEN in some files These patches add the header linux/if_ether.h and change 1500 to ETH_DATA_LEN in some files. Signed-off-by: Kris Katterjohn Signed-off-by: David S. Miller --- net/bridge/br_if.c | 5 +++-- net/ethernet/eth.c | 5 +++-- net/ipv4/ip_gre.c | 5 +++-- net/ipv4/ipip.c | 3 ++- net/ipv4/ipmr.c | 3 ++- net/ipv6/sit.c | 3 ++- 6 files changed, 15 insertions(+), 9 deletions(-) diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c index 11321197338e..ba442883e877 100644 --- a/net/bridge/br_if.c +++ b/net/bridge/br_if.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "br_private.h" @@ -323,7 +324,7 @@ int br_del_bridge(const char *name) return ret; } -/* Mtu of the bridge pseudo-device 1500 or the minimum of the ports */ +/* MTU of the bridge pseudo-device: ETH_DATA_LEN or the minimum of the ports */ int br_min_mtu(const struct net_bridge *br) { const struct net_bridge_port *p; @@ -332,7 +333,7 @@ int br_min_mtu(const struct net_bridge *br) ASSERT_RTNL(); if (list_empty(&br->port_list)) - mtu = 1500; + mtu = ETH_DATA_LEN; else { list_for_each_entry(p, &br->port_list, list) { if (!mtu || p->dev->mtu < mtu) diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c index e24577367274..9f4dbeb59315 100644 --- a/net/ethernet/eth.c +++ b/net/ethernet/eth.c @@ -53,6 +53,7 @@ #include #include #include +#include #include #include #include @@ -251,7 +252,7 @@ static int eth_mac_addr(struct net_device *dev, void *p) static int eth_change_mtu(struct net_device *dev, int new_mtu) { - if ((new_mtu < 68) || (new_mtu > 1500)) + if (new_mtu < 68 || new_mtu > ETH_DATA_LEN) return -EINVAL; dev->mtu = new_mtu; return 0; @@ -272,7 +273,7 @@ void ether_setup(struct net_device *dev) dev->type = ARPHRD_ETHER; dev->hard_header_len = ETH_HLEN; - dev->mtu = 1500; /* eth_mtu */ + dev->mtu = ETH_DATA_LEN; dev->addr_len = ETH_ALEN; dev->tx_queue_len = 1000; /* Ethernet wants good queues */ dev->flags = IFF_BROADCAST|IFF_MULTICAST; diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c index 46f9d9cf7a5f..912c42f57c79 100644 --- a/net/ipv4/ip_gre.c +++ b/net/ipv4/ip_gre.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -1140,7 +1141,7 @@ static void ipgre_tunnel_setup(struct net_device *dev) dev->type = ARPHRD_IPGRE; dev->hard_header_len = LL_MAX_HEADER + sizeof(struct iphdr) + 4; - dev->mtu = 1500 - sizeof(struct iphdr) - 4; + dev->mtu = ETH_DATA_LEN - sizeof(struct iphdr) - 4; dev->flags = IFF_NOARP; dev->iflink = 0; dev->addr_len = 4; @@ -1152,7 +1153,7 @@ static int ipgre_tunnel_init(struct net_device *dev) struct ip_tunnel *tunnel; struct iphdr *iph; int hlen = LL_MAX_HEADER; - int mtu = 1500; + int mtu = ETH_DATA_LEN; int addend = sizeof(struct iphdr) + 4; tunnel = (struct ip_tunnel*)dev->priv; diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c index c05c1df0bb04..35571cff81c6 100644 --- a/net/ipv4/ipip.c +++ b/net/ipv4/ipip.c @@ -108,6 +108,7 @@ #include #include #include +#include #include #include @@ -786,7 +787,7 @@ static void ipip_tunnel_setup(struct net_device *dev) dev->type = ARPHRD_TUNNEL; dev->hard_header_len = LL_MAX_HEADER + sizeof(struct iphdr); - dev->mtu = 1500 - sizeof(struct iphdr); + dev->mtu = ETH_DATA_LEN - sizeof(struct iphdr); dev->flags = IFF_NOARP; dev->iflink = 0; dev->addr_len = 4; diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c index caa3b7d2e48a..9a5c0ce7ff35 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include @@ -193,7 +194,7 @@ static struct net_device_stats *reg_vif_get_stats(struct net_device *dev) static void reg_vif_setup(struct net_device *dev) { dev->type = ARPHRD_PIMREG; - dev->mtu = 1500 - sizeof(struct iphdr) - 8; + dev->mtu = ETH_DATA_LEN - sizeof(struct iphdr) - 8; dev->flags = IFF_NOARP; dev->hard_start_xmit = reg_vif_xmit; dev->get_stats = reg_vif_get_stats; diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c index c3123c9e1a8e..577d49732b0f 100644 --- a/net/ipv6/sit.c +++ b/net/ipv6/sit.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -720,7 +721,7 @@ static void ipip6_tunnel_setup(struct net_device *dev) dev->type = ARPHRD_SIT; dev->hard_header_len = LL_MAX_HEADER + sizeof(struct iphdr); - dev->mtu = 1500 - sizeof(struct iphdr); + dev->mtu = ETH_DATA_LEN - sizeof(struct iphdr); dev->flags = IFF_NOARP; dev->iflink = 0; dev->addr_len = 4;