Skip to content

Commit aa584ca

Browse files
author
Dominik Brodowski
committed
pcmcia: use state machine for extended requery
The requery callback now also handles the addition of a second pseudo multifunction device. Avoids messing with dev_{g,s}et_drvdata(), and fixes any workqueue <-> skt_mutex deadlock. Tested-by: Wolfram Sang <w.sang@pengutronix.de> Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
1 parent af461fc commit aa584ca

2 files changed

Lines changed: 25 additions & 78 deletions

File tree

‎drivers/pcmcia/ds.c‎

Lines changed: 22 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -244,23 +244,11 @@ static void pcmcia_release_dev(struct device *dev)
244244
kfree(p_dev);
245245
}
246246

247-
static void pcmcia_add_device_later(struct pcmcia_socket *s, int mfc)
248-
{
249-
if (!s->pcmcia_state.device_add_pending) {
250-
dev_dbg(&s->dev, "scheduling to add %s secondary"
251-
" device to %d\n", mfc ? "mfc" : "pfc", s->sock);
252-
s->pcmcia_state.device_add_pending = 1;
253-
s->pcmcia_state.mfc_pfc = mfc;
254-
schedule_work(&s->device_add);
255-
}
256-
return;
257-
}
258247

259248
static int pcmcia_device_probe(struct device *dev)
260249
{
261250
struct pcmcia_device *p_dev;
262251
struct pcmcia_driver *p_drv;
263-
struct pcmcia_device_id *did;
264252
struct pcmcia_socket *s;
265253
cistpl_config_t cis_config;
266254
int ret = 0;
@@ -273,18 +261,6 @@ static int pcmcia_device_probe(struct device *dev)
273261
p_drv = to_pcmcia_drv(dev->driver);
274262
s = p_dev->socket;
275263

276-
/* The PCMCIA code passes the match data in via dev_set_drvdata(dev)
277-
* which is an ugly hack. Once the driver probe is called it may
278-
* and often will overwrite the match data so we must save it first
279-
*
280-
* handle pseudo multifunction devices:
281-
* there are at most two pseudo multifunction devices.
282-
* if we're matching against the first, schedule a
283-
* call which will then check whether there are two
284-
* pseudo devices, and if not, add the second one.
285-
*/
286-
did = dev_get_drvdata(&p_dev->dev);
287-
288264
dev_dbg(dev, "trying to bind to %s\n", p_drv->drv.name);
289265

290266
if ((!p_drv->probe) || (!p_dev->function_config) ||
@@ -314,9 +290,9 @@ static int pcmcia_device_probe(struct device *dev)
314290
}
315291

316292
mutex_lock(&s->ops_mutex);
317-
if (did && (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) &&
293+
if ((s->pcmcia_state.has_pfc) &&
318294
(p_dev->socket->device_count == 1) && (p_dev->device_no == 0))
319-
pcmcia_add_device_later(p_dev->socket, 0);
295+
pcmcia_parse_uevents(s, PCMCIA_UEVENT_REQUERY);
320296
mutex_unlock(&s->ops_mutex);
321297

322298
put_module:
@@ -369,7 +345,6 @@ static int pcmcia_device_remove(struct device *dev)
369345
{
370346
struct pcmcia_device *p_dev;
371347
struct pcmcia_driver *p_drv;
372-
struct pcmcia_device_id *did;
373348
int i;
374349

375350
p_dev = to_pcmcia_dev(dev);
@@ -381,8 +356,7 @@ static int pcmcia_device_remove(struct device *dev)
381356
* pseudo multi-function card, we need to unbind
382357
* all devices
383358
*/
384-
did = dev_get_drvdata(&p_dev->dev);
385-
if (did && (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) &&
359+
if ((p_dev->socket->pcmcia_state.has_pfc) &&
386360
(p_dev->socket->device_count > 0) &&
387361
(p_dev->device_no == 0))
388362
pcmcia_card_remove(p_dev->socket, p_dev);
@@ -528,8 +502,8 @@ struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, unsigned int fu
528502
p_dev->device_no = (s->device_count++);
529503
mutex_unlock(&s->ops_mutex);
530504

531-
/* max of 4 devices per card */
532-
if (p_dev->device_no >= 4)
505+
/* max of 2 devices per card */
506+
if (p_dev->device_no >= 2)
533507
goto err_free;
534508

535509
p_dev->socket = s;
@@ -652,22 +626,6 @@ static int pcmcia_card_add(struct pcmcia_socket *s)
652626
}
653627

654628

655-
static void pcmcia_delayed_add_device(struct work_struct *work)
656-
{
657-
struct pcmcia_socket *s =
658-
container_of(work, struct pcmcia_socket, device_add);
659-
u8 mfc_pfc;
660-
661-
mutex_lock(&s->ops_mutex);
662-
mfc_pfc = s->pcmcia_state.mfc_pfc;
663-
s->pcmcia_state.device_add_pending = 0;
664-
s->pcmcia_state.mfc_pfc = 0;
665-
mutex_unlock(&s->ops_mutex);
666-
667-
dev_dbg(&s->dev, "adding additional device to %d\n", s->sock);
668-
pcmcia_device_add(s, mfc_pfc);
669-
}
670-
671629
static int pcmcia_requery_callback(struct device *dev, void * _data)
672630
{
673631
struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
@@ -679,9 +637,10 @@ static int pcmcia_requery_callback(struct device *dev, void * _data)
679637
return 0;
680638
}
681639

640+
682641
static void pcmcia_requery(struct pcmcia_socket *s)
683642
{
684-
int present;
643+
int present, has_pfc;
685644

686645
mutex_lock(&s->ops_mutex);
687646
present = s->pcmcia_state.present;
@@ -723,6 +682,15 @@ static void pcmcia_requery(struct pcmcia_socket *s)
723682
}
724683
}
725684

685+
/* If the PCMCIA device consists of two pseudo devices,
686+
* call pcmcia_device_add() -- which will fail if both
687+
* devices are already registered. */
688+
mutex_lock(&s->ops_mutex);
689+
has_pfc = s->pcmcia_state.has_pfc;
690+
mutex_unlock(&s->ops_mutex);
691+
if (has_pfc)
692+
pcmcia_device_add(s, 0);
693+
726694
/* we re-scan all devices, not just the ones connected to this
727695
* socket. This does not matter, though. */
728696
if (bus_rescan_devices(&pcmcia_bus_type))
@@ -746,9 +714,6 @@ static int pcmcia_load_firmware(struct pcmcia_device *dev, char * filename)
746714
struct pcmcia_socket *s = dev->socket;
747715
const struct firmware *fw;
748716
int ret = -ENOMEM;
749-
int no_funcs;
750-
int old_funcs;
751-
cistpl_longlink_mfc_t mfc;
752717

753718
if (!filename)
754719
return -EINVAL;
@@ -775,22 +740,8 @@ static int pcmcia_load_firmware(struct pcmcia_device *dev, char * filename)
775740
/* update information */
776741
pcmcia_device_query(dev);
777742

778-
/* does this cis override add or remove functions? */
779-
old_funcs = s->functions;
780-
781-
if (!pccard_read_tuple(s, BIND_FN_ALL, CISTPL_LONGLINK_MFC, &mfc))
782-
no_funcs = mfc.nfn;
783-
else
784-
no_funcs = 1;
785-
s->functions = no_funcs;
786-
787-
if (old_funcs > no_funcs)
788-
pcmcia_card_remove(s, dev);
789-
else if (no_funcs > old_funcs) {
790-
mutex_lock(&s->ops_mutex);
791-
pcmcia_add_device_later(s, 1);
792-
mutex_unlock(&s->ops_mutex);
793-
}
743+
/* requery (as number of functions might have changed) */
744+
pcmcia_parse_uevents(s, PCMCIA_UEVENT_REQUERY);
794745
}
795746
release:
796747
release_firmware(fw);
@@ -857,6 +808,9 @@ static inline int pcmcia_devmatch(struct pcmcia_device *dev,
857808
if (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) {
858809
if (dev->device_no != did->device_no)
859810
return 0;
811+
mutex_lock(&dev->socket->ops_mutex);
812+
dev->socket->pcmcia_state.has_pfc = 1;
813+
mutex_unlock(&dev->socket->ops_mutex);
860814
}
861815

862816
if (did->match_flags & PCMCIA_DEV_ID_MATCH_FUNC_ID) {
@@ -905,8 +859,6 @@ static inline int pcmcia_devmatch(struct pcmcia_device *dev,
905859
return 0;
906860
}
907861

908-
dev_set_drvdata(&dev->dev, did);
909-
910862
return 1;
911863
}
912864

@@ -1300,6 +1252,7 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority)
13001252

13011253
case CS_EVENT_CARD_INSERTION:
13021254
mutex_lock(&s->ops_mutex);
1255+
s->pcmcia_state.has_pfc = 0;
13031256
s->pcmcia_state.present = 1;
13041257
destroy_cis_cache(s); /* to be on the safe side... */
13051258
mutex_unlock(&s->ops_mutex);
@@ -1411,7 +1364,6 @@ static int __devinit pcmcia_bus_add_socket(struct device *dev,
14111364
init_waitqueue_head(&socket->queue);
14121365
#endif
14131366
INIT_LIST_HEAD(&socket->devices_list);
1414-
INIT_WORK(&socket->device_add, pcmcia_delayed_add_device);
14151367
memset(&socket->pcmcia_state, 0, sizeof(u8));
14161368
socket->device_count = 0;
14171369

‎include/pcmcia/ss.h‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,18 +230,13 @@ struct pcmcia_socket {
230230
u8 busy:1;
231231
/* pcmcia module is being unloaded */
232232
u8 dead:1;
233-
/* a multifunction-device add event is pending */
234-
u8 device_add_pending:1;
235-
/* the pending event adds a mfc (1) or pfc (0) */
236-
u8 mfc_pfc:1;
233+
/* the PCMCIA card consists of two pseudo devices */
234+
u8 has_pfc:1;
237235

238-
u8 reserved:3;
236+
u8 reserved:4;
239237
} pcmcia_state;
240238

241239

242-
/* for adding further pseudo-multifunction devices */
243-
struct work_struct device_add;
244-
245240
#ifdef CONFIG_PCMCIA_IOCTL
246241
struct user_info_t *user;
247242
wait_queue_head_t queue;

0 commit comments

Comments
 (0)