Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / dev / netif / lnc_p / if_lnc_p.c
1 /*
2  *
3  * Copyright (c) 1996 Stefan Esser <se@freebsd.org>
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice immediately at the beginning of the file, without modification,
11  *    this list of conditions, and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. Absolutely no warranty of function or purpose is made by the author
16  *    Stefan Esser.
17  * 4. Modifications may be freely made to this file if the above conditions
18  *    are met.
19  *
20  * $FreeBSD: src/sys/pci/if_lnc_p.c,v 1.13 1999/08/28 00:50:51 peter Exp $
21  */
22
23 #include <sys/param.h>
24 #include <sys/systm.h>
25 #include <sys/malloc.h>
26 #include <sys/kernel.h>
27 #include <pci/pcireg.h>
28 #include <pci/pcivar.h>
29
30 #include "lnc.h"
31
32 #define PCI_DEVICE_ID_PCNet_PCI 0x20001022
33 #define PCI_DEVICE_ID_PCHome_PCI 0x20011022
34
35 extern void *lnc_attach_ne2100_pci __P((int unit, unsigned iobase));
36
37 static const char* lnc_pci_probe __P((pcici_t tag, pcidi_t type));
38 static void lnc_pci_attach __P((pcici_t config_id, int unit));
39
40 static u_long lnc_pci_count = NLNC;
41
42 static struct pci_device lnc_pci_driver = {
43         "lnc",
44         lnc_pci_probe,
45         lnc_pci_attach,
46         &lnc_pci_count,
47         NULL
48 };
49
50 COMPAT_PCI_DRIVER (lnc_pci, lnc_pci_driver);
51
52 static const char*
53 lnc_pci_probe (pcici_t tag, pcidi_t type)
54 {
55         switch(type) {
56         case PCI_DEVICE_ID_PCNet_PCI:
57                 return ("PCNet/PCI Ethernet adapter");
58                 break;
59         case PCI_DEVICE_ID_PCHome_PCI:
60                 return ("PCHome/PCI Ethernet adapter");
61                 break;
62         default:
63                 break;
64         }
65         return (0);
66 }
67
68 void lncintr_sc (void*);
69
70 static void
71 lnc_pci_attach(config_id, unit)
72         pcici_t config_id;
73         int     unit;
74 {
75         unsigned iobase;
76         unsigned data;  /* scratch to make this device a bus master*/
77         void *lnc; /* device specific data for interrupt handler ... */
78
79         if ( !pci_map_port(config_id,PCI_MAP_REG_START,(u_short *)&iobase) )
80             printf("lnc%d: pci_port_map_attach failed?!\n",unit);
81
82
83         /* Make this device a bus master.  This was implictly done by 
84            pci_map_port under 2.2.x -- tvf */
85
86         data = pci_cfgread(config_id, PCIR_COMMAND, 4);
87         data |= PCIM_CMD_PORTEN | PCIM_CMD_BUSMASTEREN;
88         pci_cfgwrite(config_id, PCIR_COMMAND, data, 4);
89
90         lnc = lnc_attach_ne2100_pci(unit, iobase);
91
92         if (!lnc)
93                 return;
94         if(!(pci_map_int(config_id, lncintr_sc, (void *)lnc, &net_imask))) {
95                 free (lnc, M_DEVBUF);
96                 return;
97         }
98
99         return;
100 }