aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/pcmcia
diff options
context:
space:
mode:
authorDominik Brodowski <linux@dominikbrodowski.net>2008-08-02 08:28:43 -0400
committerDominik Brodowski <linux@dominikbrodowski.net>2008-08-22 19:21:28 -0400
commitb54bf94bf91e4ca2a489eb02bca0424ddb55242a (patch)
tree4a5383d29173e24dd1fe71ce3ee4d010e60f391c /drivers/net/pcmcia
parent5fcd4da0090828bd34a1956cb322a483c6bf163c (diff)
pcmcia: use pcmcia_loop_config in net pcmcia drivers
Use the config loop helper in (some) net pcmcia drivers. CC: netdev@vger.kernel.org Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
Diffstat (limited to 'drivers/net/pcmcia')
-rw-r--r--drivers/net/pcmcia/axnet_cs.c71
-rw-r--r--drivers/net/pcmcia/pcnet_cs.c79
-rw-r--r--drivers/net/pcmcia/smc91c92_cs.c96
-rw-r--r--drivers/net/pcmcia/xirc2ps_cs.c73
4 files changed, 144 insertions, 175 deletions
diff --git a/drivers/net/pcmcia/axnet_cs.c b/drivers/net/pcmcia/axnet_cs.c
index 3f682d49a4e6..04ece0b77d1d 100644
--- a/drivers/net/pcmcia/axnet_cs.c
+++ b/drivers/net/pcmcia/axnet_cs.c
@@ -284,58 +284,47 @@ static int try_io_port(struct pcmcia_device *link)
284 } 284 }
285} 285}
286 286
287static int axnet_configcheck(struct pcmcia_device *p_dev,
288 cistpl_cftable_entry_t *cfg,
289 void *priv_data)
290{
291 int i;
292 cistpl_io_t *io = &cfg->io;
293
294 if (cfg->index == 0 || cfg->io.nwin == 0)
295 return -ENODEV;
296
297 p_dev->conf.ConfigIndex = 0x05;
298 /* For multifunction cards, by convention, we configure the
299 network function with window 0, and serial with window 1 */
300 if (io->nwin > 1) {
301 i = (io->win[1].len > io->win[0].len);
302 p_dev->io.BasePort2 = io->win[1-i].base;
303 p_dev->io.NumPorts2 = io->win[1-i].len;
304 } else {
305 i = p_dev->io.NumPorts2 = 0;
306 }
307 p_dev->io.BasePort1 = io->win[i].base;
308 p_dev->io.NumPorts1 = io->win[i].len;
309 p_dev->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
310 if (p_dev->io.NumPorts1 + p_dev->io.NumPorts2 >= 32)
311 return try_io_port(p_dev);
312
313 return -ENODEV;
314}
315
287static int axnet_config(struct pcmcia_device *link) 316static int axnet_config(struct pcmcia_device *link)
288{ 317{
289 struct net_device *dev = link->priv; 318 struct net_device *dev = link->priv;
290 axnet_dev_t *info = PRIV(dev); 319 axnet_dev_t *info = PRIV(dev);
291 tuple_t tuple;
292 cisparse_t parse;
293 int i, j, last_ret, last_fn; 320 int i, j, last_ret, last_fn;
294 u_short buf[64];
295 DECLARE_MAC_BUF(mac); 321 DECLARE_MAC_BUF(mac);
296 322
297 DEBUG(0, "axnet_config(0x%p)\n", link); 323 DEBUG(0, "axnet_config(0x%p)\n", link);
298 324
299 tuple.Attributes = 0;
300 tuple.TupleData = (cisdata_t *)buf;
301 tuple.TupleDataMax = sizeof(buf);
302 tuple.TupleOffset = 0;
303
304 /* don't trust the CIS on this; Linksys got it wrong */ 325 /* don't trust the CIS on this; Linksys got it wrong */
305 link->conf.Present = 0x63; 326 link->conf.Present = 0x63;
306 327 last_ret = pcmcia_loop_config(link, axnet_configcheck, NULL);
307 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
308 tuple.Attributes = 0;
309 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
310 while (last_ret == CS_SUCCESS) {
311 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
312 cistpl_io_t *io = &(parse.cftable_entry.io);
313
314 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
315 pcmcia_parse_tuple(link, &tuple, &parse) != 0 ||
316 cfg->index == 0 || cfg->io.nwin == 0)
317 goto next_entry;
318
319 link->conf.ConfigIndex = 0x05;
320 /* For multifunction cards, by convention, we configure the
321 network function with window 0, and serial with window 1 */
322 if (io->nwin > 1) {
323 i = (io->win[1].len > io->win[0].len);
324 link->io.BasePort2 = io->win[1-i].base;
325 link->io.NumPorts2 = io->win[1-i].len;
326 } else {
327 i = link->io.NumPorts2 = 0;
328 }
329 link->io.BasePort1 = io->win[i].base;
330 link->io.NumPorts1 = io->win[i].len;
331 link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
332 if (link->io.NumPorts1 + link->io.NumPorts2 >= 32) {
333 last_ret = try_io_port(link);
334 if (last_ret == CS_SUCCESS) break;
335 }
336 next_entry:
337 last_ret = pcmcia_get_next_tuple(link, &tuple);
338 }
339 if (last_ret != CS_SUCCESS) { 328 if (last_ret != CS_SUCCESS) {
340 cs_error(link, RequestIO, last_ret); 329 cs_error(link, RequestIO, last_ret);
341 goto failed; 330 goto failed;
diff --git a/drivers/net/pcmcia/pcnet_cs.c b/drivers/net/pcmcia/pcnet_cs.c
index 2d4c4ad89b8d..7a9eeca6adc2 100644
--- a/drivers/net/pcmcia/pcnet_cs.c
+++ b/drivers/net/pcmcia/pcnet_cs.c
@@ -512,58 +512,53 @@ static int try_io_port(struct pcmcia_device *link)
512 } 512 }
513} 513}
514 514
515static int pcnet_confcheck(struct pcmcia_device *p_dev,
516 cistpl_cftable_entry_t *cfg,
517 void *priv_data)
518{
519 int *has_shmem = priv_data;
520 int i;
521 cistpl_io_t *io = &cfg->io;
522
523 if (cfg->index == 0 || cfg->io.nwin == 0)
524 return -EINVAL;
525
526 p_dev->conf.ConfigIndex = cfg->index;
527
528 /* For multifunction cards, by convention, we configure the
529 network function with window 0, and serial with window 1 */
530 if (io->nwin > 1) {
531 i = (io->win[1].len > io->win[0].len);
532 p_dev->io.BasePort2 = io->win[1-i].base;
533 p_dev->io.NumPorts2 = io->win[1-i].len;
534 } else {
535 i = p_dev->io.NumPorts2 = 0;
536 }
537
538 *has_shmem = ((cfg->mem.nwin == 1) &&
539 (cfg->mem.win[0].len >= 0x4000));
540 p_dev->io.BasePort1 = io->win[i].base;
541 p_dev->io.NumPorts1 = io->win[i].len;
542 p_dev->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
543 if (p_dev->io.NumPorts1 + p_dev->io.NumPorts2 >= 32)
544 return try_io_port(p_dev);
545
546 return 0;
547}
548
515static int pcnet_config(struct pcmcia_device *link) 549static int pcnet_config(struct pcmcia_device *link)
516{ 550{
517 struct net_device *dev = link->priv; 551 struct net_device *dev = link->priv;
518 pcnet_dev_t *info = PRIV(dev); 552 pcnet_dev_t *info = PRIV(dev);
519 tuple_t tuple; 553 int last_ret, last_fn, start_pg, stop_pg, cm_offset;
520 cisparse_t parse;
521 int i, last_ret, last_fn, start_pg, stop_pg, cm_offset;
522 int has_shmem = 0; 554 int has_shmem = 0;
523 u_short buf[64];
524 hw_info_t *local_hw_info; 555 hw_info_t *local_hw_info;
525 DECLARE_MAC_BUF(mac); 556 DECLARE_MAC_BUF(mac);
526 557
527 DEBUG(0, "pcnet_config(0x%p)\n", link); 558 DEBUG(0, "pcnet_config(0x%p)\n", link);
528 559
529 tuple.TupleData = (cisdata_t *)buf; 560 last_ret = pcmcia_loop_config(link, pcnet_confcheck, &has_shmem);
530 tuple.TupleDataMax = sizeof(buf); 561 if (last_ret) {
531 tuple.TupleOffset = 0;
532 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
533 tuple.Attributes = 0;
534 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
535 while (last_ret == CS_SUCCESS) {
536 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
537 cistpl_io_t *io = &(parse.cftable_entry.io);
538
539 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
540 pcmcia_parse_tuple(link, &tuple, &parse) != 0 ||
541 cfg->index == 0 || cfg->io.nwin == 0)
542 goto next_entry;
543
544 link->conf.ConfigIndex = cfg->index;
545 /* For multifunction cards, by convention, we configure the
546 network function with window 0, and serial with window 1 */
547 if (io->nwin > 1) {
548 i = (io->win[1].len > io->win[0].len);
549 link->io.BasePort2 = io->win[1-i].base;
550 link->io.NumPorts2 = io->win[1-i].len;
551 } else {
552 i = link->io.NumPorts2 = 0;
553 }
554 has_shmem = ((cfg->mem.nwin == 1) &&
555 (cfg->mem.win[0].len >= 0x4000));
556 link->io.BasePort1 = io->win[i].base;
557 link->io.NumPorts1 = io->win[i].len;
558 link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
559 if (link->io.NumPorts1 + link->io.NumPorts2 >= 32) {
560 last_ret = try_io_port(link);
561 if (last_ret == CS_SUCCESS) break;
562 }
563 next_entry:
564 last_ret = pcmcia_get_next_tuple(link, &tuple);
565 }
566 if (last_ret != CS_SUCCESS) {
567 cs_error(link, RequestIO, last_ret); 562 cs_error(link, RequestIO, last_ret);
568 goto failed; 563 goto failed;
569 } 564 }
diff --git a/drivers/net/pcmcia/smc91c92_cs.c b/drivers/net/pcmcia/smc91c92_cs.c
index 250eb1954c34..c012e3400736 100644
--- a/drivers/net/pcmcia/smc91c92_cs.c
+++ b/drivers/net/pcmcia/smc91c92_cs.c
@@ -459,28 +459,36 @@ static int mhz_3288_power(struct pcmcia_device *link)
459 return 0; 459 return 0;
460} 460}
461 461
462static int mhz_mfc_config_check(struct pcmcia_device *p_dev,
463 cistpl_cftable_entry_t *cf,
464 void *priv_data)
465{
466 int k;
467 p_dev->conf.ConfigIndex = cf->index;
468 p_dev->io.BasePort2 = cf->io.win[0].base;
469 for (k = 0; k < 0x400; k += 0x10) {
470 if (k & 0x80)
471 continue;
472 p_dev->io.BasePort1 = k ^ 0x300;
473 if (!pcmcia_request_io(p_dev, &p_dev->io))
474 return 0;
475 }
476 return -ENODEV;
477}
478
462static int mhz_mfc_config(struct pcmcia_device *link) 479static int mhz_mfc_config(struct pcmcia_device *link)
463{ 480{
464 struct net_device *dev = link->priv; 481 struct net_device *dev = link->priv;
465 struct smc_private *smc = netdev_priv(dev); 482 struct smc_private *smc = netdev_priv(dev);
466 struct smc_cfg_mem *cfg_mem; 483 struct smc_cfg_mem *cfg_mem;
467 tuple_t *tuple;
468 cisparse_t *parse;
469 cistpl_cftable_entry_t *cf;
470 u_char *buf;
471 win_req_t req; 484 win_req_t req;
472 memreq_t mem; 485 memreq_t mem;
473 int i, k; 486 int i;
474 487
475 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL); 488 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
476 if (!cfg_mem) 489 if (!cfg_mem)
477 return CS_OUT_OF_RESOURCE; 490 return CS_OUT_OF_RESOURCE;
478 491
479 tuple = &cfg_mem->tuple;
480 parse = &cfg_mem->parse;
481 cf = &parse->cftable_entry;
482 buf = cfg_mem->buf;
483
484 link->conf.Attributes |= CONF_ENABLE_SPKR; 492 link->conf.Attributes |= CONF_ENABLE_SPKR;
485 link->conf.Status = CCSR_AUDIO_ENA; 493 link->conf.Status = CCSR_AUDIO_ENA;
486 link->irq.Attributes = 494 link->irq.Attributes =
@@ -489,27 +497,9 @@ static int mhz_mfc_config(struct pcmcia_device *link)
489 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8; 497 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
490 link->io.NumPorts2 = 8; 498 link->io.NumPorts2 = 8;
491 499
492 tuple->Attributes = tuple->TupleOffset = 0;
493 tuple->TupleData = (cisdata_t *)buf;
494 tuple->TupleDataMax = 255;
495 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
496
497 i = first_tuple(link, tuple, parse);
498 /* The Megahertz combo cards have modem-like CIS entries, so 500 /* The Megahertz combo cards have modem-like CIS entries, so
499 we have to explicitly try a bunch of port combinations. */ 501 we have to explicitly try a bunch of port combinations. */
500 while (i == CS_SUCCESS) { 502 if (pcmcia_loop_config(link, mhz_mfc_config_check, NULL))
501 link->conf.ConfigIndex = cf->index;
502 link->io.BasePort2 = cf->io.win[0].base;
503 for (k = 0; k < 0x400; k += 0x10) {
504 if (k & 0x80) continue;
505 link->io.BasePort1 = k ^ 0x300;
506 i = pcmcia_request_io(link, &link->io);
507 if (i == CS_SUCCESS) break;
508 }
509 if (i == CS_SUCCESS) break;
510 i = next_tuple(link, tuple, parse);
511 }
512 if (i != CS_SUCCESS)
513 goto free_cfg_mem; 503 goto free_cfg_mem;
514 dev->base_addr = link->io.BasePort1; 504 dev->base_addr = link->io.BasePort1;
515 505
@@ -533,7 +523,7 @@ static int mhz_mfc_config(struct pcmcia_device *link)
533 523
534free_cfg_mem: 524free_cfg_mem:
535 kfree(cfg_mem); 525 kfree(cfg_mem);
536 return i; 526 return -ENODEV;
537} 527}
538 528
539static int mhz_setup(struct pcmcia_device *link) 529static int mhz_setup(struct pcmcia_device *link)
@@ -660,46 +650,26 @@ static int mot_setup(struct pcmcia_device *link)
660 650
661/*====================================================================*/ 651/*====================================================================*/
662 652
653static int smc_configcheck(struct pcmcia_device *p_dev,
654 cistpl_cftable_entry_t *cf,
655 void *priv_data)
656{
657 p_dev->conf.ConfigIndex = cf->index;
658 p_dev->io.BasePort1 = cf->io.win[0].base;
659 p_dev->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK;
660 return pcmcia_request_io(p_dev, &p_dev->io);
661}
662
663static int smc_config(struct pcmcia_device *link) 663static int smc_config(struct pcmcia_device *link)
664{ 664{
665 struct net_device *dev = link->priv; 665 struct net_device *dev = link->priv;
666 struct smc_cfg_mem *cfg_mem;
667 tuple_t *tuple;
668 cisparse_t *parse;
669 cistpl_cftable_entry_t *cf;
670 u_char *buf;
671 int i; 666 int i;
672 667
673 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
674 if (!cfg_mem)
675 return CS_OUT_OF_RESOURCE;
676
677 tuple = &cfg_mem->tuple;
678 parse = &cfg_mem->parse;
679 cf = &parse->cftable_entry;
680 buf = cfg_mem->buf;
681
682 tuple->Attributes = tuple->TupleOffset = 0;
683 tuple->TupleData = (cisdata_t *)buf;
684 tuple->TupleDataMax = 255;
685 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
686
687 link->io.NumPorts1 = 16; 668 link->io.NumPorts1 = 16;
688 i = first_tuple(link, tuple, parse); 669 i = pcmcia_loop_config(link, smc_configcheck, NULL);
689 while (i != CS_NO_MORE_ITEMS) { 670 if (!i)
690 if (i == CS_SUCCESS) { 671 dev->base_addr = link->io.BasePort1;
691 link->conf.ConfigIndex = cf->index;
692 link->io.BasePort1 = cf->io.win[0].base;
693 link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK;
694 i = pcmcia_request_io(link, &link->io);
695 if (i == CS_SUCCESS) break;
696 }
697 i = next_tuple(link, tuple, parse);
698 }
699 if (i == CS_SUCCESS)
700 dev->base_addr = link->io.BasePort1;
701 672
702 kfree(cfg_mem);
703 return i; 673 return i;
704} 674}
705 675
diff --git a/drivers/net/pcmcia/xirc2ps_cs.c b/drivers/net/pcmcia/xirc2ps_cs.c
index f6c4698ce738..b57f022952b4 100644
--- a/drivers/net/pcmcia/xirc2ps_cs.c
+++ b/drivers/net/pcmcia/xirc2ps_cs.c
@@ -715,6 +715,45 @@ has_ce2_string(struct pcmcia_device * p_dev)
715 return 0; 715 return 0;
716} 716}
717 717
718static int
719xirc2ps_config_modem(struct pcmcia_device *p_dev,
720 cistpl_cftable_entry_t *cf,
721 void *priv_data)
722{
723 unsigned int ioaddr;
724
725 if (cf->io.nwin > 0 && (cf->io.win[0].base & 0xf) == 8) {
726 for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
727 p_dev->conf.ConfigIndex = cf->index ;
728 p_dev->io.BasePort2 = cf->io.win[0].base;
729 p_dev->io.BasePort1 = ioaddr;
730 if (!pcmcia_request_io(p_dev, &p_dev->io))
731 return 0;
732 }
733 }
734 return -ENODEV;
735}
736
737static int
738xirc2ps_config_check(struct pcmcia_device *p_dev,
739 cistpl_cftable_entry_t *cf,
740 void *priv_data)
741{
742 int *pass = priv_data;
743
744 if (cf->io.nwin > 0 && (cf->io.win[0].base & 0xf) == 8) {
745 p_dev->conf.ConfigIndex = cf->index ;
746 p_dev->io.BasePort2 = cf->io.win[0].base;
747 p_dev->io.BasePort1 = p_dev->io.BasePort2
748 + (*pass ? (cf->index & 0x20 ? -24:8)
749 : (cf->index & 0x20 ? 8:-24));
750 if (!pcmcia_request_io(p_dev, &p_dev->io))
751 return 0;
752 }
753 return -ENODEV;
754
755}
756
718/**************** 757/****************
719 * xirc2ps_config() is scheduled to run after a CARD_INSERTION event 758 * xirc2ps_config() is scheduled to run after a CARD_INSERTION event
720 * is received, to configure the PCMCIA socket, and to make the 759 * is received, to configure the PCMCIA socket, and to make the
@@ -725,13 +764,12 @@ xirc2ps_config(struct pcmcia_device * link)
725{ 764{
726 struct net_device *dev = link->priv; 765 struct net_device *dev = link->priv;
727 local_info_t *local = netdev_priv(dev); 766 local_info_t *local = netdev_priv(dev);
767 unsigned int ioaddr;
728 tuple_t tuple; 768 tuple_t tuple;
729 cisparse_t parse; 769 cisparse_t parse;
730 unsigned int ioaddr;
731 int err, i; 770 int err, i;
732 u_char buf[64]; 771 u_char buf[64];
733 cistpl_lan_node_id_t *node_id = (cistpl_lan_node_id_t*)parse.funce.data; 772 cistpl_lan_node_id_t *node_id = (cistpl_lan_node_id_t*)parse.funce.data;
734 cistpl_cftable_entry_t *cf = &parse.cftable_entry;
735 DECLARE_MAC_BUF(mac); 773 DECLARE_MAC_BUF(mac);
736 774
737 local->dingo_ccr = NULL; 775 local->dingo_ccr = NULL;
@@ -846,19 +884,8 @@ xirc2ps_config(struct pcmcia_device * link)
846 /* Take the Modem IO port from the CIS and scan for a free 884 /* Take the Modem IO port from the CIS and scan for a free
847 * Ethernet port */ 885 * Ethernet port */
848 link->io.NumPorts1 = 16; /* no Mako stuff anymore */ 886 link->io.NumPorts1 = 16; /* no Mako stuff anymore */
849 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 887 if (!pcmcia_loop_config(link, xirc2ps_config_modem, NULL))
850 for (err = first_tuple(link, &tuple, &parse); !err; 888 goto port_found;
851 err = next_tuple(link, &tuple, &parse)) {
852 if (cf->io.nwin > 0 && (cf->io.win[0].base & 0xf) == 8) {
853 for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
854 link->conf.ConfigIndex = cf->index ;
855 link->io.BasePort2 = cf->io.win[0].base;
856 link->io.BasePort1 = ioaddr;
857 if (!(err=pcmcia_request_io(link, &link->io)))
858 goto port_found;
859 }
860 }
861 }
862 } else { 889 } else {
863 link->io.NumPorts1 = 18; 890 link->io.NumPorts1 = 18;
864 /* We do 2 passes here: The first one uses the regular mapping and 891 /* We do 2 passes here: The first one uses the regular mapping and
@@ -866,21 +893,9 @@ xirc2ps_config(struct pcmcia_device * link)
866 * mirrored every 32 bytes. Actually we use a mirrored port for 893 * mirrored every 32 bytes. Actually we use a mirrored port for
867 * the Mako if (on the first pass) the COR bit 5 is set. 894 * the Mako if (on the first pass) the COR bit 5 is set.
868 */ 895 */
869 for (pass=0; pass < 2; pass++) { 896 for (pass=0; pass < 2; pass++)
870 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 897 if (!pcmcia_loop_config(link, xirc2ps_config_check, &pass))
871 for (err = first_tuple(link, &tuple, &parse); !err;
872 err = next_tuple(link, &tuple, &parse)){
873 if (cf->io.nwin > 0 && (cf->io.win[0].base & 0xf) == 8){
874 link->conf.ConfigIndex = cf->index ;
875 link->io.BasePort2 = cf->io.win[0].base;
876 link->io.BasePort1 = link->io.BasePort2
877 + (pass ? (cf->index & 0x20 ? -24:8)
878 : (cf->index & 0x20 ? 8:-24));
879 if (!(err=pcmcia_request_io(link, &link->io)))
880 goto port_found; 898 goto port_found;
881 }
882 }
883 }
884 /* if special option: 899 /* if special option:
885 * try to configure as Ethernet only. 900 * try to configure as Ethernet only.
886 * .... */ 901 * .... */