Lines Matching refs:ch

99     struct ata_channel *ch = device_get_softc(dev);  in ata_attach()  local
107 if (ch->r_irq) in ata_attach()
111 ch->dev = dev; in ata_attach()
112 ch->state = ATA_IDLE; in ata_attach()
113 bzero(&ch->state_mtx, sizeof(struct mtx)); in ata_attach()
114 mtx_init(&ch->state_mtx, "ATA state lock", NULL, MTX_DEF); in ata_attach()
115 TASK_INIT(&ch->conntask, 0, ata_conn_event, dev); in ata_attach()
117 ch->user[i].revision = 0; in ata_attach()
125 ch->user[i].revision = mode; in ata_attach()
126 ch->user[i].mode = 0; in ata_attach()
137 ch->user[i].mode = mode; in ata_attach()
138 if (ch->flags & ATA_SATA) in ata_attach()
139 ch->user[i].bytecount = 8192; in ata_attach()
141 ch->user[i].bytecount = MAXPHYS; in ata_attach()
142 ch->user[i].caps = 0; in ata_attach()
143 ch->curr[i] = ch->user[i]; in ata_attach()
144 if (ch->flags & ATA_SATA) { in ata_attach()
145 if (ch->pm_level > 0) in ata_attach()
146 ch->user[i].caps |= CTS_SATA_CAPS_H_PMREQ; in ata_attach()
147 if (ch->pm_level > 1) in ata_attach()
148 ch->user[i].caps |= CTS_SATA_CAPS_D_PMREQ; in ata_attach()
150 if (!(ch->flags & ATA_NO_48BIT_DMA)) in ata_attach()
151 ch->user[i].caps |= CTS_ATA_CAPS_H_DMA48; in ata_attach()
154 callout_init(&ch->poll_callout, 1); in ata_attach()
157 if (ch->dma.alloc) in ata_attach()
158 ch->dma.alloc(dev); in ata_attach()
162 ch->r_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, in ata_attach()
164 if (!ch->r_irq) { in ata_attach()
168 if ((error = bus_setup_intr(dev, ch->r_irq, ATA_INTR_FLAGS, NULL, in ata_attach()
169 ata_interrupt, ch, &ch->ih))) { in ata_attach()
170 bus_release_resource(dev, SYS_RES_IRQ, rid, ch->r_irq); in ata_attach()
175 if (ch->flags & ATA_PERIODIC_POLL) in ata_attach()
176 callout_reset(&ch->poll_callout, hz, ata_periodic_poll, ch); in ata_attach()
177 mtx_lock(&ch->state_mtx); in ata_attach()
186 ch->sim = cam_sim_alloc(ataaction, atapoll, "ata", ch, in ata_attach()
187 device_get_unit(dev), &ch->state_mtx, 1, 0, devq); in ata_attach()
188 if (ch->sim == NULL) { in ata_attach()
194 if (xpt_bus_register(ch->sim, dev, 0) != CAM_SUCCESS) { in ata_attach()
199 if (xpt_create_path(&ch->path, /*periph*/NULL, cam_sim_path(ch->sim), in ata_attach()
205 mtx_unlock(&ch->state_mtx); in ata_attach()
209 xpt_bus_deregister(cam_sim_path(ch->sim)); in ata_attach()
211 cam_sim_free(ch->sim, /*free_devq*/TRUE); in ata_attach()
212 ch->sim = NULL; in ata_attach()
214 bus_release_resource(dev, SYS_RES_IRQ, rid, ch->r_irq); in ata_attach()
215 mtx_unlock(&ch->state_mtx); in ata_attach()
216 if (ch->flags & ATA_PERIODIC_POLL) in ata_attach()
217 callout_drain(&ch->poll_callout); in ata_attach()
224 struct ata_channel *ch = device_get_softc(dev); in ata_detach() local
227 if (!ch->r_irq) in ata_detach()
231 mtx_lock(&ch->state_mtx); in ata_detach()
232 ch->state |= ATA_STALL_QUEUE; in ata_detach()
233 mtx_unlock(&ch->state_mtx); in ata_detach()
234 if (ch->flags & ATA_PERIODIC_POLL) in ata_detach()
235 callout_drain(&ch->poll_callout); in ata_detach()
237 taskqueue_drain(taskqueue_thread, &ch->conntask); in ata_detach()
239 mtx_lock(&ch->state_mtx); in ata_detach()
240 xpt_async(AC_LOST_DEVICE, ch->path, NULL); in ata_detach()
241 xpt_free_path(ch->path); in ata_detach()
242 xpt_bus_deregister(cam_sim_path(ch->sim)); in ata_detach()
243 cam_sim_free(ch->sim, /*free_devq*/TRUE); in ata_detach()
244 ch->sim = NULL; in ata_detach()
245 mtx_unlock(&ch->state_mtx); in ata_detach()
248 bus_teardown_intr(dev, ch->r_irq, ch->ih); in ata_detach()
249 bus_release_resource(dev, SYS_RES_IRQ, ATA_IRQ_RID, ch->r_irq); in ata_detach()
250 ch->r_irq = NULL; in ata_detach()
253 if (ch->dma.free) in ata_detach()
254 ch->dma.free(dev); in ata_detach()
256 mtx_destroy(&ch->state_mtx); in ata_detach()
264 struct ata_channel *ch = device_get_softc(dev); in ata_conn_event() local
267 mtx_lock(&ch->state_mtx); in ata_conn_event()
268 if (ch->sim == NULL) { in ata_conn_event()
269 mtx_unlock(&ch->state_mtx); in ata_conn_event()
276 cam_sim_path(ch->sim), in ata_conn_event()
282 mtx_unlock(&ch->state_mtx); in ata_conn_event()
288 struct ata_channel *ch = device_get_softc(dev); in ata_reinit() local
291 xpt_freeze_simq(ch->sim, 1); in ata_reinit()
292 if ((request = ch->running)) { in ata_reinit()
293 ch->running = NULL; in ata_reinit()
294 if (ch->state == ATA_ACTIVE) in ata_reinit()
295 ch->state = ATA_IDLE; in ata_reinit()
297 if (ch->dma.unload) in ata_reinit()
298 ch->dma.unload(request); in ata_reinit()
305 xpt_async(AC_BUS_RESET, ch->path, NULL); in ata_reinit()
306 xpt_release_simq(ch->sim, TRUE); in ata_reinit()
313 struct ata_channel *ch; in ata_suspend() local
316 if (!dev || !(ch = device_get_softc(dev))) in ata_suspend()
319 if (ch->flags & ATA_PERIODIC_POLL) in ata_suspend()
320 callout_drain(&ch->poll_callout); in ata_suspend()
321 mtx_lock(&ch->state_mtx); in ata_suspend()
322 xpt_freeze_simq(ch->sim, 1); in ata_suspend()
323 while (ch->state != ATA_IDLE) in ata_suspend()
324 msleep(ch, &ch->state_mtx, PRIBIO, "atasusp", hz/100); in ata_suspend()
325 mtx_unlock(&ch->state_mtx); in ata_suspend()
332 struct ata_channel *ch; in ata_resume() local
336 if (!dev || !(ch = device_get_softc(dev))) in ata_resume()
339 mtx_lock(&ch->state_mtx); in ata_resume()
341 xpt_release_simq(ch->sim, TRUE); in ata_resume()
342 mtx_unlock(&ch->state_mtx); in ata_resume()
343 if (ch->flags & ATA_PERIODIC_POLL) in ata_resume()
344 callout_reset(&ch->poll_callout, hz, ata_periodic_poll, ch); in ata_resume()
351 struct ata_channel *ch = (struct ata_channel *)data; in ata_interrupt() local
353 mtx_lock(&ch->state_mtx); in ata_interrupt()
355 mtx_unlock(&ch->state_mtx); in ata_interrupt()
361 struct ata_channel *ch = (struct ata_channel *)data; in ata_interrupt_locked() local
365 if (ch->hw.status && !ch->hw.status(ch->dev)) in ata_interrupt_locked()
369 if (!(request = ch->running)) in ata_interrupt_locked()
375 if (ch->state == ATA_IDLE) { in ata_interrupt_locked()
384 if (ch->hw.end_transaction(request) == ATA_OP_FINISHED) { in ata_interrupt_locked()
385 ch->running = NULL; in ata_interrupt_locked()
386 if (ch->state == ATA_ACTIVE) in ata_interrupt_locked()
387 ch->state = ATA_IDLE; in ata_interrupt_locked()
388 ata_cam_end_transaction(ch->dev, request); in ata_interrupt_locked()
396 struct ata_channel *ch = (struct ata_channel *)data; in ata_periodic_poll() local
398 callout_reset(&ch->poll_callout, hz, ata_periodic_poll, ch); in ata_periodic_poll()
399 ata_interrupt(ch); in ata_periodic_poll()
415 struct ata_channel *ch = device_get_softc(dev); in ata_default_registers() local
418 ch->r_io[ATA_ERROR].res = ch->r_io[ATA_FEATURE].res; in ata_default_registers()
419 ch->r_io[ATA_ERROR].offset = ch->r_io[ATA_FEATURE].offset; in ata_default_registers()
420 ch->r_io[ATA_IREASON].res = ch->r_io[ATA_COUNT].res; in ata_default_registers()
421 ch->r_io[ATA_IREASON].offset = ch->r_io[ATA_COUNT].offset; in ata_default_registers()
422 ch->r_io[ATA_STATUS].res = ch->r_io[ATA_COMMAND].res; in ata_default_registers()
423 ch->r_io[ATA_STATUS].offset = ch->r_io[ATA_COMMAND].offset; in ata_default_registers()
424 ch->r_io[ATA_ALTSTAT].res = ch->r_io[ATA_CONTROL].res; in ata_default_registers()
425 ch->r_io[ATA_ALTSTAT].offset = ch->r_io[ATA_CONTROL].offset; in ata_default_registers()
699 struct ata_channel *ch = device_get_softc(dev); in ata_atapi() local
701 return (ch->devices & (ATA_ATAPI_MASTER << target)); in ata_atapi()
707 struct ata_channel *ch; in ata_timeout() local
709 ch = device_get_softc(request->parent); in ata_timeout()
719 if (ch->state == ATA_ACTIVE) { in ata_timeout()
721 if (ch->dma.unload) in ata_timeout()
722 ch->dma.unload(request); in ata_timeout()
723 ch->running = NULL; in ata_timeout()
724 ch->state = ATA_IDLE; in ata_timeout()
725 ata_cam_end_transaction(ch->dev, request); in ata_timeout()
727 mtx_unlock(&ch->state_mtx); in ata_timeout()
733 struct ata_channel *ch = device_get_softc(dev); in ata_cam_begin_transaction() local
736 request = &ch->request; in ata_cam_begin_transaction()
778 ch->curr[ccb->ccb_h.target_id].bytecount); in ata_cam_begin_transaction()
788 if (ch->curr[ccb->ccb_h.target_id].atapi == 16) in ata_cam_begin_transaction()
791 ch->curr[ccb->ccb_h.target_id].mode >= ATA_DMA) in ata_cam_begin_transaction()
798 ch->curr[ccb->ccb_h.target_id].bytecount); in ata_cam_begin_transaction()
802 callout_init_mtx(&request->callout, &ch->state_mtx, CALLOUT_RETURNUNLOCKED); in ata_cam_begin_transaction()
806 ch->running = request; in ata_cam_begin_transaction()
807 ch->state = ATA_ACTIVE; in ata_cam_begin_transaction()
808 if (ch->hw.begin_transaction(request) == ATA_OP_FINISHED) { in ata_cam_begin_transaction()
809 ch->running = NULL; in ata_cam_begin_transaction()
810 ch->state = ATA_IDLE; in ata_cam_begin_transaction()
819 struct ata_channel *ch = device_get_softc(dev); in ata_cam_request_sense() local
822 ch->requestsense = 1; in ata_cam_request_sense()
833 if (ch->curr[ccb->ccb_h.target_id].atapi == 16) in ata_cam_request_sense()
835 if (ch->curr[ccb->ccb_h.target_id].mode >= ATA_DMA) in ata_cam_request_sense()
839 ch->curr[ccb->ccb_h.target_id].bytecount); in ata_cam_request_sense()
842 callout_init_mtx(&request->callout, &ch->state_mtx, CALLOUT_RETURNUNLOCKED); in ata_cam_request_sense()
845 ch->running = request; in ata_cam_request_sense()
846 ch->state = ATA_ACTIVE; in ata_cam_request_sense()
847 if (ch->hw.begin_transaction(request) == ATA_OP_FINISHED) { in ata_cam_request_sense()
848 ch->running = NULL; in ata_cam_request_sense()
849 ch->state = ATA_IDLE; in ata_cam_request_sense()
858 struct ata_channel *ch = device_get_softc(dev); in ata_cam_process_sense() local
862 ch->requestsense = 0; in ata_cam_process_sense()
884 struct ata_channel *ch = device_get_softc(dev); in ata_cam_end_transaction() local
888 if (ch->requestsense) { in ata_cam_end_transaction()
895 xpt_freeze_simq(ch->sim, 1); in ata_cam_end_transaction()
955 struct ata_channel *ch = device_get_softc(dev); in ata_check_ids() local
957 if (ccb->ccb_h.target_id > ((ch->flags & ATA_NO_SLAVE) ? 0 : 1)) { in ata_check_ids()
980 struct ata_channel *ch; in ataaction() local
985 ch = (struct ata_channel *)cam_sim_softc(sim); in ataaction()
986 dev = ch->dev; in ataaction()
993 if ((ch->devices & ((ATA_ATA_MASTER | ATA_ATAPI_MASTER) in ataaction()
998 if (ch->running) in ataaction()
1006 if (ch->devices & (ATA_ATA_MASTER << ccb->ccb_h.target_id)) { in ataaction()
1030 d = &ch->curr[ccb->ccb_h.target_id]; in ataaction()
1032 d = &ch->user[ccb->ccb_h.target_id]; in ataaction()
1033 if (ch->flags & ATA_SATA) { in ataaction()
1038 d->mode = ATA_SETMODE(ch->dev, in ataaction()
1053 d->mode = ATA_SETMODE(ch->dev, in ataaction()
1077 d = &ch->curr[ccb->ccb_h.target_id]; in ataaction()
1079 d = &ch->user[ccb->ccb_h.target_id]; in ataaction()
1082 if (ch->flags & ATA_SATA) { in ataaction()
1099 if (ch->pm_level) { in ataaction()
1104 ch->user[ccb->ccb_h.target_id].caps; in ataaction()
1124 if (!(ch->flags & ATA_NO_48BIT_DMA)) in ataaction()
1128 ch->user[ccb->ccb_h.target_id].caps; in ataaction()
1157 if (ch->flags & ATA_NO_SLAVE) in ataaction()
1164 if (ch->flags & ATA_SATA) in ataaction()
1172 if (ch->flags & ATA_SATA) in ataaction()
1179 cpi->maxio = ch->dma.max_iosize ? ch->dma.max_iosize : DFLTPHYS; in ataaction()
1200 struct ata_channel *ch = (struct ata_channel *)cam_sim_softc(sim); in atapoll() local
1202 ata_interrupt_locked(ch); in atapoll()