3 * ===================================
4 * HARP | Host ATM Research Platform
5 * ===================================
8 * This Host ATM Research Platform ("HARP") file (the "Software") is
9 * made available by Network Computing Services, Inc. ("NetworkCS")
10 * "AS IS". NetworkCS does not provide maintenance, improvements or
11 * support of any kind.
13 * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
14 * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
15 * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
16 * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
17 * In no event shall NetworkCS be responsible for any damages, including
18 * but not limited to consequential damages, arising from or relating to
19 * any use of the Software or related support.
21 * Copyright 1994-1998 Network Computing Services, Inc.
23 * Copies of this Software may be made, however, the above copyright
24 * notice must be reproduced on all copies.
26 * @(#) $FreeBSD: src/sys/dev/hfa/fore_load.c,v 1.13 1999/09/25 18:23:49 phk Exp $
27 * @(#) $DragonFly: src/sys/dev/atm/hfa/fore_load.c,v 1.14 2008/03/01 22:03:13 swildner Exp $
31 * FORE Systems 200-Series Adapter Support
32 * ---------------------------------------
34 * Loadable kernel module and device identification support
38 #include "fore_include.h"
43 static int fore_start (void);
44 static const char * fore_pci_probe (pcici_t, pcidi_t);
45 static void fore_pci_attach (pcici_t, int);
46 static void fore_pci_shutdown (void *, int);
47 static void fore_unattach (Fore_unit *);
48 static void fore_reset (Fore_unit *);
54 static int fore_inited = 0;
59 static u_long fore_pci_count = 0;
61 static struct pci_device fore_pci_device = {
69 COMPAT_PCI_DRIVER(fore_pci, fore_pci_device);
72 * Initialize driver processing
74 * This will be called during module loading. Not much to do here, as
75 * we must wait for our identify/attach routines to get called before
76 * we know what we're in for.
82 * 0 startup was successful
83 * errno startup failed - reason indicated
91 * Verify software version
93 if (atm_version != ATM_VERSION) {
94 log(LOG_ERR, "version mismatch: fore=%d.%d kernel=%d.%d\n",
95 ATM_VERS_MAJ(ATM_VERSION), ATM_VERS_MIN(ATM_VERSION),
96 ATM_VERS_MAJ(atm_version), ATM_VERS_MIN(atm_version));
101 * Initialize DMA mapping
106 * Start up watchdog timer
108 atm_timeout(&fore_timer, ATM_HZ * FORE_TIME_TICK, fore_timeout);
116 * Device probe routine
118 * Determine if this driver will support the identified device. If we claim
119 * to support the device, our attach routine will (later) be called for the
123 * config_id device's PCI configuration ID
124 * device_id device's PCI Vendor/Device ID
127 * name device identification string
128 * NULL device not claimed by this driver
132 fore_pci_probe(pcici_t config_id, pcidi_t device_id)
136 * Initialize driver stuff
138 if (fore_inited == 0) {
143 if ((device_id & 0xffff) != FORE_VENDOR_ID)
146 if (((device_id >> 16) & 0xffff) == FORE_PCA200E_ID)
147 return ("FORE Systems PCA-200E ATM");
154 * Device attach routine
156 * Attach a device we've previously claimed to support. Walk through its
157 * register set and map, as required. Determine what level the device will
158 * be interrupting at and then register an interrupt handler for it. If we
159 * succeed, then reset the adapter and initialize the microcode.
160 * Last, register the interface with the kernel ATM services.
163 * config_id device's PCI configuration ID
164 * unit device unit number
171 fore_pci_attach(pcici_t config_id, int unit)
178 int err_count = BOOT_LOOPS;
183 if (unit >= FORE_MAX_UNITS) {
184 log(LOG_ERR, "%s%d: too many devices\n",
185 FORE_DEV_NAME, unit);
190 * Make sure this isn't a duplicate unit
192 if (fore_units[unit] != NULL)
196 * Allocate a new unit structure
198 fup = (Fore_unit *) atm_dev_alloc(sizeof(Fore_unit), sizeof(int), 0);
203 * Start initializing it
206 fup->fu_mtu = FORE_IFF_MTU;
207 fup->fu_pcitag = config_id;
208 fup->fu_vcc_pool = &fore_vcc_pool;
209 fup->fu_nif_pool = &fore_nif_pool;
210 fup->fu_ioctl = fore_atm_ioctl;
211 fup->fu_instvcc = fore_instvcc;
212 fup->fu_openvcc = fore_openvcc;
213 fup->fu_closevcc = fore_closevcc;
214 fup->fu_output = fore_output;
215 callout_init(&fup->fu_init_timer);
218 * Get our device type
220 device_id = pci_conf_read ( config_id, PCI_ID_REG );
221 switch ((device_id >> 16) & 0xffff) {
223 case FORE_PCA200E_ID:
224 fup->fu_config.ac_device = DEV_FORE_PCA200E;
228 fup->fu_config.ac_device = DEV_UNKNOWN;
232 * Enable Memory Mapping / Bus Mastering
234 val = pci_conf_read(config_id, PCI_COMMAND_STATUS_REG);
235 val |= (PCIM_CMD_MEMEN | PCIM_CMD_BUSMASTEREN);
236 pci_conf_write(config_id, PCI_COMMAND_STATUS_REG, val);
241 val = pci_conf_read(config_id, PCI_COMMAND_STATUS_REG);
242 if ((val & PCIM_CMD_MEMEN) == 0) {
243 log(LOG_ERR, "%s%d: memory mapping not enabled\n",
244 FORE_DEV_NAME, unit);
247 if ((pci_map_mem(config_id, PCA200E_PCI_MEMBASE, &va, &pa)) == 0) {
248 log(LOG_ERR, "%s%d: unable to map memory\n",
249 FORE_DEV_NAME, unit);
252 fup->fu_ram = (Fore_mem *)va;
253 fup->fu_ramsize = PCA200E_RAM_SIZE;
254 fup->fu_mon = (Mon960 *)(fup->fu_ram + MON960_BASE);
255 fup->fu_ctlreg = (Fore_reg *)(va + PCA200E_HCR_OFFSET);
256 fup->fu_imask = (Fore_reg *)(va + PCA200E_IMASK_OFFSET);
257 fup->fu_psr = (Fore_reg *)(va + PCA200E_PSR_OFFSET);
260 * Convert Endianess of Slave RAM accesses
262 val = pci_conf_read(config_id, PCA200E_PCI_MCTL);
263 val |= PCA200E_MCTL_SWAP;
264 pci_conf_write(config_id, PCA200E_PCI_MCTL, val);
269 if ( !pci_map_int( config_id, fore_intr, fup) ) {
270 log(LOG_ERR, "%s%d: unable to map interrupt\n",
271 FORE_DEV_NAME, unit);
276 * Poke the hardware - boot the CP and prepare it for downloading
281 * Wait for the monitor to perform self-test
283 while (CP_READ(fup->fu_mon->mon_bstat) != BOOT_MONREADY) {
284 if (CP_READ(fup->fu_mon->mon_bstat) == BOOT_FAILTEST) {
285 log(LOG_ERR, "%s%d: failed self-test\n",
286 FORE_DEV_NAME, unit);
288 } else if ( --err_count == 0 ) {
289 log(LOG_ERR, "%s%d: unable to boot - status=0x%lx\n",
291 (u_long)CP_READ(fup->fu_mon->mon_bstat));
294 DELAY ( BOOT_DELAY );
298 * Setup the adapter config info - at least as much as we can
300 fup->fu_config.ac_vendor = VENDOR_FORE;
301 fup->fu_config.ac_vendapi = VENDAPI_FORE_1;
302 fup->fu_config.ac_media = MEDIA_OC3C;
303 fup->fu_pif.pif_pcr = ATM_PCR_OC3C;
304 fup->fu_config.ac_bustype = BUS_PCI;
305 fup->fu_config.ac_busslot = config_id->bus << 8 | config_id->slot;
308 * Save device ram info for user-level programs
310 fup->fu_config.ac_ram = (long)fup->fu_ram;
311 fup->fu_config.ac_ramsize = fup->fu_ramsize;
314 * Set device capabilities
316 fup->fu_pif.pif_maxvpi = FORE_MAX_VPI;
317 fup->fu_pif.pif_maxvci = FORE_MAX_VCI;
320 * Register this interface with ATM core services
322 if ( atm_physif_register
323 ((Cmn_unit *)fup, FORE_DEV_NAME, fore_services) != 0 )
326 * Registration failed - back everything out
331 fore_units[unit] = fup;
335 * Add hook to our shutdown function
337 EVENTHANDLER_REGISTER(shutdown_post_sync, fore_pci_shutdown, fup,
338 SHUTDOWN_PRI_DRIVER);
341 * Initialize the CP microcode program.
343 fore_initialize(fup);
349 * Unattach the device from the system
354 * Free any Fore-specific device resources
356 fore_interface_free(fup);
364 * Device shutdown routine
367 * howto type of shutdown
368 * fup pointer to device unit structure
375 fore_pci_shutdown(void *fup, int howto)
378 fore_reset((Fore_unit *) fup);
384 * Device unattach routine
386 * Reset the physical device, remove any pending timeouts,
387 * unmap any register sets, and unregister any interrupts.
390 * fup pointer to device unit structure
396 fore_unattach(Fore_unit *fup)
399 * Reset the board and return it to cold_start state.
400 * Hopefully, this will prevent use of resources as
401 * we're trying to free things up.
406 * Lock out all device interrupts
408 DEVICE_LOCK((Cmn_unit *)fup);
411 * Remove any pending timeout()'s
413 callout_stop(&fup->fu_init_timer);
416 * Unmap the device interrupt
418 (void) pci_unmap_int(fup->fu_pcitag);
424 (void) pci_unmap_mem(fup->fu_pcitag, PCA200E_PCI_MEMBASE);
427 DEVICE_UNLOCK((Cmn_unit *)fup);
432 * Device reset routine
434 * Reset the physical device
437 * fup pointer to device unit structure
443 fore_reset(Fore_unit *fup)
446 * Reset the board and return it to cold_start state
450 fup->fu_mon->mon_bstat = CP_WRITE(BOOT_COLDSTART);
452 if (fup->fu_ctlreg) {
454 switch (fup->fu_config.ac_device) {
456 case DEV_FORE_PCA200E:
458 * Reset i960 by setting and clearing RESET
460 PCA200E_HCR_INIT(*fup->fu_ctlreg, PCA200E_RESET);
462 PCA200E_HCR_CLR(*fup->fu_ctlreg, PCA200E_RESET);
466 panic("fore_reset: unknown device type");
477 *******************************************************************
479 * Loadable Module Support
481 *******************************************************************
487 * Driver entry points
489 static struct cdevsw fore_cdev = {
503 /* strategy */ nostrategy,
510 * Loadable device driver module description
512 MOD_DEV(fore, LM_DT_CHAR, -1, (void *)&fore_cdev);
516 * Loadable module support "load" entry point
518 * This is the routine called by the lkm driver whenever the
519 * modload(1) command is issued for this module.
522 * lkmtp pointer to lkm drivers's structure
523 * cmd lkm command code
526 * 0 command was successful
527 * errno command failed - reason indicated
531 fore_load(struct lkm_table *lkmtp, int cmd)
533 return(fore_doload());
538 * Loadable module support "unload" entry point
540 * This is the routine called by the lkm driver whenever the
541 * modunload(1) command is issued for this module.
544 * lkmtp pointer to lkm drivers's structure
545 * cmd lkm command code
548 * 0 command was successful
549 * errno command failed - reason indicated
553 fore_unload(struct lkm_table *lkmtp, int cmd)
555 return(fore_dounload());
560 * Loadable module support entry point
562 * This is the routine called by the lkm driver for all loadable module
563 * functions for this driver. This routine name must be specified
564 * on the modload(1) command. This routine will be called whenever the
565 * modload(1), modunload(1) or modstat(1) commands are issued for this
569 * lkmtp pointer to lkm drivers's structure
570 * cmd lkm command code
574 * 0 command was successful
575 * errno command failed - reason indicated
579 fore_mod(struct lkm_table *lkmtp, int cmd, int ver)
581 DISPATCH(lkmtp, cmd, ver, fore_load, fore_unload, lkm_nullcmd);
585 #endif /* ATM_LINKED */