Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/twe/twe_freebsd.c
Show First 20 Lines • Show All 577 Lines • ▼ Show 20 Lines | |||||
* This is called from twe_add_unit. | * This is called from twe_add_unit. | ||||
*/ | */ | ||||
int | int | ||||
twe_attach_drive(struct twe_softc *sc, struct twe_drive *dr) | twe_attach_drive(struct twe_softc *sc, struct twe_drive *dr) | ||||
{ | { | ||||
char buf[80]; | char buf[80]; | ||||
int error; | int error; | ||||
mtx_lock(&Giant); | bus_topo_lock(); | ||||
dr->td_disk = device_add_child(sc->twe_dev, NULL, -1); | dr->td_disk = device_add_child(sc->twe_dev, NULL, -1); | ||||
if (dr->td_disk == NULL) { | if (dr->td_disk == NULL) { | ||||
mtx_unlock(&Giant); | bus_topo_unlock(); | ||||
twe_printf(sc, "Cannot add unit\n"); | twe_printf(sc, "Cannot add unit\n"); | ||||
return (EIO); | return (EIO); | ||||
} | } | ||||
device_set_ivars(dr->td_disk, dr); | device_set_ivars(dr->td_disk, dr); | ||||
/* | /* | ||||
* XXX It would make sense to test the online/initialising bits, but they seem to be | * XXX It would make sense to test the online/initialising bits, but they seem to be | ||||
* always set... | * always set... | ||||
*/ | */ | ||||
sprintf(buf, "Unit %d, %s, %s", | sprintf(buf, "Unit %d, %s, %s", | ||||
dr->td_twe_unit, | dr->td_twe_unit, | ||||
twe_describe_code(twe_table_unittype, dr->td_type), | twe_describe_code(twe_table_unittype, dr->td_type), | ||||
twe_describe_code(twe_table_unitstate, dr->td_state & TWE_PARAM_UNITSTATUS_MASK)); | twe_describe_code(twe_table_unitstate, dr->td_state & TWE_PARAM_UNITSTATUS_MASK)); | ||||
device_set_desc_copy(dr->td_disk, buf); | device_set_desc_copy(dr->td_disk, buf); | ||||
error = device_probe_and_attach(dr->td_disk); | error = device_probe_and_attach(dr->td_disk); | ||||
mtx_unlock(&Giant); | bus_topo_unlock(); | ||||
if (error != 0) { | if (error != 0) { | ||||
twe_printf(sc, "Cannot attach unit to controller. error = %d\n", error); | twe_printf(sc, "Cannot attach unit to controller. error = %d\n", error); | ||||
return (EIO); | return (EIO); | ||||
} | } | ||||
return (0); | return (0); | ||||
} | } | ||||
/******************************************************************************** | /******************************************************************************** | ||||
* Detach the specified unit if it exsists | * Detach the specified unit if it exsists | ||||
* | * | ||||
* This is called from twe_del_unit. | * This is called from twe_del_unit. | ||||
*/ | */ | ||||
int | int | ||||
twe_detach_drive(struct twe_softc *sc, int unit) | twe_detach_drive(struct twe_softc *sc, int unit) | ||||
{ | { | ||||
int error = 0; | int error = 0; | ||||
TWE_CONFIG_ASSERT_LOCKED(sc); | TWE_CONFIG_ASSERT_LOCKED(sc); | ||||
mtx_lock(&Giant); | bus_topo_lock(); | ||||
error = device_delete_child(sc->twe_dev, sc->twe_drive[unit].td_disk); | error = device_delete_child(sc->twe_dev, sc->twe_drive[unit].td_disk); | ||||
mtx_unlock(&Giant); | bus_topo_unlock(); | ||||
if (error != 0) { | if (error != 0) { | ||||
twe_printf(sc, "failed to delete unit %d\n", unit); | twe_printf(sc, "failed to delete unit %d\n", unit); | ||||
return(error); | return(error); | ||||
} | } | ||||
bzero(&sc->twe_drive[unit], sizeof(sc->twe_drive[unit])); | bzero(&sc->twe_drive[unit], sizeof(sc->twe_drive[unit])); | ||||
return(error); | return(error); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 538 Lines • Show Last 20 Lines |