diff options
| author | cvs2svn <cvs2svn@FreeBSD.org> | 1999-05-24 16:47:10 +0000 |
|---|---|---|
| committer | cvs2svn <cvs2svn@FreeBSD.org> | 1999-05-24 16:47:10 +0000 |
| commit | c37538200ebdef38051ba82b76e6b2dab3bd2fdc (patch) | |
| tree | 3c937e1c39e039ed95d3b8ead3defc46cf60cc04 /sys/dev | |
| parent | a21d905bae94bc358756957b1c26e2ec3f487e82 (diff) | |
Notes
Diffstat (limited to 'sys/dev')
| -rw-r--r-- | sys/dev/aic7xxx/aic7xxx.c | 966 | ||||
| -rw-r--r-- | sys/dev/aic7xxx/aic7xxx.h | 137 | ||||
| -rw-r--r-- | sys/dev/aic7xxx/aic7xxx.reg | 13 | ||||
| -rw-r--r-- | sys/dev/aic7xxx/aic7xxx.seq | 14 | ||||
| -rw-r--r-- | sys/dev/aic7xxx/aicasm_symbol.c | 20 | ||||
| -rw-r--r-- | sys/dev/pccard/if_xe.c | 2404 | ||||
| -rw-r--r-- | sys/dev/pccard/if_xereg.h | 296 |
7 files changed, 726 insertions, 3124 deletions
diff --git a/sys/dev/aic7xxx/aic7xxx.c b/sys/dev/aic7xxx/aic7xxx.c index b0dbf367c293..8da50f326580 100644 --- a/sys/dev/aic7xxx/aic7xxx.c +++ b/sys/dev/aic7xxx/aic7xxx.c @@ -36,7 +36,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: aic7xxx.c,v 1.16.2.6 1999/04/19 21:37:50 gibbs Exp $ + * $Id: aic7xxx.c,v 1.16.2.7 1999/05/07 00:43:26 ken Exp $ */ /* * A few notes on features of the driver. @@ -192,7 +192,7 @@ typedef enum { SEARCH_REMOVE } ahc_search_action; -u_long ahc_unit = 0; +u_long ahc_unit; #ifdef AHC_DEBUG static int ahc_debug = AHC_DEBUG; @@ -202,6 +202,11 @@ static int ahc_debug = AHC_DEBUG; void ahc_pci_intr(struct ahc_softc *ahc); #endif +static int ahcinitscbdata(struct ahc_softc *ahc); +static void ahcfiniscbdata(struct ahc_softc *ahc); + +static bus_dmamap_callback_t ahcdmamapcb; + #if UNUSED static void ahc_dump_targcmd(struct target_cmd *cmd); #endif @@ -221,11 +226,7 @@ static void ahc_poll(struct cam_sim *sim); static void ahc_setup_data(struct ahc_softc *ahc, struct ccb_scsiio *csio, struct scb *scb); static void ahc_freeze_devq(struct ahc_softc *ahc, struct cam_path *path); -static struct scb * - ahc_get_scb(struct ahc_softc *ahc); -static void ahc_free_scb(struct ahc_softc *ahc, struct scb *scb); -static struct scb * - ahc_alloc_scb(struct ahc_softc *ahc); +static void ahcallocscbs(struct ahc_softc *ahc); static void ahc_scb_devinfo(struct ahc_softc *ahc, struct ahc_devinfo *devinfo, struct scb *scb); @@ -350,8 +351,8 @@ static __inline void ahc_busy_tcl(struct ahc_softc *ahc, struct scb *scb); static __inline void ahc_freeze_ccb(union ccb* ccb); static __inline cam_status ahc_ccb_status(union ccb* ccb); -static __inline void ahc_set_ccb_status(union ccb* ccb, - cam_status status); +static __inline void ahcsetccbstatus(union ccb* ccb, + cam_status status); static __inline void ahc_run_tqinfifo(struct ahc_softc *ahc); static __inline struct ahc_initiator_tinfo * @@ -359,11 +360,16 @@ static __inline struct ahc_initiator_tinfo * char channel, u_int our_id, u_int target, struct tmode_tstate **tstate); +static __inline void + ahcfreescb(struct ahc_softc *ahc, struct scb *scb); +static __inline struct scb * + ahcgetscb(struct ahc_softc *ahc); static __inline u_int32_t ahc_hscb_busaddr(struct ahc_softc *ahc, u_int index) { - return (ahc->hscb_busaddr + (sizeof(struct hardware_scb) * index)); + return (ahc->scb_data->hscb_busaddr + + (sizeof(struct hardware_scb) * index)); } #define AHC_BUSRESET_DELAY 25 /* Reset delay in us */ @@ -440,7 +446,7 @@ ahc_ccb_status(union ccb* ccb) } static __inline void -ahc_set_ccb_status(union ccb* ccb, cam_status status) +ahcsetccbstatus(union ccb* ccb, cam_status status) { ccb->ccb_h.status &= ~CAM_STATUS_MASK; ccb->ccb_h.status |= status; @@ -491,6 +497,62 @@ ahc_run_tqinfifo(struct ahc_softc *ahc) } } +/* + * An scb (and hence an scb entry on the board) is put onto the + * free list. + */ +static __inline void +ahcfreescb(struct ahc_softc *ahc, struct scb *scb) +{ + struct hardware_scb *hscb; + int opri; + + hscb = scb->hscb; + + opri = splcam(); + + if ((ahc->flags & AHC_RESOURCE_SHORTAGE) != 0 + && (scb->ccb->ccb_h.status & CAM_RELEASE_SIMQ) == 0) { + scb->ccb->ccb_h.status |= CAM_RELEASE_SIMQ; + ahc->flags &= ~AHC_RESOURCE_SHORTAGE; + } + + /* Clean up for the next user */ + scb->flags = SCB_FREE; + hscb->control = 0; + hscb->status = 0; + + SLIST_INSERT_HEAD(&ahc->scb_data->free_scbs, scb, links); + splx(opri); +} + +/* + * Get a free scb, either one already assigned to a hardware slot + * on the adapter or one that will require an SCB to be paged out before + * use. If there are none, see if we can allocate a new SCB. Otherwise + * either return an error or sleep. + */ +static __inline struct scb * +ahcgetscb(struct ahc_softc *ahc) +{ + struct scb *scbp; + int opri; + + opri = splcam(); + if ((scbp = SLIST_FIRST(&ahc->scb_data->free_scbs))) { + SLIST_REMOVE_HEAD(&ahc->scb_data->free_scbs, links); + } else { + ahcallocscbs(ahc); + scbp = SLIST_FIRST(&ahc->scb_data->free_scbs); + if (scbp != NULL) + SLIST_REMOVE_HEAD(&ahc->scb_data->free_scbs, links); + } + + splx(opri); + + return (scbp); +} + char * ahc_name(struct ahc_softc *ahc) { @@ -518,8 +580,8 @@ ahc_print_scb(struct scb *scb) hscb->SG_count, hscb->SG_pointer); printf(" sg_addr:%lx sg_len:%ld\n", - scb->ahc_dma[0].addr, - scb->ahc_dma[0].len); + scb->sg_list[0].addr, + scb->sg_list[0].len); printf(" cdb:%x %x %x %x %x %x %x %x %x %x %x %x\n", hscb->cmdstore[0], hscb->cmdstore[1], hscb->cmdstore[2], hscb->cmdstore[3], hscb->cmdstore[4], hscb->cmdstore[5], @@ -573,8 +635,9 @@ static struct ahc_syncrate ahc_syncrates[] = { * Allocate a controller structure for a new device and initialize it. */ struct ahc_softc * -ahc_alloc(int unit, u_int32_t iobase, vm_offset_t maddr, ahc_chip chip, - ahc_feature features, ahc_flag flags, struct scb_data *scb_data) +ahc_alloc(int unit, u_int32_t io_base, vm_offset_t maddr, + bus_dma_tag_t parent_dmat, ahc_chip chip, ahc_feature features, + ahc_flag flags, struct scb_data *scb_data) { /* * find unit and check we have that many defined @@ -595,19 +658,12 @@ ahc_alloc(int unit, u_int32_t iobase, vm_offset_t maddr, ahc_chip chip, alloc_size = sizeof(struct ahc_softc); ahc = malloc(alloc_size, M_DEVBUF, M_NOWAIT); if (!ahc) { - printf("ahc%d: cannot malloc!\n", unit); + printf("ahc%d: cannot malloc softc!\n", ahc->unit); return NULL; } bzero(ahc, alloc_size); - if (scb_data == NULL) { - struct full_ahc_softc* full_softc = (struct full_ahc_softc*)ahc; - ahc->scb_data = &full_softc->scb_data_storage; - STAILQ_INIT(&ahc->scb_data->free_scbs); - } else - ahc->scb_data = scb_data; LIST_INIT(&ahc->pending_ccbs); ahc->unit = unit; - /* * XXX This should be done by the bus specific probe stubs with * the bus layer providing the bsh and tag. Unfortunately, @@ -619,17 +675,23 @@ ahc_alloc(int unit, u_int32_t iobase, vm_offset_t maddr, ahc_chip chip, ahc->bsh = (bus_space_handle_t)maddr; } else { ahc->tag = I386_BUS_SPACE_IO; - ahc->bsh = (bus_space_handle_t)iobase; + ahc->bsh = (bus_space_handle_t)io_base; } ahc->chip = chip; ahc->features = features; - ahc->flags = flags; + ahc->flags = flags; + ahc->parent_dmat = parent_dmat; + if (scb_data == NULL) { + struct full_ahc_softc* full_softc = (struct full_ahc_softc*)ahc; + ahc->scb_data = &full_softc->scb_data_storage; + } else + ahc->scb_data = scb_data; + ahc->unpause = (ahc_inb(ahc, HCNTRL) & IRQMS) | INTEN; /* The IRQMS bit is only valid on VL and EISA chips */ if ((ahc->chip & AHC_PCI) != 0) ahc->unpause &= ~IRQMS; ahc->pause = ahc->unpause | PAUSE; - return (ahc); } @@ -637,10 +699,239 @@ void ahc_free(ahc) struct ahc_softc *ahc; { + ahcfiniscbdata(ahc); + switch (ahc->init_level) { + case 3: + bus_dmamap_unload(ahc->shared_data_dmat, + ahc->shared_data_dmamap); + case 2: + bus_dmamem_free(ahc->shared_data_dmat, ahc->qoutfifo, + ahc->shared_data_dmamap); + bus_dmamap_destroy(ahc->shared_data_dmat, + ahc->shared_data_dmamap); + case 1: + bus_dma_tag_destroy(ahc->buffer_dmat); + break; + } + + /* + * XXX We punt on releasing our register space and interrupt. + * This is addressed in -current. + */ + free(ahc, M_DEVBUF); return; } +static int +ahcinitscbdata(struct ahc_softc *ahc) +{ + struct scb_data *scb_data; + int i; + + scb_data = ahc->scb_data; + SLIST_INIT(&scb_data->free_scbs); + SLIST_INIT(&scb_data->sg_maps); + + /* Allocate SCB resources */ + scb_data->scbarray = + (struct scb *)malloc(sizeof(struct scb) * AHC_SCB_MAX, + M_DEVBUF, M_NOWAIT); + if (scb_data->scbarray == NULL) + return (ENOMEM); + bzero(scb_data->scbarray, sizeof(struct scb) * AHC_SCB_MAX); + + /* Determine the number of hardware SCBs and initialize them */ + + scb_data->maxhscbs = ahc_probe_scbs(ahc); + /* SCB 0 heads the free list */ + ahc_outb(ahc, FREE_SCBH, 0); + for (i = 0; i < ahc->scb_data->maxhscbs; i++) { + ahc_outb(ahc, SCBPTR, i); + + /* Clear the control byte. */ + ahc_outb(ahc, SCB_CONTROL, 0); + + /* Set the next pointer */ + ahc_outb(ahc, SCB_NEXT, i+1); + + /* Make the tag number invalid */ + ahc_outb(ahc, SCB_TAG, SCB_LIST_NULL); + } + + /* Make sure that the last SCB terminates the free list */ + ahc_outb(ahc, SCBPTR, i-1); + ahc_outb(ahc, SCB_NEXT, SCB_LIST_NULL); + + /* Ensure we clear the 0 SCB's control byte. */ + ahc_outb(ahc, SCBPTR, 0); + ahc_outb(ahc, SCB_CONTROL, 0); + + scb_data->maxhscbs = i; + + if (ahc->scb_data->maxhscbs == 0) + panic("%s: No SCB space found", ahc_name(ahc)); + + /* + * Create our DMA tags. These tags define the kinds of device + * accessable memory allocations and memory mappings we will + * need to perform during normal operation. + * + * Unless we need to further restrict the allocation, we rely + * on the restrictions of the parent dmat, hence the common + * use of MAXADDR and MAXSIZE. + */ + + /* DMA tag for our hardware scb structures */ + if (bus_dma_tag_create(ahc->parent_dmat, /*alignment*/0, /*boundary*/0, + /*lowaddr*/BUS_SPACE_MAXADDR, + /*highaddr*/BUS_SPACE_MAXADDR, + /*filter*/NULL, /*filterarg*/NULL, + AHC_SCB_MAX * sizeof(struct hardware_scb), + /*nsegments*/1, + /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT, + /*flags*/0, &scb_data->hscb_dmat) != 0) { + goto error_exit; + } + + scb_data->init_level++; + + /* Allocation for our ccbs */ + if (bus_dmamem_alloc(scb_data->hscb_dmat, (void **)&scb_data->hscbs, + BUS_DMA_NOWAIT, &scb_data->hscb_dmamap) != 0) { + goto error_exit; + } + + scb_data->init_level++; + + /* And permanently map them */ + bus_dmamap_load(scb_data->hscb_dmat, scb_data->hscb_dmamap, + scb_data->hscbs, + AHC_SCB_MAX * sizeof(struct hardware_scb), + ahcdmamapcb, &scb_data->hscb_busaddr, /*flags*/0); + + scb_data->init_level++; + + /* DMA tag for our sense buffers */ + if (bus_dma_tag_create(ahc->parent_dmat, /*alignment*/0, /*boundary*/0, + /*lowaddr*/BUS_SPACE_MAXADDR, + /*highaddr*/BUS_SPACE_MAXADDR, + /*filter*/NULL, /*filterarg*/NULL, + AHC_SCB_MAX * sizeof(struct scsi_sense_data), + /*nsegments*/1, + /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT, + /*flags*/0, &scb_data->sense_dmat) != 0) { + goto error_exit; + } + + scb_data->init_level++; + + /* Allocate them */ + if (bus_dmamem_alloc(scb_data->sense_dmat, (void **)&scb_data->sense, + BUS_DMA_NOWAIT, &scb_data->sense_dmamap) != 0) { + goto error_exit; + } + + scb_data->init_level++; + + /* And permanently map them */ + bus_dmamap_load(scb_data->sense_dmat, scb_data->sense_dmamap, + scb_data->sense, + AHC_SCB_MAX * sizeof(struct scsi_sense_data), + ahcdmamapcb, &scb_data->sense_busaddr, /*flags*/0); + + scb_data->init_level++; + + /* DMA tag for our S/G structures. We allocate in page sized chunks */ + if (bus_dma_tag_create(ahc->parent_dmat, /*alignment*/0, /*boundary*/0, + /*lowaddr*/BUS_SPACE_MAXADDR, + /*highaddr*/BUS_SPACE_MAXADDR, + /*filter*/NULL, /*filterarg*/NULL, + PAGE_SIZE, /*nsegments*/1, + /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT, + /*flags*/0, &scb_data->sg_dmat) != 0) { + goto error_exit; + } + + scb_data->init_level++; + + /* Perform initial CCB allocation */ + bzero(scb_data->hscbs, AHC_SCB_MAX * sizeof(struct hardware_scb)); + ahcallocscbs(ahc); + + if (scb_data->numscbs == 0) { + printf("%s: ahc_init_scb_data - " + "Unable to allocate initial scbs\n", + ahc_name(ahc)); + goto error_exit; + } + + /* + * Note that we were successfull + */ + return 0; + +error_exit: + + return ENOMEM; +} + +static void +ahcfiniscbdata(struct ahc_softc *ahc) +{ + struct scb_data *scb_data; + + scb_data = ahc->scb_data; + + switch (scb_data->init_level) { + default: + case 7: + { + struct sg_map_node *sg_map; + + while ((sg_map = SLIST_FIRST(&scb_data->sg_maps))!= NULL) { + SLIST_REMOVE_HEAD(&scb_data->sg_maps, links); + bus_dmamap_unload(scb_data->sg_dmat, + sg_map->sg_dmamap); + bus_dmamem_free(scb_data->sg_dmat, sg_map->sg_vaddr, + sg_map->sg_dmamap); + free(sg_map, M_DEVBUF); + } + bus_dma_tag_destroy(scb_data->sg_dmat); + } + case 6: + bus_dmamap_unload(scb_data->sense_dmat, + scb_data->sense_dmamap); + case 5: + bus_dmamem_free(scb_data->sense_dmat, scb_data->sense, + scb_data->sense_dmamap); + bus_dmamap_destroy(scb_data->sense_dmat, + scb_data->sense_dmamap); + case 4: + bus_dma_tag_destroy(scb_data->sense_dmat); + case 3: + bus_dmamap_unload(scb_data->hscb_dmat, scb_data->hscb_dmamap); + case 2: + bus_dmamem_free(scb_data->hscb_dmat, scb_data->hscbs, + scb_data->hscb_dmamap); + bus_dmamap_destroy(scb_data->hscb_dmat, scb_data->hscb_dmamap); + case 1: + bus_dma_tag_destroy(scb_data->hscb_dmat); + break; + } + if (scb_data->scbarray != NULL) + free(scb_data->scbarray, M_DEVBUF); +} + +static void +ahcdmamapcb(void *arg, bus_dma_segment_t *segs, int nseg, int error) +{ + bus_addr_t *baddr; + + baddr = (bus_addr_t *)arg; + *baddr = segs->ds_addr; +} + int ahc_reset(struct ahc_softc *ahc) { @@ -822,18 +1113,27 @@ ahc_update_target_msg_request(struct ahc_softc *ahc, if (ahc->targ_msg_req != targ_msg_req_orig) { /* Update the message request bit for this target */ - if (!paused) { - pause_sequencer(ahc); - DELAY(1000); - } + if ((ahc->features & AHC_HS_MAILBOX) != 0) { + if (paused) { + ahc_outb(ahc, TARGET_MSG_REQUEST, + ahc->targ_msg_req & 0xFF); + ahc_outb(ahc, TARGET_MSG_REQUEST + 1, + (ahc->targ_msg_req >> 8) & 0xFF); + } else { + ahc_outb(ahc, HS_MAILBOX, + 0x01 << HOST_MAILBOX_SHIFT); + } + } else { + if (!paused) + pause_sequencer(ahc); - ahc_outb(ahc, TARGET_MSG_REQUEST, ahc->targ_msg_req & 0xFF); - ahc_outb(ahc, TARGET_MSG_REQUEST + 1, - (ahc->targ_msg_req >> 8) & 0xFF); + ahc_outb(ahc, TARGET_MSG_REQUEST, + ahc->targ_msg_req & 0xFF); + ahc_outb(ahc, TARGET_MSG_REQUEST + 1, + (ahc->targ_msg_req >> 8) & 0xFF); - if (!paused) { - unpause_sequencer(ahc, /*unpause always*/FALSE); - DELAY(1000); + if (!paused) + unpause_sequencer(ahc, /*unpause always*/FALSE); } } } @@ -1083,11 +1383,13 @@ ahc_attach(struct ahc_softc *ahc) struct cam_path *path; struct cam_path *path2; int count; + int s; count = 0; sim = NULL; sim2 = NULL; + s = splcam(); /* * Attach secondary channel first if the user has * declared it the primary channel. @@ -1103,7 +1405,7 @@ ahc_attach(struct ahc_softc *ahc) /* * Create the device queue for our SIM(s). */ - devq = cam_simq_alloc(ahc->scb_data->maxscbs); + devq = cam_simq_alloc(AHC_SCB_MAX); if (devq == NULL) goto fail; @@ -1111,7 +1413,7 @@ ahc_attach(struct ahc_softc *ahc) * Construct our first channel SIM entry */ sim = cam_sim_alloc(ahc_action, ahc_poll, "ahc", ahc, ahc->unit, - 1, ahc->scb_data->maxscbs, devq); + 1, AHC_SCB_MAX, devq); if (sim == NULL) { cam_simq_free(devq); goto fail; @@ -1143,7 +1445,7 @@ ahc_attach(struct ahc_softc *ahc) if (ahc->features & AHC_TWIN) { sim2 = cam_sim_alloc(ahc_action, ahc_poll, "ahc", ahc, ahc->unit, 1, - ahc->scb_data->maxscbs, devq); + AHC_SCB_MAX, devq); if (sim2 == NULL) { printf("ahc_attach: Unable to attach second " @@ -1179,6 +1481,7 @@ ahc_attach(struct ahc_softc *ahc) xpt_action((union ccb *)&csa); count++; } + fail: if ((ahc->flags & AHC_CHANNEL_B_PRIMARY) != 0) { ahc->sim_b = sim; @@ -1191,6 +1494,7 @@ fail: ahc->sim_b = sim2; ahc->path_b = path2; } + splx(s); return (count); } @@ -1299,8 +1603,9 @@ ahc_intr(void *arg) scb_index = ahc->qoutfifo[ahc->qoutfifonext]; ahc->qoutfifo[ahc->qoutfifonext++] = SCB_LIST_NULL; - scb = ahc->scb_data->scbarray[scb_index]; - if (!scb || !(scb->flags & SCB_ACTIVE)) { + scb = &ahc->scb_data->scbarray[scb_index]; + if (scb_index >= ahc->scb_data->numscbs + || (scb->flags & SCB_ACTIVE) == 0) { printf("%s: WARNING no command for scb %d " "(cmdcmplt)\nQOUTPOS = %d\n", ahc_name(ahc), scb_index, @@ -1787,6 +2092,12 @@ ahc_handle_seqint(struct ahc_softc *ahc, u_int intstat) ahc_outb(ahc, SCSISIGO, ahc_inb(ahc, LASTPHASE) | ATNO); break; } + case UPDATE_TMSG_REQ: + ahc_outb(ahc, TARGET_MSG_REQUEST, ahc->targ_msg_req & 0xFF); + ahc_outb(ahc, TARGET_MSG_REQUEST + 1, + (ahc->targ_msg_req >> 8) & 0xFF); + ahc_outb(ahc, HS_MAILBOX, 0); + break; case SEND_REJECT: { u_int rejbyte = ahc_inb(ahc, ACCUM); @@ -1844,7 +2155,7 @@ ahc_handle_seqint(struct ahc_softc *ahc, u_int intstat) * the in kernel copy directly. */ scb_index = ahc_inb(ahc, SCB_TAG); - scb = ahc->scb_data->scbarray[scb_index]; + scb = &ahc->scb_data->scbarray[scb_index]; hscb = scb->hscb; /* @@ -1853,7 +2164,8 @@ ahc_handle_seqint(struct ahc_softc *ahc, u_int intstat) * this if needed. */ ahc_outb(ahc, RETURN_1, 0); - if (!(scb && (scb->flags & SCB_ACTIVE))) { + if (!(scb_index < ahc->scb_data->numscbs + && (scb->flags & SCB_ACTIVE) != 0)) { printf("%s:%c:%d: ahc_intr - referenced scb " "not valid during seqint 0x%x scb(%d)\n", ahc_name(ahc), devinfo.channel, @@ -1869,10 +2181,10 @@ ahc_handle_seqint(struct ahc_softc *ahc, u_int intstat) * complete. */ scb->flags &= ~SCB_SENSE; - ahc_set_ccb_status(scb->ccb, CAM_AUTOSENSE_FAIL); + ahcsetccbstatus(scb->ccb, CAM_AUTOSENSE_FAIL); break; } - ahc_set_ccb_status(scb->ccb, CAM_SCSI_STATUS_ERROR); + ahcsetccbstatus(scb->ccb, CAM_SCSI_STATUS_ERROR); /* Freeze the queue unit the client sees the error. */ ahc_freeze_devq(ahc, scb->ccb->ccb_h.path); ahc_freeze_ccb(scb->ccb); @@ -1894,12 +2206,13 @@ ahc_handle_seqint(struct ahc_softc *ahc, u_int intstat) #endif if ((csio->ccb_h.flags & CAM_DIS_AUTOSENSE) == 0) { - struct ahc_dma_seg *sg = scb->ahc_dma; - struct scsi_sense *sc = - (struct scsi_sense *)(&hscb->cmdstore); + struct ahc_dma_seg *sg; + struct scsi_sense *sc; struct ahc_initiator_tinfo *tinfo; struct tmode_tstate *tstate; + sg = scb->sg_list; + sc = (struct scsi_sense *)(&hscb->cmdstore); /* * Save off the residual if there is one. */ @@ -1912,24 +2225,18 @@ ahc_handle_seqint(struct ahc_softc *ahc, u_int intstat) printf("Sending Sense\n"); } #endif - /* - * bzero from the sense data before having - * the drive fill it. The SCSI spec mandates - * that any untransfered data should be - * assumed to be zero. - */ - bzero(&csio->sense_data, - sizeof(csio->sense_data)); + sg->addr = ahc->scb_data->sense_busaddr + + (hscb->tag*sizeof(struct scsi_sense_data)); + sg->len = MIN(sizeof(struct scsi_sense_data), + csio->sense_len); + sc->opcode = REQUEST_SENSE; sc->byte2 = SCB_LUN(scb) << 5; sc->unused[0] = 0; sc->unused[1] = 0; - sc->length = csio->sense_len; + sc->length = sg->len; sc->control = 0; - sg->addr = vtophys(&csio->sense_data); - sg->len = csio->sense_len; - /* * Would be nice to preserve DISCENB here, * but due to the way we page SCBs, we can't. @@ -1953,7 +2260,7 @@ ahc_handle_seqint(struct ahc_softc *ahc, u_int intstat) /*paused*/TRUE); hscb->status = 0; hscb->SG_count = 1; - hscb->SG_pointer = scb->ahc_dmaphys; + hscb->SG_pointer = scb->sg_list_phys; hscb->data = sg->addr; hscb->datalen = sg->len; hscb->cmdpointer = hscb->cmdstore_busaddr; @@ -2033,7 +2340,7 @@ ahc_handle_seqint(struct ahc_softc *ahc, u_int intstat) u_int scb_index; scb_index = ahc_inb(ahc, SCB_TAG); - scb = ahc->scb_data->scbarray[scb_index]; + scb = &ahc->scb_data->scbarray[scb_index]; if (bus_phase == P_MESGOUT) ahc_setup_initiator_msgout(ahc, @@ -2073,7 +2380,7 @@ ahc_handle_seqint(struct ahc_softc *ahc, u_int intstat) u_int lastphase = ahc_inb(ahc, LASTPHASE); int i; - scb = ahc->scb_data->scbarray[scbindex]; + scb = &ahc->scb_data->scbarray[scbindex]; xpt_print_path(scb->ccb->ccb_h.path); printf("data overrun detected in %s phase." " Tag == 0x%x.\n", @@ -2087,8 +2394,8 @@ ahc_handle_seqint(struct ahc_softc *ahc, u_int intstat) for (i = 0; i < scb->sg_count - 1; i++) { printf("sg[%d] - Addr 0x%x : Length %d\n", i, - scb->ahc_dma[i].addr, - scb->ahc_dma[i].len); + scb->sg_list[i].addr, + scb->sg_list[i].len); } } /* @@ -2096,7 +2403,7 @@ ahc_handle_seqint(struct ahc_softc *ahc, u_int intstat) * target does a command complete. */ ahc_freeze_devq(ahc, scb->ccb->ccb_h.path); - ahc_set_ccb_status(scb->ccb, CAM_DATA_RUN_ERR); + ahcsetccbstatus(scb->ccb, CAM_DATA_RUN_ERR); ahc_freeze_ccb(scb->ccb); break; } @@ -2180,7 +2487,7 @@ ahc_handle_scsiint(struct ahc_softc *ahc, u_int intstat) scb_index = ahc_inb(ahc, SCB_TAG); if (scb_index < ahc->scb_data->numscbs) { - scb = ahc->scb_data->scbarray[scb_index]; + scb = &ahc->scb_data->scbarray[scb_index]; if ((scb->flags & SCB_ACTIVE) == 0) scb = NULL; } else @@ -2222,8 +2529,8 @@ ahc_handle_scsiint(struct ahc_softc *ahc, u_int intstat) scb->hscb->tag, tag == SCB_LIST_NULL ? "" : "Tag"); if ((scb->flags & SCB_RECOVERY_SCB) != 0) { - ahc_set_ccb_status(scb->ccb, - CAM_REQ_ABORTED); + ahcsetccbstatus(scb->ccb, + CAM_REQ_ABORTED); ahc_done(ahc, scb); } printerror = 0; @@ -2284,7 +2591,7 @@ ahc_handle_scsiint(struct ahc_softc *ahc, u_int intstat) scb_index = ahc_inb(ahc, SCB_TAG); if (scb_index < ahc->scb_data->numscbs) { - scb = ahc->scb_data->scbarray[scb_index]; + scb = &ahc->scb_data->scbarray[scb_index]; if ((scb->flags & SCB_ACTIVE) == 0) scb = NULL; } else @@ -2532,7 +2839,7 @@ ahc_handle_msg_reject(struct ahc_softc *ahc, struct ahc_devinfo *devinfo) int response = 0; scb_index = ahc_inb(ahc, SCB_TAG); - scb = ahc->scb_data->scbarray[scb_index]; + scb = &ahc->scb_data->scbarray[scb_index]; /* Might be necessary */ last_msg = ahc_inb(ahc, LAST_MSG); @@ -3182,7 +3489,7 @@ ahc_handle_ign_wide_residue(struct ahc_softc *ahc, struct ahc_devinfo *devinfo) struct scb *scb; scb_index = ahc_inb(ahc, SCB_TAG); - scb = ahc->scb_data->scbarray[scb_index]; + scb = &ahc->scb_data->scbarray[scb_index]; if ((ahc_inb(ahc, SEQ_FLAGS) & DPHASE) == 0 || (scb->ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_IN) { /* @@ -3228,18 +3535,18 @@ ahc_handle_ign_wide_residue(struct ahc_softc *ahc, struct ahc_devinfo *devinfo) sg_index = scb->sg_count - resid_sgcnt; /* - * scb->ahc_dma starts with the second S/G entry. + * scb->sg_list starts with the second S/G entry. */ if (sg_index-- != 0 - && (scb->ahc_dma[sg_index].len < data_cnt)) { + && (scb->sg_list[sg_index].len < data_cnt)) { u_int sg_addr; data_cnt = 1; - data_addr = scb->ahc_dma[sg_index - 1].addr - + scb->ahc_dma[sg_index - 1].len - 1; + data_addr = scb->sg_list[sg_index - 1].addr + + scb->sg_list[sg_index - 1].len - 1; - sg_addr = scb->ahc_dmaphys - + (sg_index * sizeof(*scb->ahc_dma)); + sg_addr = scb->sg_list_phys + + (sg_index * sizeof(*scb->sg_list)); ahc_outb(ahc, SG_NEXT + 3, sg_addr >> 24); ahc_outb(ahc, SG_NEXT + 2, sg_addr >> 16); ahc_outb(ahc, SG_NEXT + 1, sg_addr >> 8); @@ -3318,8 +3625,8 @@ ahc_done(struct ahc_softc *ahc, struct scb *scb) op = BUS_DMASYNC_POSTREAD; else op = BUS_DMASYNC_POSTWRITE; - bus_dmamap_sync(ahc->dmat, scb->dmamap, op); - bus_dmamap_unload(ahc->dmat, scb->dmamap); + bus_dmamap_sync(ahc->buffer_dmat, scb->dmamap, op); + bus_dmamap_unload(ahc->buffer_dmat, scb->dmamap); } /* @@ -3331,7 +3638,7 @@ ahc_done(struct ahc_softc *ahc, struct scb *scb) if (ccb->ccb_h.func_code == XPT_CONT_TARGET_IO) { ccb->ccb_h.status = CAM_REQ_CMP; - ahc_free_scb(ahc, scb); + ahcfreescb(ahc, scb); xpt_done(ccb); return; } @@ -3368,7 +3675,7 @@ ahc_done(struct ahc_softc *ahc, struct scb *scb) SCB_LUN(scb), scb->hscb->tag, /*status*/0, SEARCH_REMOVE); if (ahc_ccb_status(ccb) == CAM_BDR_SENT) - ahc_set_ccb_status(ccb, CAM_CMD_TIMEOUT); + ahcsetccbstatus(ccb, CAM_CMD_TIMEOUT); xpt_print_path(ccb->ccb_h.path); printf("no longer in timeout, status = %x\n", ccb->ccb_h.status); @@ -3378,11 +3685,24 @@ ahc_done(struct ahc_softc *ahc, struct scb *scb) if (ahc_ccb_status(ccb) == CAM_REQ_INPROG) { ccb->ccb_h.status |= CAM_REQ_CMP; } else if ((scb->flags & SCB_SENSE) != 0) { - /* We performed autosense retrieval */ + /* + * We performed autosense retrieval. + * + * bzero the sense data before having + * the drive fill it. The SCSI spec mandates + * that any untransfered data should be + * assumed to be zero. Complete the 'bounce' + * of sense information through buffers accessible + * via bus-space by copying it into the clients + * csio. + */ + bzero(&ccb->csio.sense_data, sizeof(ccb->csio.sense_data)); + bcopy(&ahc->scb_data->sense[scb->hscb->tag], + &ccb->csio.sense_data, scb->sg_list->len); scb->ccb->ccb_h.status |= CAM_AUTOSNS_VALID; } ccb->ccb_h.status &= ~CAM_SIM_QUEUED; - ahc_free_scb(ahc, scb); + ahcfreescb(ahc, scb); xpt_done(ccb); } @@ -3412,14 +3732,16 @@ ahc_probe_scbs(struct ahc_softc *ahc) { int ahc_init(struct ahc_softc *ahc) { - int max_targ = 15; - int i; - int term; - u_int scsi_conf; - u_int scsiseq_template; - u_int ultraenb; - u_int discenable; - u_int tagenable; + int max_targ = 15; + int i; + int term; + u_int scsi_conf; + u_int scsiseq_template; + u_int ultraenb; + u_int discenable; + u_int tagenable; + size_t driver_data_size; + u_int32_t physaddr; #ifdef AHC_PRINT_SRAM printf("Scratch Ram:"); @@ -3470,6 +3792,85 @@ ahc_init(struct ahc_softc *ahc) ahc->flags &= ~AHC_INITIATORMODE; } + /* DMA tag for mapping buffers into device visible space. */ + if (bus_dma_tag_create(ahc->parent_dmat, /*alignment*/0, /*boundary*/0, + /*lowaddr*/BUS_SPACE_MAXADDR, + /*highaddr*/BUS_SPACE_MAXADDR, + /*filter*/NULL, /*filterarg*/NULL, + /*maxsize*/MAXBSIZE, /*nsegments*/AHC_NSEG, + /*maxsegsz*/AHC_MAXTRANSFER_SIZE, + /*flags*/BUS_DMA_ALLOCNOW, + &ahc->buffer_dmat) != 0) { + return (ENOMEM); + } + + ahc->init_level++; + + /* + * DMA tag for our command fifos and other data in system memory + * the card's sequencer must be able to access. For initiator + * roles, we need to allocate space for the qinfifo, qoutfifo, + * and untagged_scb arrays each of which are composed of 256 + * 1 byte elements. When providing for the target mode role, + * we additionally must provide space for the incoming target + * command fifo. + */ + driver_data_size = 3 * 256 * sizeof(u_int8_t); + if ((ahc->flags & AHC_TARGETMODE) != 0) + driver_data_size += AHC_TMODE_CMDS * sizeof(struct target_cmd); + if (bus_dma_tag_create(ahc->parent_dmat, /*alignment*/0, /*boundary*/0, + /*lowaddr*/BUS_SPACE_MAXADDR, + /*highaddr*/BUS_SPACE_MAXADDR, + /*filter*/NULL, /*filterarg*/NULL, + driver_data_size, + /*nsegments*/1, + /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT, + /*flags*/0, &ahc->shared_data_dmat) != 0) { + return (ENOMEM); + } + + ahc->init_level++; + + /* Allocation of driver data */ + if (bus_dmamem_alloc(ahc->shared_data_dmat, (void **)&ahc->qoutfifo, + BUS_DMA_NOWAIT, &ahc->shared_data_dmamap) != 0) { + return (ENOMEM); + } + + ahc->init_level++; + + /* And permanently map it in */ + bus_dmamap_load(ahc->shared_data_dmat, ahc->shared_data_dmamap, + ahc->qoutfifo, driver_data_size, + ahcdmamapcb, &ahc->shared_data_busaddr, /*flags*/0); + + ahc->init_level++; + + /* Allocate SCB data now that buffer_dmat is initialized) */ + if (ahc->scb_data->maxhscbs == 0) + if (ahcinitscbdata(ahc) != 0) + return (ENOMEM); + + ahc->qinfifo = &ahc->qoutfifo[256]; + ahc->untagged_scbs = &ahc->qinfifo[256]; + /* There are no untagged SCBs active yet. */ + for (i = 0; i < 256; i++) + ahc->untagged_scbs[i] = SCB_LIST_NULL; + + /* All of our queues are empty */ + for (i = 0; i < 256; i++) + ahc->qoutfifo[i] = SCB_LIST_NULL; + + if ((ahc->flags & AHC_TARGETMODE) != 0) { + ahc->targetcmds = (struct target_cmd *)&ahc->untagged_scbs[256]; + + /* All target command blocks start out invalid. */ + for (i = 0; i < AHC_TMODE_CMDS; i++) + ahc->targetcmds[i].cmd_valid = 0; + ahc_outb(ahc, KERNEL_TQINPOS, ahc->tqinfifonext - 1); + ahc_outb(ahc, TQINPOS, 0); + } + /* * Allocate a tstate to house information for our * initiator presence on the bus as well as the user @@ -3501,46 +3902,10 @@ ahc_init(struct ahc_softc *ahc) ahc_outb(ahc, SEQ_FLAGS, 0); - /* Determine the number of SCBs and initialize them */ - - if (ahc->scb_data->maxhscbs == 0) { - ahc->scb_data->maxhscbs = ahc_probe_scbs(ahc); - /* SCB 0 heads the free list */ - ahc_outb(ahc, FREE_SCBH, 0); - for (i = 0; i < ahc->scb_data->maxhscbs; i++) { - ahc_outb(ahc, SCBPTR, i); - - /* Clear the control byte. */ - ahc_outb(ahc, SCB_CONTROL, 0); - - /* Set the next pointer */ - ahc_outb(ahc, SCB_NEXT, i+1); - - /* Make the tag number invalid */ - ahc_outb(ahc, SCB_TAG, SCB_LIST_NULL); - } - - /* Make that the last SCB terminates the free list */ - ahc_outb(ahc, SCBPTR, i-1); - ahc_outb(ahc, SCB_NEXT, SCB_LIST_NULL); - - /* Ensure we clear the 0 SCB's control byte. */ - ahc_outb(ahc, SCBPTR, 0); - ahc_outb(ahc, SCB_CONTROL, 0); - - ahc->scb_data->maxhscbs = i; - } - - if (ahc->scb_data->maxhscbs == 0) - panic("%s: No SCB space found", ahc_name(ahc)); - if (ahc->scb_data->maxhscbs < AHC_SCB_MAX) { ahc->flags |= AHC_PAGESCBS; - ahc->scb_data->maxscbs = AHC_SCB_MAX; - printf("%d/%d SCBs\n", ahc->scb_data->maxhscbs, - ahc->scb_data->maxscbs); + printf("%d/%d SCBs\n", ahc->scb_data->maxhscbs, AHC_SCB_MAX); } else { - ahc->scb_data->maxscbs = ahc->scb_data->maxhscbs; ahc->flags &= ~AHC_PAGESCBS; printf("%d SCBs\n", ahc->scb_data->maxhscbs); } @@ -3702,10 +4067,8 @@ ahc_init(struct ahc_softc *ahc) (ultraenb & mask) ? AHC_SYNCRATE_ULTRA : AHC_SYNCRATE_FAST); - if ((scsirate & SOFS) != 0 - && tinfo->user.period != 0) { + if (tinfo->user.period != 0) tinfo->user.offset = ~0; - } } if ((scsirate & WIDEXFER) != 0 && (ahc->features & AHC_WIDE) != 0) @@ -3716,119 +4079,55 @@ ahc_init(struct ahc_softc *ahc) tstate->tagenable = tagenable; } -#ifdef AHC_DEBUG - if (ahc_debug & AHC_SHOWMISC) - printf("NEEDSDTR == 0x%x\nNEEDWDTR == 0x%x\n" - "DISCENABLE == 0x%x\nULTRAENB == 0x%x\n", - ahc->needsdtr_orig, ahc->needwdtr_orig, - discenable, ultraenb); -#endif /* - * Allocate enough "hardware scbs" to handle - * the maximum number of concurrent transactions - * we can have active. We have to use contigmalloc - * if this array crosses a page boundary since the - * sequencer depends on this array being physically - * contiguous. + * Tell the sequencer where it can find the our arrays in memory. */ - if (ahc->scb_data->hscbs == NULL) { - size_t array_size; + physaddr = ahc->scb_data->hscb_busaddr; + ahc_outb(ahc, HSCB_ADDR, physaddr & 0xFF); + ahc_outb(ahc, HSCB_ADDR + 1, (physaddr >> 8) & 0xFF); + ahc_outb(ahc, HSCB_ADDR + 2, (physaddr >> 16) & 0xFF); + ahc_outb(ahc, HSCB_ADDR + 3, (physaddr >> 24) & 0xFF); - array_size = ahc->scb_data->maxscbs*sizeof(struct hardware_scb); - if (array_size > PAGE_SIZE) { - ahc->scb_data->hscbs = (struct hardware_scb *) - contigmalloc(array_size, M_DEVBUF, - M_NOWAIT, 0ul, 0xffffffff, - PAGE_SIZE, 0x10000); - } else { - ahc->scb_data->hscbs = (struct hardware_scb *) - malloc(array_size, M_DEVBUF, M_NOWAIT); - } - - if (ahc->scb_data->hscbs == NULL) { - printf("%s: unable to allocate hardware SCB array. " - "Failing attach\n", ahc_name(ahc)); - return (-1); - } - /* At least the control byte of each hscb needs to be zeroed */ - bzero(ahc->scb_data->hscbs, array_size); - } - - if ((ahc->flags & AHC_TARGETMODE) != 0) { - size_t array_size; - - array_size = AHC_TMODE_CMDS * sizeof(struct target_cmd); - ahc->targetcmds = contigmalloc(array_size, M_DEVBUF, - M_NOWAIT, 0ul, 0xffffffff, - PAGE_SIZE, 0x10000); - - if (ahc->targetcmds == NULL) { - printf("%s: unable to allocate targetcmd array. " - "Failing attach\n", ahc_name(ahc)); - return (-1); - } + physaddr = ahc->shared_data_busaddr; + ahc_outb(ahc, SCBID_ADDR, physaddr & 0xFF); + ahc_outb(ahc, SCBID_ADDR + 1, (physaddr >> 8) & 0xFF); + ahc_outb(ahc, SCBID_ADDR + 2, (physaddr >> 16) & 0xFF); + ahc_outb(ahc, SCBID_ADDR + 3, (physaddr >> 24) & 0xFF); - /* All target command blocks start out invalid. */ - for (i = 0; i < AHC_TMODE_CMDS; i++) - ahc->targetcmds[i].cmd_valid = 0; - ahc_outb(ahc, KERNEL_TQINPOS, ahc->tqinfifonext - 1); - ahc_outb(ahc, TQINPOS, 0); - } + /* Target mode incomding command fifo */ + physaddr += 3 * 256 * sizeof(u_int8_t); + ahc_outb(ahc, TMODE_CMDADDR, physaddr & 0xFF); + ahc_outb(ahc, TMODE_CMDADDR + 1, (physaddr >> 8) & 0xFF); + ahc_outb(ahc, TMODE_CMDADDR + 2, (physaddr >> 16) & 0xFF); + ahc_outb(ahc, TMODE_CMDADDR + 3, (physaddr >> 24) & 0xFF); /* - * Tell the sequencer where it can find the our arrays in memory. + * Initialize the group code to command length table. + * This overrides the values in TARG_SCSIRATE, so only + * setup the table after we have processed that information. */ - { - u_int32_t physaddr; - - /* Tell the sequencer where it can find the hscb array. */ - physaddr = vtophys(ahc->scb_data->hscbs); - ahc_outb(ahc, HSCB_ADDR, physaddr & 0xFF); - ahc_outb(ahc, HSCB_ADDR + 1, (physaddr >> 8) & 0xFF); - ahc_outb(ahc, HSCB_ADDR + 2, (physaddr >> 16) & 0xFF); - ahc_outb(ahc, HSCB_ADDR + 3, (physaddr >> 24) & 0xFF); - ahc->hscb_busaddr = physaddr; - - physaddr = vtophys(ahc->qoutfifo); - ahc_outb(ahc, SCBID_ADDR, physaddr & 0xFF); - ahc_outb(ahc, SCBID_ADDR + 1, (physaddr >> 8) & 0xFF); - ahc_outb(ahc, SCBID_ADDR + 2, (physaddr >> 16) & 0xFF); - ahc_outb(ahc, SCBID_ADDR + 3, (physaddr >> 24) & 0xFF); - - if ((ahc->flags & AHC_TARGETMODE) != 0) { - physaddr = vtophys(ahc->targetcmds); - ahc_outb(ahc, TMODE_CMDADDR, physaddr & 0xFF); - ahc_outb(ahc, TMODE_CMDADDR + 1, - (physaddr >> 8) & 0xFF); - ahc_outb(ahc, TMODE_CMDADDR + 2, - (physaddr >> 16) & 0xFF); - ahc_outb(ahc, TMODE_CMDADDR + 3, - (physaddr >> 24) & 0xFF); - - ahc_outb(ahc, CMDSIZE_TABLE, 5); - ahc_outb(ahc, CMDSIZE_TABLE + 1, 9); - ahc_outb(ahc, CMDSIZE_TABLE + 2, 9); - ahc_outb(ahc, CMDSIZE_TABLE + 3, 0); - ahc_outb(ahc, CMDSIZE_TABLE + 4, 15); - ahc_outb(ahc, CMDSIZE_TABLE + 5, 11); - ahc_outb(ahc, CMDSIZE_TABLE + 6, 0); - ahc_outb(ahc, CMDSIZE_TABLE + 7, 0); - } + ahc_outb(ahc, CMDSIZE_TABLE, 5); + ahc_outb(ahc, CMDSIZE_TABLE + 1, 9); + ahc_outb(ahc, CMDSIZE_TABLE + 2, 9); + ahc_outb(ahc, CMDSIZE_TABLE + 3, 0); + ahc_outb(ahc, CMDSIZE_TABLE + 4, 15); + ahc_outb(ahc, CMDSIZE_TABLE + 5, 11); + ahc_outb(ahc, CMDSIZE_TABLE + 6, 0); + ahc_outb(ahc, CMDSIZE_TABLE + 7, 0); - /* There are no untagged SCBs active yet. */ - for (i = 0; i < sizeof(ahc->untagged_scbs); i++) { - ahc->untagged_scbs[i] = SCB_LIST_NULL; - } - for (i = 0; i < sizeof(ahc->qoutfifo); i++) { - ahc->qoutfifo[i] = SCB_LIST_NULL; - } - } - - /* Our Q FIFOs are empty. */ + /* Tell the sequencer of our initial queue positions */ ahc_outb(ahc, KERNEL_QINPOS, 0); ahc_outb(ahc, QINPOS, 0); ahc_outb(ahc, QOUTPOS, 0); +#ifdef AHC_DEBUG + if (ahc_debug & AHC_SHOWMISC) + printf("NEEDSDTR == 0x%x\nNEEDWDTR == 0x%x\n" + "DISCENABLE == 0x%x\nULTRAENB == 0x%x\n", + ahc->needsdtr_orig, ahc->needwdtr_orig, + discenable, ultraenb); +#endif + /* Don't have any special messages to send to targets */ ahc_outb(ahc, TARGET_MSG_REQUEST, 0); ahc_outb(ahc, TARGET_MSG_REQUEST + 1, 0); @@ -4029,14 +4328,14 @@ ahc_action(struct cam_sim *sim, union ccb *ccb) /* * get an scb to use. */ - if ((scb = ahc_get_scb(ahc)) == NULL) { + if ((scb = ahcgetscb(ahc)) == NULL) { int s; s = splcam(); ahc->flags |= AHC_RESOURCE_SHORTAGE; splx(s); xpt_freeze_simq(ahc->sim, /*count*/1); - ahc_set_ccb_status(ccb, CAM_REQUEUE_REQ); + ahcsetccbstatus(ccb, CAM_REQUEUE_REQ); xpt_done(ccb); return; } @@ -4444,13 +4743,13 @@ ahc_execute_scb(void *arg, bus_dma_segment_t *dm_segs, int nsegments, end_seg = dm_segs + nsegments; /* Copy the first SG into the data pointer area */ - scb->hscb->SG_pointer = scb->ahc_dmaphys; + scb->hscb->SG_pointer = scb->sg_list_phys; scb->hscb->data = dm_segs->ds_addr; scb->hscb->datalen = dm_segs->ds_len; dm_segs++; /* Copy the remaining segments into our SG list */ - sg = scb->ahc_dma; + sg = scb->sg_list; while (dm_segs < end_seg) { sg->addr = dm_segs->ds_addr; sg->len = dm_segs->ds_len; @@ -4463,7 +4762,7 @@ ahc_execute_scb(void *arg, bus_dma_segment_t *dm_segs, int nsegments, else op = BUS_DMASYNC_PREWRITE; - bus_dmamap_sync(ahc->dmat, scb->dmamap, op); + bus_dmamap_sync(ahc->buffer_dmat, scb->dmamap, op); if (ccb->ccb_h.func_code == XPT_CONT_TARGET_IO) { scb->hscb->cmdpointer |= DPHASE_PENDING; @@ -4486,8 +4785,8 @@ ahc_execute_scb(void *arg, bus_dma_segment_t *dm_segs, int nsegments, */ if (ahc_ccb_status(ccb) != CAM_REQ_INPROG) { if (nsegments != 0) - bus_dmamap_unload(ahc->dmat, scb->dmamap); - ahc_free_scb(ahc, scb); + bus_dmamap_unload(ahc->buffer_dmat, scb->dmamap); + ahcfreescb(ahc, scb); xpt_done(ccb); splx(s); return; @@ -4560,12 +4859,16 @@ ahc_setup_data(struct ahc_softc *ahc, struct ccb_scsiio *csio, hscb->cmdlen); hscb->cmdpointer = hscb->cmdstore_busaddr; - } else - hscb->cmdpointer = - vtophys(csio->cdb_io.cdb_ptr); + } else { + ahcsetccbstatus(scb->ccb, + CAM_REQ_INVALID); + xpt_done(scb->ccb); + ahcfreescb(ahc, scb); + return; + } else hscb->cmdpointer = - (u_int32_t)csio->cdb_io.cdb_ptr; + ((intptr_t)csio->cdb_io.cdb_ptr) & 0xffffffff; } else { /* * CCB CDB Data Storage area is only 16 bytes @@ -4586,7 +4889,7 @@ ahc_setup_data(struct ahc_softc *ahc, struct ccb_scsiio *csio, int error; s = splsoftvm(); - error = bus_dmamap_load(ahc->dmat, + error = bus_dmamap_load(ahc->buffer_dmat, scb->dmamap, csio->data_ptr, csio->dxfer_len, @@ -4653,124 +4956,67 @@ ahc_freeze_devq(struct ahc_softc *ahc, struct cam_path *path) SEARCH_COMPLETE); } -/* - * An scb (and hence an scb entry on the board) is put onto the - * free list. - */ static void -ahc_free_scb(struct ahc_softc *ahc, struct scb *scb) -{ - struct hardware_scb *hscb; - int opri; - - hscb = scb->hscb; - - opri = splcam(); +ahcallocscbs(struct ahc_softc *ahc) +{ + struct scb_data *scb_data; + struct scb *next_scb; + struct sg_map_node *sg_map; + bus_addr_t physaddr; + struct ahc_dma_seg *segs; + int newcount; + int i; - if ((ahc->flags & AHC_RESOURCE_SHORTAGE) != 0 - && (scb->ccb->ccb_h.status & CAM_RELEASE_SIMQ) == 0) { - scb->ccb->ccb_h.status |= CAM_RELEASE_SIMQ; - ahc->flags &= ~AHC_RESOURCE_SHORTAGE; - } + scb_data = ahc->scb_data; + if (scb_data->numscbs >= AHC_SCB_MAX) + /* Can't allocate any more */ + return; - /* Clean up for the next user */ - scb->flags = SCB_FREE; - hscb->control = 0; - hscb->status = 0; + next_scb = &scb_data->scbarray[scb_data->numscbs]; - STAILQ_INSERT_HEAD(&ahc->scb_data->free_scbs, scb, links); - splx(opri); -} + sg_map = malloc(sizeof(*sg_map), M_DEVBUF, M_NOWAIT); -/* - * Get a free scb, either one already assigned to a hardware slot - * on the adapter or one that will require an SCB to be paged out before - * use. If there are none, see if we can allocate a new SCB. Otherwise - * either return an error or sleep. - */ -static struct scb * -ahc_get_scb(struct ahc_softc *ahc) -{ - struct scb *scbp; - int opri; + if (sg_map == NULL) + return; - opri = splcam(); - if ((scbp = STAILQ_FIRST(&ahc->scb_data->free_scbs))) { - STAILQ_REMOVE_HEAD(&ahc->scb_data->free_scbs, links); - } else if (ahc->scb_data->numscbs < ahc->scb_data->maxscbs) { - scbp = ahc_alloc_scb(ahc); - if (scbp == NULL) - printf("%s: Can't malloc SCB\n", ahc_name(ahc)); + /* Allocate S/G space for the next batch of SCBS */ + if (bus_dmamem_alloc(scb_data->sg_dmat, (void **)&sg_map->sg_vaddr, + BUS_DMA_NOWAIT, &sg_map->sg_dmamap) != 0) { + free(sg_map, M_DEVBUF); + return; } - splx(opri); + SLIST_INSERT_HEAD(&scb_data->sg_maps, sg_map, links); - return (scbp); -} + bus_dmamap_load(scb_data->sg_dmat, sg_map->sg_dmamap, sg_map->sg_vaddr, + PAGE_SIZE, ahcdmamapcb, &sg_map->sg_physaddr, + /*flags*/0); + segs = sg_map->sg_vaddr; + physaddr = sg_map->sg_physaddr; -static struct scb * -ahc_alloc_scb(struct ahc_softc *ahc) -{ - static struct ahc_dma_seg *next_sg_array = NULL; - static int sg_arrays_free = 0; - struct scb *newscb; - int error; + newcount = (PAGE_SIZE / (AHC_NSEG * sizeof(struct ahc_dma_seg))); + for (i = 0; scb_data->numscbs < AHC_SCB_MAX && i < newcount; i++) { + int error; - newscb = (struct scb *) malloc(sizeof(struct scb), M_DEVBUF, M_NOWAIT); - if (newscb != NULL) { - bzero(newscb, sizeof(struct scb)); - error = bus_dmamap_create(ahc->dmat, /*flags*/0, - &newscb->dmamap); + next_scb->sg_list = segs; + next_scb->sg_list_phys = physaddr; + next_scb->flags = SCB_FREE; + error = bus_dmamap_create(ahc->buffer_dmat, /*flags*/0, + &next_scb->dmamap); if (error != 0) - printf("%s: Unable to allocate SCB dmamap - error %d\n", - ahc_name(ahc), error); - - if (error == 0 && next_sg_array == NULL) { - size_t alloc_size = sizeof(struct ahc_dma_seg) - * AHC_NSEG; - sg_arrays_free = PAGE_SIZE / alloc_size; - alloc_size *= sg_arrays_free; - if (alloc_size == 0) - panic("%s: SG list doesn't fit in a page", - ahc_name(ahc)); - next_sg_array = (struct ahc_dma_seg *) - malloc(alloc_size, M_DEVBUF, M_NOWAIT); - } - if (error == 0 && next_sg_array != NULL) { - struct hardware_scb *hscb; - - newscb->ahc_dma = next_sg_array; - newscb->ahc_dmaphys = vtophys(next_sg_array); - sg_arrays_free--; - if (sg_arrays_free == 0) - next_sg_array = NULL; - else - next_sg_array = &next_sg_array[AHC_NSEG]; - hscb = &ahc->scb_data->hscbs[ahc->scb_data->numscbs]; - newscb->hscb = hscb; - hscb->control = 0; - hscb->status = 0; - hscb->tag = ahc->scb_data->numscbs; - hscb->residual_data_count[2] = 0; - hscb->residual_data_count[1] = 0; - hscb->residual_data_count[0] = 0; - hscb->residual_SG_count = 0; - hscb->cmdstore_busaddr = - ahc_hscb_busaddr(ahc, hscb->tag) - + offsetof(struct hardware_scb, cmdstore); - /* - * Place in the scbarray - * Never is removed. - */ - ahc->scb_data->scbarray[hscb->tag] = newscb; - ahc->scb_data->numscbs++; - } else { - free(newscb, M_DEVBUF); - newscb = NULL; - } + break; + next_scb->hscb = &scb_data->hscbs[scb_data->numscbs]; + next_scb->hscb->tag = ahc->scb_data->numscbs; + next_scb->hscb->cmdstore_busaddr = + ahc_hscb_busaddr(ahc, next_scb->hscb->tag) + + offsetof(struct hardware_scb, cmdstore); + SLIST_INSERT_HEAD(&ahc->scb_data->free_scbs, next_scb, links); + segs += AHC_NSEG; + physaddr += (AHC_NSEG * sizeof(struct ahc_dma_seg)); + next_scb++; + ahc->scb_data->numscbs++; } - return newscb; } static void @@ -5092,7 +5338,7 @@ ahc_timeout(void *arg) * Do a full bus reset. */ bus_reset: - ahc_set_ccb_status(scb->ccb, CAM_CMD_TIMEOUT); + ahcsetccbstatus(scb->ccb, CAM_CMD_TIMEOUT); found = ahc_reset_channel(ahc, channel, /*Initiate Reset*/TRUE); printf("%s: Issued Channel %c Bus Reset. " "%d SCBs aborted\n", ahc_name(ahc), channel, found); @@ -5133,7 +5379,7 @@ bus_reset: * and wait for it's timeout to expire before * taking additional action. */ - active_scb = ahc->scb_data->scbarray[active_scb_index]; + active_scb = &ahc->scb_data->scbarray[active_scb_index]; if (active_scb->hscb->tcl != scb->hscb->tcl && (scb->flags & SCB_OTHERTCL_TIMEOUT) == 0) { struct ccb_hdr *ccbh; @@ -5160,7 +5406,7 @@ bus_reset: * and properly record the error condition. */ ahc_freeze_devq(ahc, scb->ccb->ccb_h.path); - ahc_set_ccb_status(scb->ccb, CAM_CMD_TIMEOUT); + ahcsetccbstatus(scb->ccb, CAM_CMD_TIMEOUT); ahc_freeze_ccb(scb->ccb); ahc_done(ahc, scb); @@ -5283,7 +5529,7 @@ ahc_search_qinfifo(struct ahc_softc *ahc, int target, char channel, ahc->qinfifonext = qinpos; while (qinpos != qintail) { - scbp = ahc->scb_data->scbarray[ahc->qinfifo[qinpos]]; + scbp = &ahc->scb_data->scbarray[ahc->qinfifo[qinpos]]; if (ahc_match_scb(scbp, target, channel, lun, tag)) { /* * We found an scb that needs to be removed. @@ -5291,7 +5537,7 @@ ahc_search_qinfifo(struct ahc_softc *ahc, int target, char channel, switch (action) { case SEARCH_COMPLETE: if (ahc_ccb_status(scbp->ccb) == CAM_REQ_INPROG) - ahc_set_ccb_status(scbp->ccb, status); + ahcsetccbstatus(scbp->ccb, status); ahc_freeze_ccb(scbp->ccb); ahc_done(ahc, scbp); break; @@ -5441,7 +5687,7 @@ ahc_abort_scbs(struct ahc_softc *ahc, int target, char channel, "SCB index == %d, yet numscbs == %d.", scb_index, ahc->scb_data->numscbs); } - scbp = ahc->scb_data->scbarray[scb_index]; + scbp = &ahc->scb_data->scbarray[scb_index]; if (ahc_match_scb(scbp, target, channel, lun, tag)) { next = ahc_abort_wscb(ahc, next, prev); @@ -5468,7 +5714,7 @@ ahc_abort_scbs(struct ahc_softc *ahc, int target, char channel, ahc_outb(ahc, SCBPTR, i); scbid = ahc_inb(ahc, SCB_TAG); if (scbid < ahc->scb_data->numscbs) { - scbp = ahc->scb_data->scbarray[scbid]; + scbp = &ahc->scb_data->scbarray[scbid]; if (ahc_match_scb(scbp, target, channel, lun, tag)) { ahc_add_curscb_to_free_list(ahc); } @@ -5491,7 +5737,7 @@ ahc_abort_scbs(struct ahc_softc *ahc, int target, char channel, ccb_h = ccb_h->sim_links.le.le_next; if (ahc_match_scb(scbp, target, channel, lun, tag)) { if (ahc_ccb_status(scbp->ccb) == CAM_REQ_INPROG) - ahc_set_ccb_status(scbp->ccb, status); + ahcsetccbstatus(scbp->ccb, status); ahc_freeze_ccb(scbp->ccb); ahc_done(ahc, scbp); found++; @@ -5529,7 +5775,7 @@ ahc_search_disc_list(struct ahc_softc *ahc, int target, char channel, "SCB index == %d, yet numscbs == %d.", scb_index, ahc->scb_data->numscbs); } - scbp = ahc->scb_data->scbarray[scb_index]; + scbp = &ahc->scb_data->scbarray[scb_index]; if (ahc_match_scb(scbp, target, channel, lun, tag)) { next = ahc_rem_scb_from_disc_list(ahc, prev, next); @@ -5816,7 +6062,7 @@ ahc_calc_residual(struct scb *scb) sg = scb->sg_count - resid_sgs - 1/*first SG*/; while (resid_sgs > 0) { - resid += scb->ahc_dma[sg].len; + resid += scb->sg_list[sg].len; sg++; resid_sgs--; } @@ -5915,7 +6161,7 @@ ahc_update_pending_syncrates(struct ahc_softc *ahc) u_int our_id, remote_id; u_int control; - pending_scb = ahc->scb_data->scbarray[scb_tag]; + pending_scb = &ahc->scb_data->scbarray[scb_tag]; if (pending_scb->flags == SCB_FREE) continue; pending_hscb = pending_scb->hscb; diff --git a/sys/dev/aic7xxx/aic7xxx.h b/sys/dev/aic7xxx/aic7xxx.h index cf3037aaa07d..4cc4c8802bf1 100644 --- a/sys/dev/aic7xxx/aic7xxx.h +++ b/sys/dev/aic7xxx/aic7xxx.h @@ -3,7 +3,7 @@ * SCSI controllers. This is used to implement product specific * probe and attach routines. * - * Copyright (c) 1994, 1995, 1996, 1997, 1998 Justin T. Gibbs. + * Copyright (c) 1994, 1995, 1996, 1997, 1998, 1999 Justin T. Gibbs. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -34,7 +34,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: aic7xxx.h,v 1.5 1999/01/14 06:14:15 gibbs Exp $ + * $Id: aic7xxx.h,v 1.5.2.1 1999/03/07 00:40:47 gibbs Exp $ */ #ifndef _AIC7XXX_H_ @@ -45,20 +45,29 @@ #include <pci/pcivar.h> /* for pcici_t */ +#ifndef MAX +#define MAX(a,b) (((a) > (b)) ? (a) : (b)) +#endif + +#ifndef MIN +#define MIN(a,b) (((a) < (b)) ? (a) : (b)) +#endif + +/* + * The maximum transfer per S/G segment. + */ #define AHC_MAXTRANSFER_SIZE 0x00ffffff /* limited by 24bit counter */ -#define AHC_NSEG 32 /* The number of dma segments supported. - * AHC_NSEG can be maxed out at 256 entries, - * but the kernel will never need to transfer - * such a large (1MB) request. To reduce the - * driver's memory consumption, we reduce the - * max to 32. 16 would work if all transfers - * are paged alined since the kernel will only - * generate at most a 64k transfer, but to - * handle non-page aligned transfers, you need - * 17, so we round to the next power of two - * to make allocating SG space easy and - * efficient. - */ + +/* + * The number of dma segments supported. The current implementation limits + * us to 255 S/G entries (this may change to be unlimited at some point). + * To reduce the driver's memory consumption, we further limit the number + * supported to be sufficient to handle the largest mapping supported by + * the kernel, MAXPHYS. Assuming the transfer is as fragmented as possible + * and unaligned, this turns out to be the number of paged sized transfers + * in MAXPHYS plus an extra element to handle any unaligned residual. + */ +#define AHC_NSEG (MIN(btoc(MAXPHYS) + 1, 255)) #define AHC_SCB_MAX 255 /* * Up to 255 SCBs on some types of aic7xxx @@ -75,9 +84,7 @@ * wrap point of an 8bit counter. */ -#if defined(__FreeBSD__) extern u_long ahc_unit; -#endif struct ahc_dma_seg { u_int32_t addr; @@ -112,16 +119,17 @@ typedef enum { AHC_SG_PRELOAD = 0x0080, /* Can perform auto-SG preload */ AHC_SPIOCAP = 0x0100, /* Has a Serial Port I/O Cap Register */ AHC_MULTI_TID = 0x0200, /* Has bitmask of TIDs for select-in */ + AHC_HS_MAILBOX = 0x0400, /* Has HS_MAILBOX register */ AHC_AIC7770_FE = AHC_FENONE, AHC_AIC7850_FE = AHC_FENONE|AHC_SPIOCAP, AHC_AIC7860_FE = AHC_ULTRA|AHC_SPIOCAP, AHC_AIC7870_FE = AHC_FENONE, AHC_AIC7880_FE = AHC_ULTRA, AHC_AIC7890_FE = AHC_MORE_SRAM|AHC_CMD_CHAN|AHC_ULTRA2|AHC_QUEUE_REGS - |AHC_SG_PRELOAD|AHC_MULTI_TID, + |AHC_SG_PRELOAD|AHC_MULTI_TID|AHC_HS_MAILBOX, AHC_AIC7895_FE = AHC_MORE_SRAM|AHC_CMD_CHAN|AHC_ULTRA, AHC_AIC7896_FE = AHC_MORE_SRAM|AHC_CMD_CHAN|AHC_ULTRA2|AHC_QUEUE_REGS - |AHC_SG_PRELOAD|AHC_MULTI_TID, + |AHC_SG_PRELOAD|AHC_MULTI_TID|AHC_HS_MAILBOX, } ahc_feature; typedef enum { @@ -138,7 +146,6 @@ typedef enum { * SRAM, we use the default target * settings. */ - AHC_INDIRECT_PAGING = 0x008, AHC_SHARED_SRAM = 0x010, AHC_LARGE_SEEPROM = 0x020,/* Uses C56_66 not C46 */ AHC_RESET_BUS_A = 0x040, @@ -228,28 +235,13 @@ struct hardware_scb { struct scb { struct hardware_scb *hscb; - STAILQ_ENTRY(scb) links; /* for chaining */ + SLIST_ENTRY(scb) links; /* for chaining */ union ccb *ccb; /* the ccb for this cmd */ - scb_flag flags; - bus_dmamap_t dmamap; - struct ahc_dma_seg *ahc_dma;/* Pointer to SG segments */ - u_int32_t ahc_dmaphys;/* Phsical address of SG list */ - u_int sg_count;/* How full ahc_dma_seg is */ -}; - -struct scb_data { - struct hardware_scb *hscbs; /* Array of hardware SCBs */ - struct scb *scbarray[AHC_SCB_MAX]; /* Array of kernel SCBs */ - STAILQ_HEAD(, scb) free_scbs; /* - * Pool of SCBs ready to be assigned - * commands to execute. - */ - u_int8_t numscbs; - u_int8_t maxhscbs; /* Number of SCBs on the card */ - u_int8_t maxscbs; /* - * Max SCBs we allocate total including - * any that will force us to page SCBs - */ + scb_flag flags; + bus_dmamap_t dmamap; + struct ahc_dma_seg *sg_list; + bus_addr_t sg_list_phys; + u_int sg_count;/* How full ahc_dma_seg is */ }; /* @@ -402,10 +394,45 @@ typedef enum { MSG_TYPE_TARGET_MSGIN = 0x04 } ahc_msg_type; +struct sg_map_node { + bus_dmamap_t sg_dmamap; + bus_addr_t sg_physaddr; + struct ahc_dma_seg* sg_vaddr; + SLIST_ENTRY(sg_map_node) links; +}; + +struct scb_data { + struct hardware_scb *hscbs; /* Array of hardware SCBs */ + struct scb *scbarray; /* Array of kernel SCBs */ + SLIST_HEAD(, scb) free_scbs; /* + * Pool of SCBs ready to be assigned + * commands to execute. + */ + struct scsi_sense_data *sense; /* Per SCB sense data */ + + /* + * "Bus" addresses of our data structures. + */ + bus_dma_tag_t hscb_dmat; /* dmat for our hardware SCB array */ + bus_dmamap_t hscb_dmamap; + bus_addr_t hscb_busaddr; + bus_dma_tag_t sense_dmat; + bus_dmamap_t sense_dmamap; + bus_addr_t sense_busaddr; + bus_dma_tag_t sg_dmat; /* dmat for our sg segments */ + SLIST_HEAD(, sg_map_node) sg_maps; + u_int8_t numscbs; + u_int8_t maxhscbs; /* Number of SCBs on the card */ + u_int8_t init_level; /* + * How far we've initialized + * this structure. + */ +}; + struct ahc_softc { bus_space_tag_t tag; bus_space_handle_t bsh; - bus_dma_tag_t dmat; + bus_dma_tag_t buffer_dmat; /* dmat for buffer I/O */ struct scb_data *scb_data; /* @@ -447,14 +474,14 @@ struct ahc_softc { /* Command Queues */ u_int8_t qoutfifonext; u_int8_t qinfifonext; - u_int8_t qoutfifo[256]; - u_int8_t qinfifo[256]; + u_int8_t *qoutfifo; + u_int8_t *qinfifo; /* * 256 byte array storing the SCBID of outstanding * untagged SCBs indexed by TCL. */ - u_int8_t untagged_scbs[256]; + u_int8_t *untagged_scbs; /* * Hooks into the XPT. @@ -501,13 +528,16 @@ struct ahc_softc { u_int msgout_index; /* Current index in msgout */ u_int msgin_index; /* Current index in msgin */ + bus_dma_tag_t parent_dmat; + bus_dma_tag_t shared_data_dmat; + bus_dmamap_t shared_data_dmamap; + bus_addr_t shared_data_busaddr; + /* Number of enabled target mode device on this card */ u_int enabled_luns; - /* - * "Bus" addresses of our data structures. - */ - u_int32_t hscb_busaddr; + /* Initialization level of this data structure */ + u_int init_level; }; struct full_ahc_softc { @@ -530,10 +560,11 @@ extern int ahc_debug; /* Initialized in i386/scsi/aic7xxx.c */ char *ahc_name(struct ahc_softc *ahc); -struct ahc_softc *ahc_alloc(int unit, u_int32_t io_base, - vm_offset_t maddr, ahc_chip chip, - ahc_feature features, ahc_flag flags, - struct scb_data *scb_data); +struct ahc_softc* + ahc_alloc(int unit, u_int32_t io_base, vm_offset_t maddr, + bus_dma_tag_t parent_dmat, ahc_chip chip, + ahc_feature features, ahc_flag flags, + struct scb_data *scb_data); int ahc_reset(struct ahc_softc *ahc); void ahc_free(struct ahc_softc *); int ahc_probe_scbs(struct ahc_softc *); diff --git a/sys/dev/aic7xxx/aic7xxx.reg b/sys/dev/aic7xxx/aic7xxx.reg index 1edd241456e1..1922b15a39d6 100644 --- a/sys/dev/aic7xxx/aic7xxx.reg +++ b/sys/dev/aic7xxx/aic7xxx.reg @@ -32,7 +32,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: aic7xxx.reg,v 1.12.2.1 1999/03/07 00:40:47 gibbs Exp $ + * $Id: aic7xxx.reg,v 1.12.2.2 1999/03/08 22:44:36 gibbs Exp $ */ /* @@ -669,6 +669,16 @@ register DSPCISTATUS { mask DFTHRSH_100 0xc0 } +/* aic7890/91/96/97 only */ +register HS_MAILBOX { + address 0x086 + mask HOST_MAILBOX 0xF0 + mask SEQ_MAILBOX 0x0F +} + +const HOST_MAILBOX_SHIFT 4 +const SEQ_MAILBOX_SHIFT 0 + /* * Host Control (p. 3-47) R/W * Overall host control of the device. @@ -727,6 +737,7 @@ register INTSTAT { mask NO_IDENT 0x20|SEQINT /* no IDENTIFY after reconnect*/ mask NO_MATCH 0x30|SEQINT /* no cmd match for reconnect */ mask ABORT_REQUESTED 0x50|SEQINT /* Reconect of aborted SCB */ + mask UPDATE_TMSG_REQ 0x60|SEQINT /* Update TMSG_REQ values */ mask BAD_STATUS 0x70|SEQINT /* Bad status from target */ mask RESIDUAL 0x80|SEQINT /* Residual byte count != 0 */ mask TRACE_POINT 0x90|SEQINT diff --git a/sys/dev/aic7xxx/aic7xxx.seq b/sys/dev/aic7xxx/aic7xxx.seq index e0753ea6050a..7dad1d293bb2 100644 --- a/sys/dev/aic7xxx/aic7xxx.seq +++ b/sys/dev/aic7xxx/aic7xxx.seq @@ -32,7 +32,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: aic7xxx.seq,v 1.84.2.2 1999/03/07 00:40:47 gibbs Exp $ + * $Id: aic7xxx.seq,v 1.84.2.3 1999/03/23 07:41:27 gibbs Exp $ */ #include <dev/aic7xxx/aic7xxx.reg> @@ -1025,6 +1025,18 @@ p_mesgout: mov FUNCTION1, SCB_TCL; mov A, FUNCTION1; mov SINDEX, TARGET_MSG_REQUEST[0]; + if ((ahc->features & AHC_HS_MAILBOX) != 0) { + /* + * Work around a pausing bug in at least the aic7890. + * If the host needs to update the TARGET_MSG_REQUEST + * bit field, it will set the HS_MAILBOX to 1. In + * response, we pause with a specific interrupt code + * asking for the mask to be updated before we continue. + * Ugh. + */ + test HS_MAILBOX, 0xF0 jz . + 2; + mvi INTSTAT, UPDATE_TMSG_REQ; + } if ((ahc->features & AHC_TWIN) != 0) { /* Second Channel uses high byte bits */ test SCB_TCL, SELBUSB jz . + 2; diff --git a/sys/dev/aic7xxx/aicasm_symbol.c b/sys/dev/aic7xxx/aicasm_symbol.c index f808e8900d31..0704baa0942e 100644 --- a/sys/dev/aic7xxx/aicasm_symbol.c +++ b/sys/dev/aic7xxx/aicasm_symbol.c @@ -25,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: aicasm_symbol.c,v 1.4 1997/09/27 19:37:30 gibbs Exp $ + * $Id: aicasm_symbol.c,v 1.5 1998/09/15 07:24:17 gibbs Exp $ */ @@ -128,10 +128,10 @@ symtable_close() DBT data; while (symtable->seq(symtable, &key, &data, R_FIRST) == 0) { - symbol_t *cursym; + symbol_t *stored_ptr; - cursym = *(symbol_t **)data.data; - symbol_delete(cursym); + memcpy(&stored_ptr, data.data, sizeof(stored_ptr)); + symbol_delete(stored_ptr); } symtable->close(symtable); } @@ -145,9 +145,10 @@ symbol_t * symtable_get(name) char *name; { - DBT key; - DBT data; - int retval; + symbol_t *stored_ptr; + DBT key; + DBT data; + int retval; key.data = (void *)name; key.size = strlen(name); @@ -176,7 +177,8 @@ symtable_get(name) /* NOTREACHED */ } } - return (*(symbol_t **)data.data); + memcpy(&stored_ptr, data.data, sizeof(stored_ptr)); + return (stored_ptr); } symbol_node_t * @@ -327,7 +329,7 @@ symtable_dump(ofile) while (symtable->seq(symtable, &key, &data, flag) == 0) { symbol_t *cursym; - cursym = *(symbol_t **)data.data; + memcpy(&cursym, data.data, sizeof(cursym)); switch(cursym->type) { case REGISTER: case SCBLOC: diff --git a/sys/dev/pccard/if_xe.c b/sys/dev/pccard/if_xe.c deleted file mode 100644 index 1836f89332d5..000000000000 --- a/sys/dev/pccard/if_xe.c +++ /dev/null @@ -1,2404 +0,0 @@ -/*- - * Copyright (c) 1998, 1999 Scott Mitchell - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Author_Id: if_xe.c,v 1.19 1999/04/15 22:15:53 scott Exp $ - * $Id: if_xe.c,v 1.19 1999/04/15 22:15:53 scott Exp $ - */ - -/* - * Portions of this software were derived from Werner Koch's xirc2ps driver - * for Linux under the terms of the following license (from v1.30 of the - * xirc2ps driver): - * - * Copyright (c) 1997 by Werner Koch (dd9jn) - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, and the entire permission notice in its entirety, - * including the disclaimer of warranties. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote - * products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * FreeBSD device driver for Xircom CreditCard PCMCIA Ethernet adapters. The - * following cards are currently known to work with the driver: - * Xircom CreditCard 10/100 (CE3) - * Xircom CreditCard Ethernet 10/100 + Modem 56 (CEM56) - * Xircom RealPort Ethernet 10/100 - * Xircom RealPort Ethernet 10/100 + Modem 56 (REM56, REM56G) - * Intel EtherExpress Pro/100 PC Card Mobile Adapter 16 (Pro/100 M16A) - * Compaq Netelligent 10/100 PC Card (CPQ-10/100) - * - * Some other cards *should* work, but support for them is either broken or in - * an unknown state at the moment. I'm always interested in hearing from - * people who own any of these cards: - * Xircom CreditCard 10Base-T (PS-CE2-10) - * Xircom CreditCard Ethernet + ModemII (CEM2) - * Xircom CEM28 and CEM33 Ethernet/Modem cards (may be variants of CEM2?) - * - * Thanks to all who assisted with the development and testing of the driver, - * especially: Werner Koch, Duke Kamstra, Duncan Barclay, Jason George, Dru - * Nelson, Mike Kephart, Bill Rainey and Douglas Rand. Apologies if I've left - * out anyone who deserves a mention here. - * - * Special thanks to Ade Lovett for both hosting the mailing list and doing - * the CEM56/REM56 support code; and the FreeBSD UK Users' Group for hosting - * the web pages. - * - * Contact points: - * - * Driver web page: http://ukug.uk.freebsd.org/~scott/xe_drv/ - * - * Mailing list: http://www.lovett.com/lists/freebsd-xircom/ - * or send "subscribe freebsd-xircom" to <majordomo@lovett.com> - * - * Author email: <scott@uk.freebsd.org> - */ - - -#define XE_DEBUG 1 - -#include "xe.h" -#include "card.h" -#include "apm.h" -#include "bpfilter.h" - -#if NXE > 0 - -#if NCARD > 0 - -#include <sys/param.h> -#include <sys/cdefs.h> -#include <sys/conf.h> -#include <sys/errno.h> -#include <sys/kernel.h> -#include <sys/malloc.h> -#include <sys/mbuf.h> -#include <sys/select.h> -#include <sys/socket.h> -#include <sys/sockio.h> -#include <sys/systm.h> -#include <sys/uio.h> - -#include <net/ethernet.h> -#include <net/if.h> -#include <net/if_arp.h> -#include <net/if_dl.h> -#include <net/if_media.h> -#include <net/if_mib.h> -#if NBPFILTER > 0 -#include <net/bpf.h> -#endif /* NBPFILTER > 0 */ - -#include <i386/isa/isa.h> -#include <i386/isa/isa_device.h> -#include <dev/pccard/if_xereg.h> -#include <machine/clock.h> -#if NAPM > 0 -#include <machine/apm_bios.h> -#endif /* NAPM > 0 */ - -#include <pccard/cardinfo.h> -#include <pccard/cis.h> -#include <pccard/driver.h> -#include <pccard/slot.h> - - - -/* - * One of these structures per allocated device - */ -struct xe_softc { - struct arpcom arpcom; - struct ifmedia ifmedia; - struct callout_handle chand; - struct ifmib_iso_8802_3 mibdata; - struct isa_device *dev; - struct pccard_devinfo *crd; - struct ifnet *ifp; - struct ifmedia *ifm; - char *card_type; /* Card model name */ - char *vendor; /* Card manufacturer */ - int unit; /* Unit number, from dev->id_unit */ - int srev; /* Silicon revision */ - int tx_queued; /* Packets currently waiting to transmit */ - int tx_ptr; /* Last value of PTR reg on card */ - int tx_collisions; /* Collisions since last successful send */ - int tx_timeouts; /* Count of transmit timeouts */ - int autoneg_status; /* Autonegotiation progress state */ - int media; /* Private media word */ - u_char modem; /* 1 = Multifunction card with modem */ - u_char ce3; /* 1 = CE3 class (100Mbit) adapter */ - u_char cem56; /* 1 = CEM56 class (CE3 + 56Kbps modem) adapter */ - u_char phy_ok; /* 1 = MII-compliant PHY found and initialised */ - u_char gone; /* 1 = Card bailed out */ -#if NAPM > 0 - struct apmhook suspend_hook; - struct apmhook resume_hook; -#endif /* NAPM > 0 */ -}; - -static struct xe_softc *sca[MAXSLOT]; -static int iob[MAXSLOT]; /* XXX - very gross */ - - -/* - * MII command structure - */ -struct xe_mii_frame { - u_int8_t mii_stdelim; - u_int8_t mii_opcode; - u_int8_t mii_phyaddr; - u_int8_t mii_regaddr; - u_int8_t mii_turnaround; - u_int16_t mii_data; -}; - -/* - * For accessing card registers - */ -#define XE_INB(r) inb(scp->dev->id_iobase+(r)) -#define XE_INW(r) inw(scp->dev->id_iobase+(r)) -#define XE_OUTB(r, b) outb(scp->dev->id_iobase+(r), (b)) -#define XE_OUTW(r, w) outw(scp->dev->id_iobase+(r), (w)) -#define XE_SELECT_PAGE(p) XE_OUTB(XE_PSR, (p)) - -/* - * Horrid stuff for accessing CIS tuples - */ -#define CARD_MAJOR 50 -#define CISTPL_BUFSIZE 512 -#define CISTPL_TYPE(tpl) tpl[0] -#define CISTPL_LEN(tpl) tpl[2] -#define CISTPL_DATA(tpl,pos) tpl[4 + ((pos)<<1)] - -/* - * Media autonegotiation progress constants - */ -#define XE_AUTONEG_NONE 0 /* No autonegotiation in progress */ -#define XE_AUTONEG_WAITING 1 /* Waiting for transmitter to go idle */ -#define XE_AUTONEG_STARTED 2 /* Waiting for autonegotiation to complete */ -#define XE_AUTONEG_100TX 3 /* Trying to force 100baseTX link */ -#define XE_AUTONEG_FAIL 4 /* Autonegotiation failed */ - - -/* - * Prototypes start here - */ -static int xe_probe (struct isa_device *dev); -static int xe_card_init (struct pccard_devinfo *devi); -static int xe_attach (struct isa_device *dev); -static void xe_init (void *xscp); -static void xe_start (struct ifnet *ifp); -static int xe_ioctl (struct ifnet *ifp, u_long command, caddr_t data); -static int xe_card_intr (struct pccard_devinfo *devi); -static void xe_watchdog (struct ifnet *ifp); -static int xe_media_change (struct ifnet *ifp); -static void xe_media_status (struct ifnet *ifp, struct ifmediareq *mrp); -static timeout_t xe_setmedia; -static void xe_hard_reset (struct xe_softc *scp); -static void xe_soft_reset (struct xe_softc *scp); -static void xe_stop (struct xe_softc *scp); -static void xe_enable_intr (struct xe_softc *scp); -static void xe_disable_intr (struct xe_softc *scp); -static void xe_setmulti (struct xe_softc *scp); -static void xe_setaddrs (struct xe_softc *scp); -static int xe_pio_write_packet (struct xe_softc *scp, struct mbuf *mbp); -static void xe_card_unload (struct pccard_devinfo *devi); - -/* - * MII functions - */ -static void xe_mii_sync (struct xe_softc *scp); -static int xe_mii_init (struct xe_softc *scp); -static void xe_mii_send (struct xe_softc *scp, u_int32_t bits, int cnt); -static int xe_mii_readreg (struct xe_softc *scp, struct xe_mii_frame *frame); -static int xe_mii_writereg (struct xe_softc *scp, struct xe_mii_frame *frame); -static u_int16_t xe_phy_readreg (struct xe_softc *scp, u_int16_t reg); -static void xe_phy_writereg (struct xe_softc *scp, u_int16_t reg, u_int16_t data); - -/* - * Debug functions - */ -#ifdef XE_DEBUG -#define XE_REG_DUMP(scp) xe_reg_dump((scp)) -#define XE_MII_DUMP(scp) xe_mii_dump((scp)) -static void xe_reg_dump (struct xe_softc *scp); -static void xe_mii_dump (struct xe_softc *scp); -#else -#define XE_REG_DUMP(scp) -#define XE_MII_DUMP(scp) -#endif - -#if NAPM > 0 -/* - * APM hook functions - */ -static int xe_suspend (void *xunit); -static int xe_resume (void *xunit); -#endif /* NAPM > 0 */ - - -/* - * PCMCIA driver hooks - */ -#ifdef PCCARD_MODULE -PCCARD_MODULE(xe, xe_card_init, xe_card_unload, xe_card_intr, 0, net_imask); -#else -static struct pccard_device xe_info = { /* For pre 3.1-STABLE code */ - "xe", - xe_card_init, - xe_card_unload, - xe_card_intr, - 0, - &net_imask -}; -DATA_SET(pccarddrv_set, xe_info); -#endif /* PCCARD_MODULE */ - - -/* - * ISA driver hooks. I'd like to do without these but the kernel config stuff - * seems to require them. - */ -struct isa_driver xedriver = { - xe_probe, - xe_attach, - "xe" -}; - - - -/* - * ISA probe routine. - * All of the supported devices are PCMCIA cards. I have no idea if it's even - * possible to successfully probe/attach these at boot time (pccardd normally - * does a lot of setup work) so I don't even bother trying. - */ -static int -xe_probe (struct isa_device *dev) { -#ifdef XE_DEBUG - printf("xe%d: probe, iobase = %#x\n", dev->id_unit, dev->id_iobase); -#endif - bzero(sca, MAXSLOT * sizeof(sca[0])); - iob[dev->id_unit] = dev->id_iobase; - return 0; -} - - -/* - * Two routines to read from/write to the attribute memory - * the write portion is used only for fixing up the RealPort cards, - * the reader portion was needed for debugging info, and duplicated some - * code in xe_card_init(), so it appears here instead with suitable - * modifications to xe_card_init() - * -aDe Lovett - */ -static int -xe_memwrite(struct pccard_devinfo *devi, off_t offset, u_char byte) -{ - struct iovec iov; - struct uio uios; - - iov.iov_base = &byte; - iov.iov_len = sizeof(byte); - - uios.uio_iov = &iov; - uios.uio_iovcnt = 1; - uios.uio_offset = offset; - uios.uio_resid = sizeof(byte); - uios.uio_segflg = UIO_SYSSPACE; - uios.uio_rw = UIO_WRITE; - uios.uio_procp = 0; - - return cdevsw[CARD_MAJOR]->d_write(makedev(CARD_MAJOR, devi->slt->slotnum), &uios, 0); -} - - -static int -xe_memread(struct pccard_devinfo *devi, off_t offset, u_char *buf, int size) -{ - struct iovec iov; - struct uio uios; - - iov.iov_base = buf; - iov.iov_len = size; - - uios.uio_iov = &iov; - uios.uio_iovcnt = 1; - uios.uio_offset = offset; - uios.uio_resid = size; - uios.uio_segflg = UIO_SYSSPACE; - uios.uio_rw = UIO_READ; - uios.uio_procp = 0; - - return cdevsw[CARD_MAJOR]->d_read(makedev(CARD_MAJOR, devi->slt->slotnum), &uios, 0); -} - - -/* - * Hacking for RealPort cards - */ -static int -xe_cem56fix(struct xe_softc *scp) -{ - struct pccard_devinfo *devi; - struct slot *slt; - struct slot_ctrl *ctrl; - int ioport, fail; - - /* initialise a few variables */ - devi = scp->crd; - slt = devi->slt; - ctrl = slt->ctrl; - - /* allocate a new I/O slot for the ethernet */ - /* XXX: ctrl->mapio() always appears to return 0 (success), so - * this may cause problems if another device is listening - * on 0x300 already - */ - slt->io[1].window = 1; - slt->io[1].flags = IODF_WS|IODF_16BIT|IODF_ZEROWS|IODF_ACTIVE; - slt->io[1].size = 0x10; - if (iob[scp->unit] == -1) { - for (ioport = 0x300; ioport < 0x400; ioport += 0x10) { - slt->io[1].start = ioport; - if ((fail = ctrl->mapio( slt, 1 )) == 0) - break; - } - } - else { - ioport = iob[scp->unit]; - slt->io[1].start = ioport; - fail = ctrl->mapio(slt, 1); - } - - /* did we find one? */ - if (fail) { - printf( "xe%d: xe_cem56fix: no free address space\n", scp->unit ); - return -1; - } - - - /* munge the id_iobase entry for use by the rest of the driver */ -#ifdef XE_DEBUG - printf( "xe%d: using 0x%x for RealPort ethernet\n", scp->unit, ioport ); -#endif - scp->dev->id_iobase = ioport; - scp->dev->id_alive = 0x10; - - /* magic to set up the ethernet */ - xe_memwrite( devi, 0x800, 0x47 ); - xe_memwrite( devi, 0x80a, ioport & 0xff ); - xe_memwrite( devi, 0x80c, (ioport >> 8) & 0xff ); - - xe_memwrite( devi, 0x820, 0x01 ); - xe_memwrite( devi, 0x822, 0x0c ); - xe_memwrite( devi, 0x824, 0x00 ); - xe_memwrite( devi, 0x826, 0x00 ); - xe_memwrite( devi, 0x828, 0x00 ); - - /* success! */ - return 0; -} - - -/* - * PCMCIA probe routine. - * Probe and identify the device. Called by the slot manager when the card is - * inserted or the machine wakes up from suspend mode. Assmes that the slot - * structure has been initialised already. - */ -static int -xe_card_init(struct pccard_devinfo *devi) -{ - struct xe_softc *scp; - struct isa_device *dev; - u_char buf[CISTPL_BUFSIZE]; - u_char ver_str[CISTPL_BUFSIZE>>1]; - off_t offs; - int unit, success, rc, i; - - unit = devi->isahd.id_unit; - scp = sca[unit]; - dev = &devi->isahd; - success = 0; - -#ifdef XE_DEBUG - printf("xe: Probing for unit %d\n", unit); -#endif - - /* Check that unit number is OK */ - if (unit > MAXSLOT) { - printf("xe: bad unit (%d)\n", unit); - return (ENODEV); - } - - /* Don't attach an active device */ - if (scp && !scp->gone) { - printf("xe: unit already attached (%d)\n", unit); - return (EBUSY); - } - - /* Allocate per-instance storage */ - if (!scp) { - if ((scp = malloc(sizeof(*scp), M_DEVBUF, M_NOWAIT)) == NULL) { - printf("xe%d: failed to allocage driver storage\n", unit); - return (ENOMEM); - } - bzero(scp, sizeof(*scp)); - } - - /* Re-attach an existing device */ - if (scp->gone) { - scp->gone = 0; - return 0; - } - - /* Grep through CIS looking for relevant tuples */ - offs = 0; - do { - u_int16_t vendor; - u_int8_t rev, media, prod; - - /* - * Read tuples one at a time into buf. Sucks, but it only happens once. - * XXX - If the stuff we need isn't in attribute memory, or (worse yet) - * XXX - attribute memory isn't mapped, we're FUBAR. Maybe need to do an - * XXX - ioctl on the card device and follow links? - * XXX - Not really the driver's problem, PCCARD should handle all this! - */ - if ((rc = xe_memread( devi, offs, buf, CISTPL_BUFSIZE )) == 0) { - - switch (CISTPL_TYPE(buf)) { - - case 0x15: /* Grab version string (needed to ID some weird CE2's) */ -#ifdef XE_DEBUG - printf("xe%d: Got version string (0x15)\n", unit); -#endif - for (i = 0; i < CISTPL_LEN(buf); ver_str[i] = CISTPL_DATA(buf, i++)); - ver_str[i] = '\0'; - ver_str[(CISTPL_BUFSIZE>>1) - 1] = CISTPL_LEN(buf); - success++; - break; - - case 0x20: /* Figure out what type of card we have */ -#ifdef XE_DEBUG - printf("xe%d: Got card ID (0x20)\n", unit); -#endif - vendor = CISTPL_DATA(buf, 0) + (CISTPL_DATA(buf, 1) << 8); - rev = CISTPL_DATA(buf, 2); - media = CISTPL_DATA(buf, 3); - prod = CISTPL_DATA(buf, 4); - - switch (vendor) { /* Get vendor ID */ - case 0x0105: - scp->vendor = "Xircom"; break; - case 0x0138: - case 0x0183: - scp->vendor = "Compaq"; break; - case 0x0089: - scp->vendor = "Intel"; break; - default: - scp->vendor = "Unknown"; - } - - if (!((prod & 0x40) && (media & 0x01))) { -#ifdef XE_DEBUG - printf("xe%d: Not a PCMCIA Ethernet card!\n", unit); -#endif - rc = ENODEV; /* Not a PCMCIA Ethernet device */ - } - else { - if (media & 0x10) { /* Ethernet/modem cards */ -#ifdef XE_DEBUG - printf("xe%d: Card is Ethernet/modem combo\n", unit); -#endif - scp->modem = 1; - switch (prod & 0x0f) { - case 1: - scp->card_type = "CEM"; break; - case 2: - scp->card_type = "CEM2"; break; - case 3: - scp->card_type = "CEM3"; break; - case 4: - scp->card_type = "CEM33"; break; - case 5: - scp->ce3 = 1; - scp->card_type = "CEM56M"; break; - case 6: - case 7: /* Some kind of RealPort card */ - scp->ce3 = 1; - scp->cem56 = 1; - scp->card_type = "CEM56"; break; - default: - rc = ENODEV; - } - } - else { /* Ethernet-only cards */ -#ifdef XE_DEBUG - printf("xe%d: Card is Ethernet only\n", unit); -#endif - switch (prod & 0x0f) { - case 1: - scp->card_type = "CE"; break; - case 2: - scp->card_type = "CE2"; break; - case 3: - scp->ce3 = 1; - scp->card_type = "CE3"; break; - default: - rc = ENODEV; - } - } - } - success++; - break; - - case 0x22: /* Get MAC address */ -#ifdef XE_DEBUG - printf("xe%d: Got MAC address (0x22)\n", unit); -#endif - if ((CISTPL_LEN(buf) == 8) && - (CISTPL_DATA(buf, 0) == 0x04) && - (CISTPL_DATA(buf, 1) == ETHER_ADDR_LEN)) { - for (i = 0; i < ETHER_ADDR_LEN; scp->arpcom.ac_enaddr[i] = CISTPL_DATA(buf, i+2), i++); - } - success++; - break; - default: - } - } - - /* Skip to next tuple */ - offs += ((CISTPL_LEN(buf) + 2) << 1); - - } while ((CISTPL_TYPE(buf) != 0xff) && (CISTPL_LEN(buf) != 0xff) && (rc == 0)); - - - /* Die now if something went wrong above */ - if ((rc != 0) || (success < 3)) { - free(scp, M_DEVBUF); - return rc; - } - - /* Check for certain strange CE2's that look like CE's */ - if (strcmp(scp->card_type, "CE") == 0) { - u_char *str = ver_str; -#ifdef XE_DEBUG - printf("xe%d: Checking for weird CE2 string\n", unit); -#endif - str += strlen(str) + 1; /* Skip forward to 3rd version string */ - str += strlen(str) + 1; - str += strlen(str) + 1; - for (i = 0; i < strlen(str) - 2; i++) { - if (bcmp(&str[i], "CE2", 3) ==0) { /* Look for "CE2" string */ - scp->card_type = "CE2"; - } - } - } - - /* Reject unsupported cards */ - if (strcmp(scp->card_type, "CE") == 0 || strcmp(scp->card_type, "CEM") == 0) { - printf("xe%d: Sorry, your %s card is not supported :(\n", unit, scp->card_type); - free(scp, M_DEVBUF); - return ENODEV; - } - - /* Fill in some private data */ - sca[unit] = scp; - scp->dev = &devi->isahd; - scp->crd = devi; - scp->ifp = &scp->arpcom.ac_if; - scp->ifm = &scp->ifmedia; - scp->unit = unit; - scp->autoneg_status = 0; - - /* Hack RealPorts into submission */ - if (scp->cem56 && xe_cem56fix(scp) < 0) { - printf( "xe%d: Unable to fix your RealPort\n", unit ); - sca[unit] = 0; - free(scp, M_DEVBUF); - return ENODEV; - } - - /* Attempt to attach the device */ - if (!xe_attach(scp->dev)) { - sca[unit] = 0; - free(scp, M_DEVBUF); - return ENXIO; - } - -#if NAPM > 0 - /* Establish APM hooks once device attached */ - scp->suspend_hook.ah_name = "xe_suspend"; - scp->suspend_hook.ah_fun = xe_suspend; - scp->suspend_hook.ah_arg = (void *)unit; - scp->suspend_hook.ah_order = APM_MIN_ORDER; - apm_hook_establish(APM_HOOK_SUSPEND, &scp->suspend_hook); - scp->resume_hook.ah_name = "xe_resume"; - scp->resume_hook.ah_fun = xe_resume; - scp->resume_hook.ah_arg = (void *)unit; - scp->resume_hook.ah_order = APM_MIN_ORDER; - apm_hook_establish(APM_HOOK_RESUME, &scp->resume_hook); -#endif /* NAPM > 0 */ - - /* Success */ - return 0; -} - - -/* - * Attach a device (called when xe_card_init succeeds). Assume that the probe - * routine has set up the softc structure correctly and that we can trust the - * unit number. - */ -static int -xe_attach (struct isa_device *dev) { - struct xe_softc *scp = sca[dev->id_unit]; - int i; - -#ifdef XE_DEBUG - printf("xe%d: attach\n", scp->unit); -#endif - - /* Initialise the ifnet structure */ - if (!scp->ifp->if_name) { - scp->ifp->if_softc = scp; - scp->ifp->if_name = "xe"; - scp->ifp->if_unit = scp->unit; - scp->ifp->if_timer = 0; - scp->ifp->if_flags = (IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST); - scp->ifp->if_linkmib = &scp->mibdata; - scp->ifp->if_linkmiblen = sizeof scp->mibdata; - scp->ifp->if_output = ether_output; - scp->ifp->if_start = xe_start; - scp->ifp->if_ioctl = xe_ioctl; - scp->ifp->if_watchdog = xe_watchdog; - scp->ifp->if_init = xe_init; - scp->ifp->if_snd.ifq_maxlen = IFQ_MAXLEN; - } - - /* Initialise the ifmedia structure */ - ifmedia_init(scp->ifm, 0, xe_media_change, xe_media_status); - callout_handle_init(&scp->chand); - - /* - * Fill in supported media types. Some cards _do_ support full duplex - * operation, but this driver doesn't, yet. Therefore we leave those modes - * out of the list. We support some form of autoselection in all cases. - */ - if (scp->ce3) { - ifmedia_add(scp->ifm, IFM_ETHER|IFM_100_TX, 0, NULL); - ifmedia_add(scp->ifm, IFM_ETHER|IFM_10_T, 0, NULL); - } - else { - ifmedia_add(scp->ifm, IFM_ETHER|IFM_10_T, 0, NULL); - ifmedia_add(scp->ifm, IFM_ETHER|IFM_10_2, 0, NULL); - } - ifmedia_add(scp->ifm, IFM_ETHER|IFM_AUTO, 0, NULL); - - /* Default is to autoselect best supported media type */ - ifmedia_set(scp->ifm, IFM_ETHER|IFM_AUTO); - - /* Print some useful information */ - printf("\nxe%d: %s %s%s%s\n", - scp->unit, - scp->vendor, - scp->card_type, - scp->ce3 ? ", 100Mbps capable" : "", - scp->cem56 ? ", with modem" : ""); - printf("xe%d: Ethernet address %02x", scp->unit, scp->arpcom.ac_enaddr[0]); - for (i = 1; i < ETHER_ADDR_LEN; i++) { - printf(":%02x", scp->arpcom.ac_enaddr[i]); - } - printf("\n"); - - /* Attach the interface */ - if_attach(scp->ifp); - ether_ifattach(scp->ifp); - -#if NBPFILTER > 0 - /* If BPF is in the kernel, call the attach for it */ -#ifdef XE_DEBUG - printf("xe%d: BPF listener attached\n", scp->unit); -#endif - bpfattach(scp->ifp, DLT_EN10MB, sizeof(struct ether_header)); -#endif - - /* Done */ - return 1; -} - - -/* - * Initialize device. Completes the reset procedure on the card and starts - * output. If there's an autonegotiation in progress we DON'T do anything; - * the media selection code will call us again when it's done. - */ -static void -xe_init(void *xscp) { - struct xe_softc *scp = xscp; - int s; - -#ifdef XE_DEBUG - printf("xe%d: init\n", scp->unit); -#endif - - if (scp->gone) return; - - if (TAILQ_EMPTY(&scp->ifp->if_addrhead)) return; - - /* Reset transmitter flags */ - scp->tx_queued = 0; - scp->tx_ptr = 0; - scp->tx_collisions = 0; - scp->ifp->if_timer = 0; - - s = splimp(); - - XE_SELECT_PAGE(0x42); - XE_OUTB(XE_SWC0, 0x20); /* Disable source insertion (WTF is that?) */ - - /* - * Set the 'local memory dividing line' -- splits the 32K card memory into - * 8K for transmit buffers and 24K for receive. This is done automatically - * on newer revision cards. - */ - if (scp->srev != 1) { - XE_SELECT_PAGE(2); - XE_OUTW(XE_RBS, 0x2000); - } - - /* Set up multicast addresses */ - xe_setmulti(scp); - - /* Fix the data offset register -- reset leaves it off-by-one */ - XE_SELECT_PAGE(0); - XE_OUTW(XE_DOR, 0x2000); - - /* - * Set MAC interrupt masks and clear status regs. The bit names are direct - * from the Linux code; I have no idea what most of them do. - */ - XE_SELECT_PAGE(0x40); /* Bit 7..0 */ - XE_OUTB(XE_RXM0, 0xff); /* ROK, RAB, rsv, RO, CRC, AE, PTL, MP */ - XE_OUTB(XE_TXM0, 0xff); /* TOK, TAB, SQE, LL, TU, JAB, EXC, CRS */ - XE_OUTB(XE_TXM1, 0xb0); /* rsv, rsv, PTD, EXT, rsv, rsv, rsv, rsv */ - XE_OUTB(XE_RXS0, 0x00); /* ROK, RAB, REN, RO, CRC, AE, PTL, MP */ - XE_OUTB(XE_TXS0, 0x00); /* TOK, TAB, SQE, LL, TU, JAB, EXC, CRS */ - XE_OUTB(XE_TXS1, 0x00); /* TEN, rsv, PTD, EXT, retry_counter:4 */ - - /* - * Check for an in-progress autonegotiation. If one is active, just set - * IFF_RUNNING and return. The media selection code will call us again when - * it's done. - */ - if (scp->autoneg_status) { - scp->ifp->if_flags |= IFF_RUNNING; - } - else { - /* Enable receiver, put MAC online */ - XE_SELECT_PAGE(0x40); - XE_OUTB(XE_OCR, XE_OCR_RX_ENABLE|XE_OCR_ONLINE); - - /* Set up IMR, enable interrupts */ - xe_enable_intr(scp); - - /* Attempt to start output */ - scp->ifp->if_flags |= IFF_RUNNING; - scp->ifp->if_flags &= ~IFF_OACTIVE; - xe_start(scp->ifp); - } - - (void)splx(s); -} - - -/* - * Start output on interface. We make two assumptions here: - * 1) that the current priority is set to splimp _before_ this code - * is called *and* is returned to the appropriate priority after - * return - * 2) that the IFF_OACTIVE flag is checked before this code is called - * (i.e. that the output part of the interface is idle) - */ -static void -xe_start(struct ifnet *ifp) { - struct xe_softc *scp = ifp->if_softc; - struct mbuf *mbp; - - if (scp->gone) return; - - /* - * Loop while there are packets to be sent, and space to send them. - */ - while (1) { - IF_DEQUEUE(&ifp->if_snd, mbp); /* Suck a packet off the send queue */ - - if (mbp == NULL) { - /* - * We are using the !OACTIVE flag to indicate to the outside world that - * we can accept an additional packet rather than that the transmitter - * is _actually_ active. Indeed, the transmitter may be active, but if - * we haven't filled all the buffers with data then we still want to - * accept more. - */ - ifp->if_flags &= ~IFF_OACTIVE; - return; - } - - if (xe_pio_write_packet(scp, mbp) != 0) { - IF_PREPEND(&ifp->if_snd, mbp); /* Push the packet back onto the queue */ - ifp->if_flags |= IFF_OACTIVE; - return; - } - -#if NBPFILTER > 0 - /* Tap off here if there is a bpf listener */ - if (ifp->if_bpf) { -#if XE_DEBUG > 1 - printf("xe%d: sending output packet to BPF\n", scp->unit); -#endif - bpf_mtap(ifp, mbp); - } -#endif /* NBPFILTER > 0 */ - - ifp->if_timer = 5; /* In case we don't hear from the card again */ - scp->tx_queued++; - - m_freem(mbp); - } -} - - -/* - * Process an ioctl request. Adapted from the ed driver. - */ -static int -xe_ioctl (register struct ifnet *ifp, u_long command, caddr_t data) { - struct xe_softc *scp; - int s, error; - - scp = ifp->if_softc; - error = 0; - - if (scp->gone) { - return ENXIO; - } - - s = splimp(); - - switch (command) { - - case SIOCSIFADDR: - case SIOCGIFADDR: - case SIOCSIFMTU: - error = ether_ioctl(ifp, command, data); - break; - - case SIOCSIFFLAGS: - /* - * If the interface is marked up and stopped, then start it. If it is - * marked down and running, then stop it. - */ - if (ifp->if_flags & IFF_UP) { - if (!(ifp->if_flags & IFF_RUNNING)) { - xe_hard_reset(scp); - xe_setmedia(scp); - xe_init(scp); - } - } - else { - if (ifp->if_flags & IFF_RUNNING) - xe_stop(scp); - } - - case SIOCADDMULTI: - case SIOCDELMULTI: - /* - * Multicast list has (maybe) changed; set the hardware filter - * accordingly. This also serves to deal with promiscuous mode if we have - * a BPF listener active. - */ - xe_setmulti(scp); - error = 0; - break; - - case SIOCSIFMEDIA: - case SIOCGIFMEDIA: - /* - * Someone wants to get/set media options. - */ - error = ifmedia_ioctl(ifp, (struct ifreq *)data, &scp->ifmedia, command); - break; - - default: - error = EINVAL; - } - - (void)splx(s); - - return error; -} - - -/* - * Card interrupt handler: should return true if the interrupt was for us, in - * case we are sharing our IRQ line with other devices (this will probably be - * the case for multifunction cards). - * - * This function is probably more complicated than it needs to be, as it - * attempts to deal with the case where multiple packets get sent between - * interrupts. This is especially annoying when working out the collision - * stats. Not sure whether this case ever really happens or not (maybe on a - * slow/heavily loaded machine?) so it's probably best to leave this like it - * is. - * - * Note that the crappy PIO used to get packets on and off the card means that - * you will spend a lot of time in this routine -- I can get my P150 to spend - * 90% of its time servicing interrupts if I really hammer the network. Could - * fix this, but then you'd start dropping/losing packets. The moral of this - * story? If you want good network performance _and_ some cycles left over to - * get your work done, don't buy a Xircom card. Or convince them to tell me - * how to do memory-mapped I/O :) - */ -static int -xe_card_intr(struct pccard_devinfo *devi) { - struct xe_softc *scp; - struct ifnet *ifp; - int unit, result; - u_int16_t rx_bytes, rxs, txs; - u_int8_t psr, isr, esr, rsr; - - unit = devi->isahd.id_unit; - scp = sca[unit]; - ifp = &scp->arpcom.ac_if; - rx_bytes = 0; /* Bytes received on this interrupt */ - result = 0; /* Set true if the interrupt is for us */ - - if (scp->gone) - return 0; - - if (scp->ce3) { - XE_OUTB(XE_CR, 0); /* Disable interrupts */ - } - - psr = XE_INB(XE_PSR); /* Stash the current register page */ - - /* - * Read ISR to see what caused this interrupt. Note that this clears the - * ISR on CE2 type cards. - */ - if ((isr = XE_INB(XE_ISR)) && isr != 0xff) { - - result = 1; /* This device did generate an int */ - esr = XE_INB(XE_ESR); /* Read the other status registers */ - XE_SELECT_PAGE(0x40); - rxs = XE_INB(XE_RXS0); - XE_OUTB(XE_RXS0, ~rxs & 0xff); - txs = XE_INB(XE_TXS0); - txs |= XE_INB(XE_TXS1) << 8; - XE_OUTB(XE_TXS0, 0); - XE_OUTB(XE_TXS1, 0); - XE_SELECT_PAGE(0); - -#if XE_DEBUG > 3 - printf("xe%d: ISR=%#2.2x ESR=%#2.2x RXS=%#2.2x TXS=%#4.4x\n", unit, isr, esr, rxs, txs); -#endif - - /* - * Handle transmit interrupts - */ - if (isr & XE_ISR_TX_PACKET) { - u_int8_t new_ptr, sent; - - if ((new_ptr = XE_INB(XE_PTR)) < scp->tx_ptr) /* Update packet count */ - sent = (0xff - scp->tx_ptr) + new_ptr; /* PTR rolled over */ - else - sent = new_ptr - scp->tx_ptr; - - if (sent > 0) { /* Packets sent since last interrupt */ - scp->tx_ptr = new_ptr; - scp->tx_queued -= sent; - ifp->if_opackets += sent; - ifp->if_collisions += scp->tx_collisions; - - /* - * Collision stats are a PITA. If multiples frames have been sent, we - * distribute any outstanding collision count equally amongst them. - * However, if we're missing interrupts we're quite likely to also - * miss some collisions; thus the total count will be off anyway. - * Likewise, if we miss a frame dropped due to excessive collisions - * any outstanding collisions count will be held against the next - * frame to be successfully sent. Hopefully it averages out in the - * end! - * XXX - This will screw up if tx_collisions/sent > 14. FIX IT! - */ - switch (scp->tx_collisions) { - case 0: - break; - case 1: - scp->mibdata.dot3StatsSingleCollisionFrames++; - scp->mibdata.dot3StatsCollFrequencies[0]++; - break; - default: - if (sent == 1) { - scp->mibdata.dot3StatsMultipleCollisionFrames++; - scp->mibdata.dot3StatsCollFrequencies[scp->tx_collisions-1]++; - } - else { /* Distribute across multiple frames */ - scp->mibdata.dot3StatsMultipleCollisionFrames += sent; - scp->mibdata. - dot3StatsCollFrequencies[scp->tx_collisions/sent] += sent - scp->tx_collisions%sent; - scp->mibdata. - dot3StatsCollFrequencies[scp->tx_collisions/sent + 1] += scp->tx_collisions%sent; - } - } - scp->tx_collisions = 0; - } - ifp->if_timer = 0; - ifp->if_flags &= ~IFF_OACTIVE; - } - if (txs & 0x0002) { /* Excessive collisions (packet dropped) */ - ifp->if_collisions += 16; - ifp->if_oerrors++; - scp->tx_collisions = 0; - scp->mibdata.dot3StatsExcessiveCollisions++; - scp->mibdata.dot3StatsMultipleCollisionFrames++; - scp->mibdata.dot3StatsCollFrequencies[15]++; - XE_OUTB(XE_CR, XE_CR_RESTART_TX); - } - if (txs & 0x0040) /* Transmit aborted -- probably collisions */ - scp->tx_collisions++; - - - /* - * Handle receive interrupts - */ - while ((esr = XE_INB(XE_ESR)) & XE_ESR_FULL_PKT_RX) { - - if ((rsr = XE_INB(XE_RSR)) & XE_RSR_RX_OK) { - struct ether_header *ehp; - struct mbuf *mbp; - u_int16_t len; - - len = XE_INW(XE_RBC); - - if (len == 0) - continue; - -#if 0 - /* - * Limit the amount of time we spend in this loop, dropping packets if - * necessary. The Linux code does this with considerably more - * finesse, adjusting the threshold dynamically. - */ - if ((rx_bytes += len) > 22000) { - ifp->if_iqdrops++; - scp->mibData.dot3StatsMissedFrames++; - XE_OUTW(XE_DOR, 0x8000); - continue; - } -#endif - - if (len & 0x01) - len++; - - MGETHDR(mbp, M_DONTWAIT, MT_DATA); /* Allocate a header mbuf */ - if (mbp != NULL) { - mbp->m_pkthdr.rcvif = ifp; - mbp->m_pkthdr.len = mbp->m_len = len; - - /* - * If the mbuf header isn't big enough for the packet, attach an - * mbuf cluster to hold it. The +2 is to allow for the nasty little - * alignment hack below. - */ - if (len + 2 > MHLEN) { - MCLGET(mbp, M_DONTWAIT); - if ((mbp->m_flags & M_EXT) == 0) { - m_freem(mbp); - mbp = NULL; - } - } - } - - if (mbp != NULL) { - /* - * The Ethernet header is 14 bytes long; thus the actual packet data - * won't be 32-bit aligned when it's dumped into the mbuf. We - * offset everything by 2 bytes to fix this. Apparently the - * alignment is important for NFS, damn its eyes. - */ - mbp->m_data += 2; - ehp = mtod(mbp, struct ether_header *); - - /* - * Now get the packet, including the Ethernet header and trailer (?) - * We use programmed I/O, because we don't know how to do shared - * memory with these cards. So yes, it's real slow, and heavy on - * the interrupts (CPU on my P150 maxed out at ~950KBps incoming). - */ - if (scp->srev == 0) { /* Workaround a bug in old cards */ - u_short rhs; - - XE_SELECT_PAGE(5); - rhs = XE_INW(XE_RHS); - XE_SELECT_PAGE(0); - - rhs += 3; /* Skip control info */ - - if (rhs >= 0x8000) - rhs = 0; - - if (rhs + len > 0x8000) { - int i; - - /* - * XXX - This i-- seems very wrong, but it's what the Linux guys - * XXX - do. Need someone with an old CE2 to test this for me. - * XXX - 99/3/28: Changed the first i-- to an i++, maybe that'll - * XXX - fix it? It seems as though the previous version would - * XXX - have caused an infinite loop (what, another one?). - */ - for (i = 0; i < len; i++, rhs++) { - ((char *)ehp)[i] = XE_INB(XE_EDP); - if (rhs == 0x8000) { - rhs = 0; - i--; - } - } - } - else - insw(scp->dev->id_iobase+XE_EDP, ehp, len >> 1); - } - else - insw(scp->dev->id_iobase+XE_EDP, ehp, len >> 1); - -#if NBPFILTER > 0 - /* - * Check if there's a BPF listener on this interface. If so, hand - * off the raw packet to bpf. - */ - if (ifp->if_bpf) { -#if XE_DEBUG > 1 - printf("xe%d: passing input packet to BPF\n", scp->unit); -#endif - bpf_mtap(ifp, mbp); - - /* - * Note that the interface cannot be in promiscuous mode if there - * are no BPF listeners. And if we are in promiscuous mode, we - * have to check if this packet is really ours. - */ - if ((ifp->if_flags & IFF_PROMISC) && - bcmp(ehp->ether_dhost, scp->arpcom.ac_enaddr, sizeof(ehp->ether_dhost)) != 0 && - (rsr & XE_RSR_PHYS_PKT)) { - m_freem(mbp); - mbp = NULL; - } - } -#endif /* NBPFILTER > 0 */ - - if (mbp != NULL) { - mbp->m_pkthdr.len = mbp->m_len = len - ETHER_HDR_LEN; - mbp->m_data += ETHER_HDR_LEN; /* Strip off Ethernet header */ - ether_input(ifp, ehp, mbp); /* Send the packet on its way */ - ifp->if_ipackets++; /* Success! */ - } - XE_OUTW(XE_DOR, 0x8000); /* skip_rx_packet command */ - } - } - else if (rsr & XE_RSR_LONG_PKT) { /* Packet length >1518 bytes */ - scp->mibdata.dot3StatsFrameTooLongs++; - ifp->if_ierrors++; - } - else if (rsr & XE_RSR_CRC_ERR) { /* Bad checksum on packet */ - scp->mibdata.dot3StatsFCSErrors++; - ifp->if_ierrors++; - } - else if (rsr & XE_RSR_ALIGN_ERR) { /* Packet alignment error */ - scp->mibdata.dot3StatsAlignmentErrors++; - ifp->if_ierrors++; - } - } - if (rxs & 0x10) { /* Receiver overrun */ - scp->mibdata.dot3StatsInternalMacReceiveErrors++; - ifp->if_ierrors++; - XE_OUTB(XE_CR, XE_CR_CLEAR_OVERRUN); - } - } - - XE_SELECT_PAGE(psr); /* Restore saved page */ - XE_OUTB(XE_CR, XE_CR_ENABLE_INTR); /* Re-enable interrupts */ - - /* XXX - Could force an int here, instead of dropping packets? */ - /* XXX - XE_OUTB(XE_CR, XE_CR_ENABLE_INTR|XE_CE_FORCE_INTR); */ - - return result; -} - - -/* - * Device timeout/watchdog routine. Called automatically if we queue a packet - * for transmission but don't get an interrupt within a specified timeout - * (usually 5 seconds). When this happens we assume the worst and reset the - * card. - */ -static void -xe_watchdog(struct ifnet *ifp) { - struct xe_softc *scp = ifp->if_softc; - - if (scp->gone) return; - - printf("xe%d: watchdog timeout; resetting card\n", scp->unit); - scp->tx_timeouts++; - ifp->if_oerrors += scp->tx_queued; - xe_stop(scp); - xe_hard_reset(scp); - xe_setmedia(scp); - xe_init(scp); -} - - -/* - * Change media selection. - */ -static int -xe_media_change(struct ifnet *ifp) { - struct xe_softc *scp = ifp->if_softc; - -#ifdef XE_DEBUG - printf("xe%d: media_change\n", ifp->if_unit); -#endif - - if (IFM_TYPE(scp->ifm->ifm_media) != IFM_ETHER) - return(EINVAL); - - /* - * Some card/media combos aren't always possible -- filter those out here. - */ - if ((IFM_SUBTYPE(scp->ifm->ifm_media) == IFM_AUTO || - IFM_SUBTYPE(scp->ifm->ifm_media) == IFM_100_TX) && !scp->phy_ok) - return (EINVAL); - - xe_setmedia(scp); - - return 0; -} - - -/* - * Return current media selection. - */ -static void -xe_media_status(struct ifnet *ifp, struct ifmediareq *mrp) { - -#ifdef XE_DEBUG - printf("xe%d: media_status\n", ifp->if_unit); -#endif - - mrp->ifm_active = ((struct xe_softc *)ifp->if_softc)->media; - - return; -} - - -/* - * Select active media. - */ -static void xe_setmedia(void *xscp) { - struct xe_softc *scp = xscp; - u_int16_t bmcr, bmsr, anar, lpar; - -#ifdef XE_DEBUG - printf("xe%d: setmedia\n", scp->unit); -#endif - - /* Cancel any pending timeout */ - untimeout(xe_setmedia, scp, scp->chand); - xe_disable_intr(scp); - - /* Select media */ - scp->media = IFM_ETHER; - switch (IFM_SUBTYPE(scp->ifm->ifm_media)) { - - case IFM_AUTO: /* Autoselect media */ - scp->media = IFM_ETHER|IFM_AUTO; - - /* - * Autoselection is really awful. It goes something like this: - * - * Wait until the transmitter goes idle (2sec timeout). - * Reset card - * IF a 100Mbit PHY exists - * Start NWAY autonegotiation (3.5sec timeout) - * IF that succeeds - * Select 100baseTX or 10baseT, whichever was detected - * ELSE - * Reset card - * IF a 100Mbit PHY exists - * Try to force a 100baseTX link (3sec timeout) - * IF that succeeds - * Select 100baseTX - * ELSE - * Disable the PHY - * ENDIF - * ENDIF - * ENDIF - * ENDIF - * IF nothing selected so far - * IF a 100Mbit PHY exists - * Select 10baseT - * ELSE - * Select 10baseT or 10base2, whichever is connected - * ENDIF - * ENDIF - */ - switch (scp->autoneg_status) { - - case XE_AUTONEG_NONE: -#ifdef XE_DEBUG - printf("xe%d: Waiting for idle transmitter\n", scp->unit); -#endif - scp->arpcom.ac_if.if_flags |= IFF_OACTIVE; - scp->autoneg_status = XE_AUTONEG_WAITING; - scp->chand = timeout(xe_setmedia, scp, hz * 2); - return; - - case XE_AUTONEG_WAITING: - xe_soft_reset(scp); - if (scp->phy_ok) { -#ifdef XE_DEBUG - printf("xe%d: Starting autonegotiation\n", scp->unit); -#endif - bmcr = xe_phy_readreg(scp, PHY_BMCR); - bmcr &= ~(PHY_BMCR_AUTONEGENBL); - xe_phy_writereg(scp, PHY_BMCR, bmcr); - anar = xe_phy_readreg(scp, PHY_ANAR); - anar &= ~(PHY_ANAR_100BT4|PHY_ANAR_100BTXFULL|PHY_ANAR_10BTFULL); - anar |= PHY_ANAR_100BTXHALF|PHY_ANAR_10BTHALF; - xe_phy_writereg(scp, PHY_ANAR, anar); - bmcr |= PHY_BMCR_AUTONEGENBL|PHY_BMCR_AUTONEGRSTR; - xe_phy_writereg(scp, PHY_BMCR, bmcr); - scp->autoneg_status = XE_AUTONEG_STARTED; - scp->chand = timeout(xe_setmedia, scp, hz * 7/2); - return; - } - else { - scp->autoneg_status = XE_AUTONEG_FAIL; - } - break; - - case XE_AUTONEG_STARTED: - bmsr = xe_phy_readreg(scp, PHY_BMSR); - lpar = xe_phy_readreg(scp, PHY_LPAR); - if (bmsr & (PHY_BMSR_AUTONEGCOMP|PHY_BMSR_LINKSTAT)) { -#ifdef XE_DEBUG - printf("xe%d: Autonegotiation complete!\n", scp->unit); -#endif - /* - * XXX - Shouldn't have to do this, but (on my hub at least) the - * XXX - transmitter won't work after a successful autoneg. So we see - * XXX - what the negotiation result was and force that mode. I'm - * XXX - sure there is an easy fix for this. - */ - if (lpar & PHY_LPAR_100BTXHALF) { - xe_phy_writereg(scp, PHY_BMCR, PHY_BMCR_SPEEDSEL); - XE_MII_DUMP(scp); - XE_SELECT_PAGE(2); - XE_OUTB(XE_MSR, XE_INB(XE_MSR) | 0x08); - scp->media = IFM_ETHER|IFM_100_TX; - scp->autoneg_status = XE_AUTONEG_NONE; - } - else { - /* - * XXX - Bit of a hack going on in here. - * XXX - This is derived from Ken Hughes patch to the Linux driver - * XXX - to make it work with 10Mbit _autonegotiated_ links on CE3B - * XXX - cards. What's a CE3B and how's it differ from a plain CE3? - * XXX - these are the things we need to find out. - */ - xe_phy_writereg(scp, PHY_BMCR, 0x0000); - XE_SELECT_PAGE(2); - /* BEGIN HACK */ - XE_OUTB(XE_MSR, XE_INB(XE_MSR) | 0x08); - XE_SELECT_PAGE(0x42); - XE_OUTB(XE_SWC1, 0x80); - scp->media = IFM_ETHER|IFM_10_T; - scp->autoneg_status = XE_AUTONEG_NONE; - /* END HACK */ - /*XE_OUTB(XE_MSR, XE_INB(XE_MSR) & ~0x08);*/ /* Disable PHY? */ - /*scp->autoneg_status = XE_AUTONEG_FAIL;*/ - } - } - else { -#ifdef XE_DEBUG - printf("xe%d: Autonegotiation failed; trying 100baseTX\n", scp->unit); -#endif - XE_MII_DUMP(scp); - xe_soft_reset(scp); - if (scp->phy_ok) { - xe_phy_writereg(scp, PHY_BMCR, PHY_BMCR_SPEEDSEL); - scp->autoneg_status = XE_AUTONEG_100TX; - scp->chand = timeout(xe_setmedia, scp, hz * 3); - return; - } - else { - scp->autoneg_status = XE_AUTONEG_FAIL; - } - } - break; - - case XE_AUTONEG_100TX: - (void)xe_phy_readreg(scp, PHY_BMSR); - bmsr = xe_phy_readreg(scp, PHY_BMSR); - if (bmsr & PHY_BMSR_LINKSTAT) { -#ifdef XE_DEBUG - printf("xe%d: Got 100baseTX link!\n", scp->unit); -#endif - XE_MII_DUMP(scp); - XE_SELECT_PAGE(2); - XE_OUTB(XE_MSR, XE_INB(XE_MSR) | 0x08); - scp->media = IFM_ETHER|IFM_100_TX; - scp->autoneg_status = XE_AUTONEG_NONE; - } - else { -#ifdef XE_DEBUG - printf("xe%d: Autonegotiation failed; disabling PHY\n", scp->unit); -#endif - XE_MII_DUMP(scp); - xe_phy_writereg(scp, PHY_BMCR, 0x0000); - XE_SELECT_PAGE(2); - XE_OUTB(XE_MSR, XE_INB(XE_MSR) & ~0x08); /* Disable PHY? */ - scp->autoneg_status = XE_AUTONEG_FAIL; - } - break; - } - - /* - * If we got down here _and_ autoneg_status is XE_AUTONEG_FAIL, then - * either autonegotiation failed, or never got started to begin with. In - * either case, select a suitable 10Mbit media and hope it works. We - * don't need to reset the card again, since it will have been done - * already by the big switch above. - */ - if (scp->autoneg_status == XE_AUTONEG_FAIL) { -#ifdef XE_DEBUG - printf("xe%d: Selecting 10baseX\n", scp->unit); -#endif - if (scp->ce3) { - XE_SELECT_PAGE(0x42); - XE_OUTB(XE_SWC1, 0x80); - scp->media = IFM_ETHER|IFM_10_T; - scp->autoneg_status = XE_AUTONEG_NONE; - } - else { - XE_SELECT_PAGE(4); - XE_OUTB(XE_GPR0, 4); - DELAY(50000); - XE_SELECT_PAGE(0x42); - XE_OUTB(XE_SWC1, (XE_INB(XE_ESR) & XE_ESR_MEDIA_SELECT) ? 0x80 : 0xc0); - scp->media = IFM_ETHER|((XE_INB(XE_ESR) & XE_ESR_MEDIA_SELECT) ? IFM_10_T : IFM_10_2); - scp->autoneg_status = XE_AUTONEG_NONE; - } - } - break; - - - /* - * If a specific media has been requested, we just reset the card and - * select it (one small exception -- if 100baseTX is requested by there is - * no PHY, we fall back to 10baseT operation). - */ - case IFM_100_TX: /* Force 100baseTX */ - xe_soft_reset(scp); - if (scp->phy_ok) { -#ifdef XE_DEBUG - printf("xe%d: Selecting 100baseTX\n", scp->unit); -#endif - XE_SELECT_PAGE(0x42); - XE_OUTB(XE_SWC1, 0); - xe_phy_writereg(scp, PHY_BMCR, PHY_BMCR_SPEEDSEL); - XE_SELECT_PAGE(2); - XE_OUTB(XE_MSR, XE_INB(XE_MSR) | 0x08); - scp->media |= IFM_100_TX; - break; - } - /* FALLTHROUGH */ - - case IFM_10_T: /* Force 10baseT */ - xe_soft_reset(scp); -#ifdef XE_DEBUG - printf("xe%d: Selecting 10baseT\n", scp->unit); -#endif - if (scp->phy_ok) { - xe_phy_writereg(scp, PHY_BMCR, 0x0000); - XE_SELECT_PAGE(2); - XE_OUTB(XE_MSR, XE_INB(XE_MSR) & ~0x08); /* Disable PHY */ - } - XE_SELECT_PAGE(0x42); - XE_OUTB(XE_SWC1, 0x80); - scp->media |= IFM_10_T; - break; - - case IFM_10_2: - xe_soft_reset(scp); -#ifdef XE_DEBUG - printf("xe%d: Selecting 10base2\n", scp->unit); -#endif - XE_SELECT_PAGE(0x42); - XE_OUTB(XE_SWC1, 0xc0); - scp->media |= IFM_10_2; - break; - } - - - /* - * Finally, the LEDs are set to match whatever media was chosen and the - * transmitter is unblocked. - */ -#ifdef XE_DEBUG - printf("xe%d: Setting LEDs\n", scp->unit); -#endif - XE_SELECT_PAGE(2); - switch (IFM_SUBTYPE(scp->media)) { - case IFM_100_TX: - case IFM_10_T: - XE_OUTB(XE_LED, 0x3b); - if (scp->cem56) - XE_OUTB(0x0b, 0x04); /* 100Mbit LED */ - break; - - case IFM_10_2: - XE_OUTB(XE_LED, 0x3a); - break; - } - - /* Restart output? */ - scp->ifp->if_flags &= ~IFF_OACTIVE; - xe_init(scp); -} - - -/* - * Hard reset (power cycle) the card. - */ -static void -xe_hard_reset(struct xe_softc *scp) { - int s; - -#ifdef XE_DEBUG - printf("xe%d: hard_reset\n", scp->unit); -#endif - - if (scp->gone) return; - - s = splimp(); - - /* - * Power cycle the card. - */ - XE_SELECT_PAGE(4); - XE_OUTB(XE_GPR1, 0); /* Power off */ - DELAY(40000); - - if (scp->ce3) - XE_OUTB(XE_GPR1, 1); /* And back on again */ - else - XE_OUTB(XE_GPR1, 5); /* Also set AIC bit, whatever that is */ - DELAY(40000); - XE_SELECT_PAGE(0); - - (void)splx(s); -} - - -/* - * Soft reset the card. Also makes sure that the ML6692 and 10Mbit controller - * are powered up, sets the silicon revision number in softc, disables - * interrupts and checks for the prescence of a 100Mbit PHY. This should - * leave us in a position where we can access the PHY and do media - * selection. The function imposes a 0.5s delay while the hardware powers up. - */ -static void -xe_soft_reset(struct xe_softc *scp) { - int s; - -#ifdef XE_DEBUG - printf("xe%d: soft_reset\n", scp->unit); -#endif - - if (scp->gone) return; - - s = splimp(); - - /* - * Reset the card, (again). - */ - XE_SELECT_PAGE(0); - XE_OUTB(XE_CR, XE_CR_SOFT_RESET); - DELAY(40000); - XE_OUTB(XE_CR, 0); - DELAY(40000); - - if (scp->ce3) { - /* - * set GP1 and GP2 as outputs (bits 2 & 3) - * set GP1 low to power on the ML6692 (bit 0) - * set GP2 high to power on the 10Mhz chip (bit 1) - */ - XE_SELECT_PAGE(4); - XE_OUTB(XE_GPR0, 0x0e); - } - - /* - * Wait for everything to wake up. - */ - DELAY(500000); - - /* - * Get silicon revision number. - */ - XE_SELECT_PAGE(4); - if (scp->ce3) - scp->srev = (XE_INB(XE_BOV) & 0x70) >> 4; - else - scp->srev = (XE_INB(XE_BOV) & 0x30) >> 4; -#ifdef XE_DEBUG - printf("xe%d: silicon revision = %d\n", scp->unit, scp->srev); -#endif - - /* - * Shut off interrupts. - */ - xe_disable_intr(scp); - - /* - * Check for PHY. - */ - if (scp->ce3) { - scp->phy_ok = xe_mii_init(scp); - } - - XE_SELECT_PAGE(0); - - (void)splx(s); -} - - -/* - * Take interface offline. This is done by powering down the device, which I - * assume means just shutting down the transceiver and Ethernet logic. This - * requires a _hard_ reset to recover from, as we need to power up again. - */ -static void -xe_stop(struct xe_softc *scp) { - int s; - -#ifdef XE_DEBUG - printf("xe%d: stop\n", scp->unit); -#endif - - if (scp->gone) return; - - s = splimp(); - - /* - * Shut off interrupts. - */ - xe_disable_intr(scp); - - /* - * Power down. - */ - XE_SELECT_PAGE(4); - XE_OUTB(XE_GPR1, 0); - XE_SELECT_PAGE(0); - - /* - * ~IFF_RUNNING == interface down. - */ - scp->ifp->if_flags &= ~IFF_RUNNING; - scp->ifp->if_flags &= ~IFF_OACTIVE; - scp->ifp->if_timer = 0; - - (void)splx(s); -} - - -/* - * Enable Ethernet interrupts from the card. - */ -static void -xe_enable_intr(struct xe_softc *scp) { -#ifdef XE_DEBUG - printf("xe%d: enable_intr\n", scp->unit); -#endif - - XE_SELECT_PAGE(1); - XE_OUTB(XE_IMR0, 0xff); /* Unmask everything */ - XE_OUTB(XE_IMR1, 0x01); /* Unmask TX underrun detection */ - DELAY(1); - - XE_SELECT_PAGE(0); - XE_OUTB(XE_CR, XE_CR_ENABLE_INTR); /* Enable interrupts */ - if (scp->modem && !scp->cem56) { /* This bit is just magic */ - if (!(XE_INB(0x10) & 0x01)) { - XE_OUTB(0x10, 0x11); /* Unmask master int enable bit */ - } - } -} - - -/* - * Disable all Ethernet interrupts from the card. - */ -static void -xe_disable_intr(struct xe_softc *scp) { -#ifdef XE_DEBUG - printf("xe%d: disable_intr\n", scp->unit); -#endif - - XE_SELECT_PAGE(0); - XE_OUTB(XE_CR, 0); /* Disable interrupts */ - if (scp->modem && !scp->cem56) { /* More magic (does this work?) */ - XE_OUTB(0x10, 0x10); /* Mask the master int enable bit */ - } - - XE_SELECT_PAGE(1); - XE_OUTB(XE_IMR0, 0); /* Forbid all interrupts */ - XE_OUTB(XE_IMR1, 0); - XE_SELECT_PAGE(0); -} - - -/* - * Set up multicast filter and promiscuous mode - */ -static void -xe_setmulti(struct xe_softc *scp) { - struct ifnet *ifp; - struct ifmultiaddr *maddr; - int count; - - ifp = &scp->arpcom.ac_if; - maddr = ifp->if_multiaddrs.lh_first; - - /* Get length of multicast list */ - for (count = 0; maddr != NULL; maddr = maddr->ifma_link.le_next, count++); - - if ((ifp->if_flags & IFF_PROMISC) || (ifp->if_flags & IFF_ALLMULTI) || (count > 9)) { - /* - * Go into promiscuous mode if either of the PROMISC or ALLMULTI flags are - * set, or if we have been asked to deal with more than 9 multicast - * addresses. To do this: set MPE and PME in SWC1 - */ - XE_SELECT_PAGE(0x42); - XE_OUTB(XE_SWC1, 0x06); - } - else if ((ifp->if_flags & IFF_MULTICAST) && (count > 0)) { - /* - * Program the filters for up to 9 addresses - */ - XE_SELECT_PAGE(0x42); - XE_OUTB(XE_SWC1, 0x01); - XE_SELECT_PAGE(0x40); - XE_OUTB(XE_OCR, XE_OCR_OFFLINE); - /*xe_reg_dump(scp);*/ - xe_setaddrs(scp); - /*xe_reg_dump(scp);*/ - XE_SELECT_PAGE(0x40); - XE_OUTB(XE_OCR, XE_OCR_RX_ENABLE|XE_OCR_ONLINE); - } - else { - /* - * No multicast operation (default) - */ - XE_SELECT_PAGE(0x42); - XE_OUTB(XE_SWC1, 0); - } - XE_SELECT_PAGE(0); -} - - -/* - * Set up all on-chip addresses (for multicast). AFAICS, there are 10 - * of these things; the first is our MAC address, the other 9 are mcast - * addresses, padded with the MAC address if there aren't enough. - * XXX - This doesn't work right, but I'm not sure why yet. We seem to be - * XXX - doing much the same as the Linux code, which is weird enough that - * XXX - it's probably right (despite my earlier comments to the contrary). - * XXX - I wonder if this thing has a multicast hash filter like most other - * XXX - Ethernet hardware seems to? - */ -static void -xe_setaddrs(struct xe_softc *scp) { - struct ifmultiaddr *maddr; - u_int8_t *addr; - u_int8_t page, slot, byte, i; - - maddr = scp->arpcom.ac_if.if_multiaddrs.lh_first; - - XE_SELECT_PAGE(page = 0x50); - - for (slot = 0, byte = 8; slot < 10; slot++) { - - if (slot == 0) - addr = (u_int8_t *)(&scp->arpcom.ac_enaddr); - else { - while (maddr != NULL && maddr->ifma_addr->sa_family != AF_LINK) - maddr = maddr->ifma_link.le_next; - if (maddr != NULL) - addr = LLADDR((struct sockaddr_dl *)maddr->ifma_addr); - else - addr = (u_int8_t *)(&scp->arpcom.ac_enaddr); - } - - for (i = 0; i < 6; i++, byte++) { -#if XE_DEBUG > 1 - if (i) - printf(":%x", addr[i]); - else - printf("xe%d: individual addresses %d: %x", scp->unit, slot, addr[0]); -#endif - - if (byte > 15) { - page++; - byte = 8; - XE_SELECT_PAGE(page); - } - - if (scp->ce3) - XE_OUTB(byte, addr[5 - i]); - else - XE_OUTB(byte, addr[i]); - } -#if XE_DEBUG > 1 - printf("\n"); -#endif - } - - XE_SELECT_PAGE(0); -} - - -/* - * Write an outgoing packet to the card using programmed I/O. - */ -static int -xe_pio_write_packet(struct xe_softc *scp, struct mbuf *mbp) { - struct mbuf *mbp2; - u_int16_t len, pad, free, ok; - u_int8_t *data; - u_int8_t savebyte[2], wantbyte; - - /* Get total packet length */ - for (len = 0, mbp2 = mbp; mbp2 != NULL; len += mbp2->m_len, mbp2 = mbp2->m_next); - - /* Packets < minimum length may need to be padded out */ - pad = 0; - if (len < ETHER_MIN_LEN - ETHER_CRC_LEN) { - pad = (ETHER_MIN_LEN - ETHER_CRC_LEN - len + 1) >> 1; - len = ETHER_MIN_LEN - ETHER_CRC_LEN; - } - - /* Check transmit buffer space */ - XE_SELECT_PAGE(0); - XE_OUTW(XE_TRS, len+2); - free = XE_INW(XE_TSO); - ok = free & 0x8000; - free &= 0x7fff; - if (free <= len + 2) - return 1; - - /* Send packet length to card */ - XE_OUTW(XE_EDP, len); - - /* - * Write packet to card using PIO (code stolen from the ed driver) - */ - wantbyte = 0; - while (mbp != NULL) { - len = mbp->m_len; - if (len > 0) { - data = mtod(mbp, caddr_t); - if (wantbyte) { /* Finish the last word */ - savebyte[1] = *data; - XE_OUTW(XE_EDP, *(u_short *)savebyte); - data++; - len--; - wantbyte = 0; - } - if (len > 1) { /* Output contiguous words */ - outsw(scp->dev->id_iobase+XE_EDP, data, len >> 1); - data += len & ~1; - len &= 1; - } - if (len == 1) { /* Save last byte, if necessary */ - savebyte[0] = *data; - wantbyte = 1; - } - } - mbp = mbp->m_next; - } - if (wantbyte) /* Last byte for odd-length packets */ - XE_OUTW(XE_EDP, *(u_short *)savebyte); - - /* - * For CE3 cards, just tell 'em to send -- apparently the card will pad out - * short packets with random cruft. Otherwise, write nonsense words to fill - * out the packet. I guess it is then sent automatically (?) - */ - if (scp->ce3) - XE_OUTB(XE_CR, XE_CR_TX_PACKET|XE_CR_ENABLE_INTR); - else - while (pad > 0) { - XE_OUTW(XE_EDP, 0xdead); - pad--; - } - - return 0; -} - - -/* - * The device entry is being removed, probably because someone ejected the - * card. The interface should have been brought down manually before calling - * this function; if not you may well lose packets. In any case, I shut down - * the card and the interface, and hope for the best. The 'gone' flag is set, - * so hopefully no-one else will try to access the missing card. - */ -static void -xe_card_unload(struct pccard_devinfo *devi) { - struct xe_softc *scp; - struct ifnet *ifp; - int unit; - - unit = devi->isahd.id_unit; - scp = sca[unit]; - ifp = &scp->arpcom.ac_if; - - if (scp->gone) { - printf("xe%d: already unloaded\n", unit); - return; - } - - if_down(ifp); - ifp->if_flags &= ~(IFF_RUNNING|IFF_OACTIVE); - xe_stop(scp); - scp->gone = 1; -} - - - -/************************************************************** - * * - * M I I F U N C T I O N S * - * * - **************************************************************/ - -/* - * Alternative MII/PHY handling code adapted from the xl driver. It doesn't - * seem to work any better than the xirc2_ps stuff, but it's cleaner code. - */ -#define XE_MII_SET(x) XE_OUTB(XE_GPR2, (XE_INB(XE_GPR2) | 0x04) | (x)) -#define XE_MII_CLR(x) XE_OUTB(XE_GPR2, (XE_INB(XE_GPR2) | 0x04) & ~(x)) - - -/* - * Sync the PHYs by setting data bit and strobing the clock 32 times. - */ -static void -xe_mii_sync(struct xe_softc *scp) { - register int i; - - XE_SELECT_PAGE(2); - XE_MII_SET(XE_MII_DIR|XE_MII_WRD); - - for (i = 0; i < 32; i++) { - XE_MII_SET(XE_MII_CLK); - DELAY(1); - XE_MII_CLR(XE_MII_CLK); - DELAY(1); - } -} - - -/* - * Look for a MII-compliant PHY. If we find one, reset it. - */ -static int -xe_mii_init(struct xe_softc *scp) { - u_int16_t status; - - status = xe_phy_readreg(scp, PHY_BMSR); - if ((status & 0xff00) != 0x7800) { -#ifdef XE_DEBUG - printf("xe%d: no PHY found, %0x\n", scp->unit, status); -#endif - return 0; - } - else { -#ifdef XE_DEBUG - printf("xe%d: PHY OK!\n", scp->unit); -#endif - - /* Reset the PHY */ - xe_phy_writereg(scp, PHY_BMCR, PHY_BMCR_RESET); - DELAY(500); - while(xe_phy_readreg(scp, PHY_BMCR) & PHY_BMCR_RESET); - XE_MII_DUMP(scp); - return 1; - } -} - - -/* - * Clock a series of bits through the MII. - */ -static void -xe_mii_send(struct xe_softc *scp, u_int32_t bits, int cnt) { - int i; - - XE_SELECT_PAGE(2); - XE_MII_CLR(XE_MII_CLK); - - for (i = (0x1 << (cnt - 1)); i; i >>= 1) { - if (bits & i) { - XE_MII_SET(XE_MII_WRD); - } else { - XE_MII_CLR(XE_MII_WRD); - } - DELAY(1); - XE_MII_CLR(XE_MII_CLK); - DELAY(1); - XE_MII_SET(XE_MII_CLK); - } -} - - -/* - * Read an PHY register through the MII. - */ -static int -xe_mii_readreg(struct xe_softc *scp, struct xe_mii_frame *frame) { - int i, ack, s; - - s = splimp(); - - /* - * Set up frame for RX. - */ - frame->mii_stdelim = XE_MII_STARTDELIM; - frame->mii_opcode = XE_MII_READOP; - frame->mii_turnaround = 0; - frame->mii_data = 0; - - XE_SELECT_PAGE(2); - XE_OUTB(XE_GPR2, 0); - - /* - * Turn on data xmit. - */ - XE_MII_SET(XE_MII_DIR); - - xe_mii_sync(scp); - - /* - * Send command/address info. - */ - xe_mii_send(scp, frame->mii_stdelim, 2); - xe_mii_send(scp, frame->mii_opcode, 2); - xe_mii_send(scp, frame->mii_phyaddr, 5); - xe_mii_send(scp, frame->mii_regaddr, 5); - - /* Idle bit */ - XE_MII_CLR((XE_MII_CLK|XE_MII_WRD)); - DELAY(1); - XE_MII_SET(XE_MII_CLK); - DELAY(1); - - /* Turn off xmit. */ - XE_MII_CLR(XE_MII_DIR); - - /* Check for ack */ - XE_MII_CLR(XE_MII_CLK); - DELAY(1); - XE_MII_SET(XE_MII_CLK); - DELAY(1); - ack = XE_INB(XE_GPR2) & XE_MII_RDD; - - /* - * Now try reading data bits. If the ack failed, we still - * need to clock through 16 cycles to keep the PHY(s) in sync. - */ - if (ack) { - for(i = 0; i < 16; i++) { - XE_MII_CLR(XE_MII_CLK); - DELAY(1); - XE_MII_SET(XE_MII_CLK); - DELAY(1); - } - goto fail; - } - - for (i = 0x8000; i; i >>= 1) { - XE_MII_CLR(XE_MII_CLK); - DELAY(1); - if (!ack) { - if (XE_INB(XE_GPR2) & XE_MII_RDD) - frame->mii_data |= i; - DELAY(1); - } - XE_MII_SET(XE_MII_CLK); - DELAY(1); - } - -fail: - - XE_MII_CLR(XE_MII_CLK); - DELAY(1); - XE_MII_SET(XE_MII_CLK); - DELAY(1); - - splx(s); - - if (ack) - return(1); - return(0); -} - - -/* - * Write to a PHY register through the MII. - */ -static int -xe_mii_writereg(struct xe_softc *scp, struct xe_mii_frame *frame) { - int s; - - s = splimp(); - - /* - * Set up frame for TX. - */ - frame->mii_stdelim = XE_MII_STARTDELIM; - frame->mii_opcode = XE_MII_WRITEOP; - frame->mii_turnaround = XE_MII_TURNAROUND; - - XE_SELECT_PAGE(2); - - /* - * Turn on data output. - */ - XE_MII_SET(XE_MII_DIR); - - xe_mii_sync(scp); - - xe_mii_send(scp, frame->mii_stdelim, 2); - xe_mii_send(scp, frame->mii_opcode, 2); - xe_mii_send(scp, frame->mii_phyaddr, 5); - xe_mii_send(scp, frame->mii_regaddr, 5); - xe_mii_send(scp, frame->mii_turnaround, 2); - xe_mii_send(scp, frame->mii_data, 16); - - /* Idle bit. */ - XE_MII_SET(XE_MII_CLK); - DELAY(1); - XE_MII_CLR(XE_MII_CLK); - DELAY(1); - - /* - * Turn off xmit. - */ - XE_MII_CLR(XE_MII_DIR); - - splx(s); - - return(0); -} - - -/* - * Read a register from the PHY. - */ -static u_int16_t -xe_phy_readreg(struct xe_softc *scp, u_int16_t reg) { - struct xe_mii_frame frame; - - bzero((char *)&frame, sizeof(frame)); - - frame.mii_phyaddr = 0; - frame.mii_regaddr = reg; - xe_mii_readreg(scp, &frame); - - return(frame.mii_data); -} - - -/* - * Write to a PHY register. - */ -static void -xe_phy_writereg(struct xe_softc *scp, u_int16_t reg, u_int16_t data) { - struct xe_mii_frame frame; - - bzero((char *)&frame, sizeof(frame)); - - frame.mii_phyaddr = 0; - frame.mii_regaddr = reg; - frame.mii_data = data; - xe_mii_writereg(scp, &frame); - - return; -} - - -#ifdef XE_DEBUG -/* - * A bit of debugging code. - */ -static void -xe_mii_dump(struct xe_softc *scp) { - int i, s; - - s = splimp(); - - printf("xe%d: MII registers: ", scp->unit); - for (i = 0; i < 2; i++) { - printf(" %d:%04x", i, xe_phy_readreg(scp, i)); - } - for (i = 4; i < 7; i++) { - printf(" %d:%04x", i, xe_phy_readreg(scp, i)); - } - printf("\n"); - - (void)splx(s); -} - -static void -xe_reg_dump(struct xe_softc *scp) { - int page, i, s; - - s = splimp(); - - printf("xe%d: Common registers: ", scp->unit); - for (i = 0; i < 8; i++) { - printf(" %2.2x", XE_INB(i)); - } - printf("\n"); - - for (page = 0; page <= 8; page++) { - printf("xe%d: Register page %2.2x: ", scp->unit, page); - XE_SELECT_PAGE(page); - for (i = 8; i < 16; i++) { - printf(" %2.2x", XE_INB(i)); - } - printf("\n"); - } - - for (page = 0x10; page < 0x5f; page++) { - if ((page >= 0x11 && page <= 0x3f) || - (page == 0x41) || - (page >= 0x43 && page <= 0x4f) || - (page >= 0x59)) - continue; - printf("xe%d: Register page %2.2x: ", scp->unit, page); - XE_SELECT_PAGE(page); - for (i = 8; i < 16; i++) { - printf(" %2.2x", XE_INB(i)); - } - printf("\n"); - } - - (void)splx(s); -} -#endif - - - -#if NAPM > 0 -/************************************************************** - * * - * A P M F U N C T I O N S * - * * - **************************************************************/ - -/* - * This is called when we go into suspend/standby mode - */ -static int -xe_suspend(void *xunit) { - -#ifdef XE_DEBUG - struct xe_softc *scp = sca[(int)xunit]; - - printf("xe%d: APM suspend\n", scp->unit); -#endif - - return 0; -} - -/* - * This is called when we wake up again - */ -static int -xe_resume(void *xunit) { - -#ifdef XE_DEBUG - struct xe_softc *scp = sca[(int)xunit]; - - printf("xe%d: APM resume\n", scp->unit); -#endif - - return 0; -} - -#endif /* NAPM > 0 */ - -#endif /* NCARD > 0 */ - -#endif /* NXE > 0 */ diff --git a/sys/dev/pccard/if_xereg.h b/sys/dev/pccard/if_xereg.h deleted file mode 100644 index 07cb0b1bbb59..000000000000 --- a/sys/dev/pccard/if_xereg.h +++ /dev/null @@ -1,296 +0,0 @@ -/*- - * Copyright (c) 1998, 1999 Scott Mitchell - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: if_xereg.h,v 1.3 1999/02/22 14:00:53 root Exp $ - */ - -/* - * Register definitions for Xircom CreditCard Ethernet adapters. See if_xe.c - * for details of supported hardware. Adapted from Werner Koch's 'xirc2ps' - * driver for Linux and the FreeBSD 'xl' driver (for the MII support). - */ - -#include "xe.h" -#if NXE > 0 - - -/* - * Common registers - */ -#define XE_CR 0 /* Command register (write) */ -#define XE_ESR 0 /* Ethernet status register (read) */ -#define XE_PSR 1 /* Page select register */ -#define XE_EDP 4 /* Ethernet data port */ -#define XE_ISR 6 /* Interrupt status register */ - -/* - * Command register values - */ -#define XE_CR_TX_PACKET 0x01 -#define XE_CR_SOFT_RESET 0x02 -#define XE_CR_ENABLE_INTR 0x04 -#define XE_CR_FORCE_INTR 0x08 -#define XE_CR_CLEAR_FIFO 0x10 -#define XE_CR_CLEAR_OVERRUN 0x20 -#define XE_CR_RESTART_TX 0x40 - -/* - * Status register values - */ -#define XE_ESR_FULL_PKT_RX 0x01 -#define XE_ESR_PKT_REJECT 0x04 -#define XE_ESR_TX_PENDING 0x08 -#define XE_ESR_BAD_POLARITY 0x10 -#define XE_ESR_MEDIA_SELECT 0x20 - -/* - * Interrupt register values - */ -#define XE_ISR_TX_OVERFLOW 0x01 -#define XE_ISR_TX_PACKET 0x02 -#define XE_ISR_MAC_INTR 0x04 -#define XE_ISR_TX_RES 0x08 -#define XE_ISR_RX_PACKET 0x20 -#define XE_ISR_RX_REJECT 0x40 -#define XE_ISR_FORCE_INTR 0x80 - - -/* - * Page 0 registers - */ -#define XE_TSO 8 /* Transmit space open */ -#define XE_TRS 10 /* Transmit reservation size */ -#define XE_DOR 12 /* Data offset register (write) */ -#define XE_RSR 12 /* Receive status register (read) */ -#define XE_PTR 13 /* Packets transmitted register (read) */ -#define XE_RBC 14 /* Received byte count (read) */ - -/* - * RSR values - */ -#define XE_RSR_PHYS_PKT 0x01 -#define XE_RSR_BCAST_PKT 0x02 -#define XE_RSR_LONG_PKT 0x04 -#define XE_RSR_ALIGN_ERR 0x10 -#define XE_RSR_CRC_ERR 0x20 -#define XE_RSR_RX_OK 0x80 - - -/* - * Page 1 registers - */ -#define XE_IMR0 12 /* Interrupt mask register, part 1 */ -#define XE_IMR1 13 /* Interrupt mask register, part 2 */ -#define XE_ECR 14 /* Ethernet configuration register */ - -/* - * ECR values - */ -#define XE_ECR_FULL_DUPLEX 0x04 -#define XE_ECR_LONG_TPCABLE 0x08 -#define XE_ECR_NO_POLCOL 0x10 -#define XE_ECR_NO_LINKPULSE 0x20 -#define XE_ECR_NO_AUTOTX 0x40 - - -/* - * Page 2 registers - */ -#define XE_RBS 8 /* Receive buffer start */ -#define XE_LED 10 /* LED configuration register */ -#define XE_MSR 12 /* Mohawk specfic register (Mohawk = CE3) */ -#define XE_GPR2 13 /* General purpose register 2 */ - - -/* - * Page 4 registers - */ -#define XE_GPR0 8 /* General purpose register 0 */ -#define XE_GPR1 9 /* General purpose register 1 */ -#define XE_BOV 10 /* Bonding version register */ -#define XE_LMA 12 /* Local memory address */ -#define XE_LMD 14 /* Local memory data */ - - -/* - * Page 5 registers - */ -#define XE_RHS 10 /* Receive host start address */ - - -/* - * Page 0x40 registers - */ -#define XE_OCR 8 /* The Other command register */ -#define XE_RXS0 9 /* Receive status 0 */ -#define XE_TXS0 11 /* Transmit status 0 */ -#define XE_TXS1 12 /* Transmit status 1 */ -#define XE_RXM0 13 /* Receive mask register 0 */ -#define XE_TXM0 14 /* Transmit mask register 0 */ -#define XE_TXM1 15 /* Transmit mask register 1 */ - -/* - * OCR values - */ -#define XE_OCR_TX 0x01 -#define XE_OCR_RX_ENABLE 0x04 -#define XE_OCR_RX_DISABLE 0x08 -#define XE_OCR_ABORT 0x10 -#define XE_OCR_ONLINE 0x20 -#define XE_OCR_ACK_INTR 0x40 -#define XE_OCR_OFFLINE 0x80 - - -/* - * Page 0x42 registers - */ -#define XE_SWC0 8 /* Software configuration register 0 */ -#define XE_SWC1 9 /* Software configuration register 1 */ -#define XE_BOC 10 /* Back-off configuration */ - - -/* - * Page 0x44 registers - */ -#define XE_TDR0 8 /* Time domain reflectometry register 0 */ -#define XE_TDR1 9 /* Time domain reflectometry register 1 */ -#define XE_RXC0 10 /* Receive byte count low */ -#define XE_RXC1 11 /* Receive byte count high */ - - -/* - * Page 0x45 registers - */ -#define XE_REV 15 /* Revision (read) */ - - -/* - * Page 0x50 registers - */ -#define XE_IAR 8 /* Individual address register */ - - -/* - * Pages 0x43, 0x46-0x4f and 0x51-0x5e apparently don't exist. - * The remainder of 0x0-0x8 and 0x40-0x5f exist, but I have no - * idea what's on most of them. - */ - - - -/* - * Definitions for the Micro Linear ML6692 100Base-TX PHY, which handles the - * 100Mbit functionality of CE3 type cards, including media autonegotiation. - * It appears to be mostly compatible with the National Semiconductor - * DP83840A, but with a much smaller register set. Please refer to the data - * sheets for these devices for the definitive word on what all this stuff - * means :) - * - * Note that the ML6692 has no 10Mbit capability -- that is handled by another - * chip that we don't know anything about. - * - * Most of these definitions were adapted from the xl driver. - */ - -/* - * Masks for the MII-related bits in GPR2. For some reason read and write - * data are on separate bits. - */ -#define XE_MII_CLK 0x01 -#define XE_MII_DIR 0x08 -#define XE_MII_WRD 0x02 -#define XE_MII_RDD 0x20 - -/* - * MII command (etc) bit strings. - */ -#define XE_MII_STARTDELIM 0x01 -#define XE_MII_READOP 0x02 -#define XE_MII_WRITEOP 0x01 -#define XE_MII_TURNAROUND 0x02 - -/* - * PHY registers. - */ -#define PHY_BMCR 0x00 /* Basic Mode Control Register */ -#define PHY_BMSR 0x01 /* Basic Mode Status Register */ -#define PHY_ANAR 0x04 /* Auto-Negotiation Advertisment Register */ -#define PHY_LPAR 0x05 /* Auto-Negotiation Link Partner Ability Register */ -#define PHY_ANER 0x06 /* Auto-Negotiation Expansion Register */ - -#define PHY_BMCR_RESET 0x8000 /* Soft reset PHY. Self-clearing */ -#define PHY_BMCR_LOOPBK 0x4000 /* Enable loopback */ -#define PHY_BMCR_SPEEDSEL 0x2000 /* 1=100Mbps, 0=10Mbps */ -#define PHY_BMCR_AUTONEGENBL 0x1000 /* Auto-negotiation enabled */ -#define PHY_BMCR_ISOLATE 0x0400 /* Isolate ML6692 from MII */ -#define PHY_BMCR_AUTONEGRSTR 0x0200 /* Restart auto-negotiation. Self-clearing */ -#define PHY_BMCR_DUPLEX 0x0100 /* Full duplex operation */ -#define PHY_BMCR_COLLTEST 0x0080 /* Enable collision test */ - -#define PHY_BMSR_100BT4 0x8000 /* 100Base-T4 capable */ -#define PHY_BMSR_100BTXFULL 0x4000 /* 100Base-TX full duplex capable */ -#define PHY_BMSR_100BTXHALF 0x2000 /* 100Base-TX half duplex capable */ -#define PHY_BMSR_10BTFULL 0x1000 /* 10Base-T full duplex capable */ -#define PHY_BMSR_10BTHALF 0x0800 /* 10Base-T half duplex capable */ -#define PHY_BMSR_AUTONEGCOMP 0x0020 /* Auto-negotiation complete */ -#define PHY_BMSR_CANAUTONEG 0x0008 /* Auto-negotiation supported */ -#define PHY_BMSR_LINKSTAT 0x0004 /* Link is up */ -#define PHY_BMSR_EXTENDED 0x0001 /* Extended register capabilities */ - -#define PHY_ANAR_NEXTPAGE 0x8000 /* Additional link code word pages */ -#define PHY_ANAR_TLRFLT 0x2000 /* Remote wire fault detected */ -#define PHY_ANAR_100BT4 0x0200 /* 100Base-T4 capable */ -#define PHY_ANAR_100BTXFULL 0x0100 /* 100Base-TX full duplex capable */ -#define PHY_ANAR_100BTXHALF 0x0080 /* 100Base-TX half duplex capable */ -#define PHY_ANAR_10BTFULL 0x0040 /* 10Base-T full duplex capable */ -#define PHY_ANAR_10BTHALF 0x0020 /* 10Base-T half duplex capable */ -#define PHY_ANAR_PROTO4 0x0010 /* Protocol selection (00001 = 802.3) */ -#define PHY_ANAR_PROTO3 0x0008 -#define PHY_ANAR_PROTO2 0x0004 -#define PHY_ANAR_PROTO1 0x0002 -#define PHY_ANAR_PROTO0 0x0001 - -#define PHY_LPAR_NEXTPAGE 0x8000 /* Additional link code word pages */ -#define PHY_LPAR_LPACK 0x4000 /* Link partner acknowledged receipt */ -#define PHY_LPAR_TLRFLT 0x2000 /* Remote wire fault detected */ -#define PHY_LPAR_100BT4 0x0200 /* 100Base-T4 capable */ -#define PHY_LPAR_100BTXFULL 0x0100 /* 100Base-TX full duplex capable */ -#define PHY_LPAR_100BTXHALF 0x0080 /* 100Base-TX half duplex capable */ -#define PHY_LPAR_10BTFULL 0x0040 /* 10Base-T full duplex capable */ -#define PHY_LPAR_10BTHALF 0x0020 /* 10Base-T half duplex capable */ -#define PHY_LPAR_PROTO4 0x0010 /* Protocol selection (00001 = 802.3) */ -#define PHY_LPAR_PROTO3 0x0008 -#define PHY_LPAR_PROTO2 0x0004 -#define PHY_LPAR_PROTO1 0x0002 -#define PHY_LPAR_PROTO0 0x0001 - -#define PHY_ANER_MLFAULT 0x0010 /* More than one link is up! */ -#define PHY_ANER_LPNPABLE 0x0008 /* Link partner supports next page */ -#define PHY_ANER_NPABLE 0x0004 /* Local port supports next page */ -#define PHY_ANER_PAGERX 0x0002 /* Page received */ -#define PHY_ANER_LPAUTONEG 0x0001 /* Link partner can auto-negotiate */ - - -#endif /* NXE > 0 */ |
