Lines Matching defs:ocs

44 #include "ocs.h"
86 static uint32_t ocs_abort_initiator_io(struct ocs_softc *ocs, union ccb *accb);
87 static void ocs_abort_inot(struct ocs_softc *ocs, union ccb *ccb);
88 static void ocs_abort_atio(struct ocs_softc *ocs, union ccb *ccb);
95 ocs_fcp_change_role(struct ocs_softc *ocs, ocs_fcport *fcp, uint32_t new_role);
99 static void ocs_delete_target(ocs_t *ocs, ocs_fcport *fcp, int tgt);
105 static inline ocs_io_t *ocs_scsi_find_io(struct ocs_softc *ocs, uint32_t tag)
108 return ocs_io_get_instance(ocs, tag);
117 if(io->ocs->io_in_use != 0)
118 atomic_subtract_acq_32(&io->ocs->io_in_use, 1);
122 ocs_attach_port(ocs_t *ocs, int chan)
127 uint32_t max_io = ocs_scsi_get_property(ocs, OCS_SCSI_MAX_IOS);
128 ocs_fcport *fcp = FCPORT(ocs, chan);
131 device_get_name(ocs->dev), ocs,
132 device_get_unit(ocs->dev), &ocs->sim_lock,
133 max_io, max_io, ocs->devq))) {
134 device_printf(ocs->dev, "Can't allocate SIM\n");
138 mtx_lock(&ocs->sim_lock);
139 if (CAM_SUCCESS != xpt_bus_register(sim, ocs->dev, chan)) {
140 device_printf(ocs->dev, "Can't register bus %d\n", 0);
141 mtx_unlock(&ocs->sim_lock);
145 mtx_unlock(&ocs->sim_lock);
149 device_printf(ocs->dev, "Can't create path\n");
151 mtx_unlock(&ocs->sim_lock);
156 fcp->ocs = ocs;
160 callout_init_mtx(&fcp->ldt, &ocs->sim_lock, 0);
167 ocs_detach_port(ocs_t *ocs, int32_t chan)
172 fcp = FCPORT(ocs, chan);
181 mtx_lock(&ocs->sim_lock);
182 ocs_tgt_resource_abort(ocs, &fcp->targ_rsrc_wildcard);
192 mtx_unlock(&ocs->sim_lock);
199 ocs_cam_attach(ocs_t *ocs)
203 uint32_t max_io = ocs_scsi_get_property(ocs, OCS_SCSI_MAX_IOS);
206 device_printf(ocs->dev, "Can't allocate SIMQ\n");
210 ocs->devq = devq;
212 if (mtx_initialized(&ocs->sim_lock) == 0) {
213 mtx_init(&ocs->sim_lock, "ocs_sim_lock", NULL, MTX_DEF);
216 for (i = 0; i < (ocs->num_vports + 1); i++) {
217 if (ocs_attach_port(ocs, i)) {
218 ocs_log_err(ocs, "Attach port failed for chan: %d\n", i);
223 ocs->io_high_watermark = max_io;
224 ocs->io_in_use = 0;
229 ocs_detach_port(ocs, i);
232 cam_simq_free(ocs->devq);
234 if (mtx_initialized(&ocs->sim_lock))
235 mtx_destroy(&ocs->sim_lock);
241 ocs_cam_detach(ocs_t *ocs)
245 for (i = (ocs->num_vports); i >= 0; i--) {
246 ocs_detach_port(ocs, i);
249 cam_simq_free(ocs->devq);
251 if (mtx_initialized(&ocs->sim_lock))
252 mtx_destroy(&ocs->sim_lock);
267 * @param ocs the driver instance's software context
272 ocs_scsi_tgt_new_device(ocs_t *ocs)
274 ocs->enable_task_set_full = ocs_scsi_get_property(ocs,
276 ocs_log_debug(ocs, "task set full processing is %s\n",
277 ocs->enable_task_set_full ? "enabled" : "disabled");
284 * @brief Tears down target members of ocs structure.
288 * @param ocs pointer to ocs
293 ocs_scsi_tgt_del_device(ocs_t *ocs)
371 ocs_t *ocs = sport->ocs;
374 sport->tgt_data = FCPORT(ocs, 0);
423 ocs_t *ocs = node->ocs;
431 ocs_log_err(ocs, "FCP is NULL \n");
439 atomic_subtract_acq_32(&ocs->io_high_watermark, OCS_RSVD_INI_IO);
495 ocs_t *ocs = node->ocs;
503 ocs_log_err(ocs, "FCP is NULL \n");
523 atomic_add_acq_32(&ocs->io_high_watermark, OCS_RSVD_INI_IO);
551 ocs_t *ocs = io->ocs;
560 ocs_log_err(ocs, "FCP is NULL \n");
564 atomic_add_acq_32(&ocs->io_in_use, 1);
567 io->timeout = ocs->target_io_timer_sec;
569 if (ocs->enable_task_set_full &&
570 (ocs->io_in_use >= ocs->io_high_watermark)) {
622 ocs->dev, "%s: no ATIO for LUN %lx (en=%s) OX_ID %#x\n",
684 ocs_t *ocs = tmfio->ocs;
693 ocs_log_err(ocs, "FCP is NULL \n");
703 device_printf(tmfio->ocs->dev, "%s: io=%u(index) cmd=%#x LU=%lx en=%s\n",
712 ocs->dev, "%s: no INOT for LUN %llx (en=%s) OX_ID %#x\n",
743 device_printf(ocs->dev, "%s: ABTS IO.%#x st=%#x\n",
749 device_printf(ocs->dev,
775 device_printf(ocs->dev, "%s: unsupported TMF %#x\n",
803 * @brief Initializes any initiator fields on the ocs structure.
807 * @param ocs pointer to ocs
812 ocs_scsi_ini_new_device(ocs_t *ocs)
820 * @brief Tears down initiator members of ocs structure.
824 * @param ocs pointer to ocs
830 ocs_scsi_ini_del_device(ocs_t *ocs)
907 ocs_t *ocs = sport->ocs;
908 ocs_fcport *fcp = FCPORT(ocs, 0);
935 ocs_t *ocs = sport->ocs;
936 ocs_fcport *fcp = FCPORT(ocs, 0);
946 ocs_t *ocs = sport->ocs;
957 ocs_xport_status(ocs->xport, OCS_XPORT_PORT_STATUS, &value);
960 ocs_log_debug(ocs, "PORT offline,.. skipping\n");
966 ocs_log_debug(ocs,"sport is not NULL, skipping\n");
970 ocs_sport_vport_alloc(ocs->domain, fcp->vport);
1035 struct ocs_softc *ocs = node->ocs;
1043 device_printf(ocs->dev, "%s: ccb allocation failed\n", __func__);
1051 ocs->dev, "%s: target path creation failed\n", __func__);
1085 ocs_delete_target(ocs_t *ocs, ocs_fcport *fcp, int tgt)
1090 device_printf(ocs->dev, "%s: calling with NULL sim\n", __func__);
1124 ocs_t *ocs = fcp->ocs;
1135 if ((tgt->gone_timer != 0) && (ocs->attached)){
1141 ocs_delete_target(ocs, fcp, i);
1180 struct ocs_softc *ocs = node->ocs;
1185 if (ocs == NULL) {
1186 ocs_log_err(ocs,"OCS is NULL \n");
1192 ocs_log_err(ocs,"FCP is NULL \n");
1198 ocs_log_err(ocs,"target is invalid\n");
1205 if(!ocs->attached) {
1206 ocs_delete_target(ocs, fcp, tgt_id);
1317 ocs_t *ocs = io->ocs;
1330 io->ocs->io_in_use, io->ocs->io_high_watermark);
1334 io->ocs->io_in_use);
1338 if (OCS_LOG_ENABLE_Q_FULL_BUSY_MSG(ocs)) {
1342 ocs_log_info(ocs, "OCS CAM TASK SET FULL. Tasks >= %d\n",
1343 ocs->io_high_watermark);
1347 ocs_log_info(ocs, "OCS CAM SCSI BUSY\n");
1373 struct ocs_softc *ocs = csio->ccb_h.ccb_ocs_ptr;
1389 bus_dmamap_sync(ocs->buf_dmat, io->tgt_io.dmap, op);
1391 bus_dmamap_unload(ocs->buf_dmat, io->tgt_io.dmap);
1426 /*device_printf(ocs->dev, "%s: CTIO state=%d tag=%#x\n",
1443 struct ocs_softc *ocs = NULL;
1448 ocs = io->ocs;
1460 device_printf(ocs->dev, "%s: unhandled status %d\n",
1490 struct ocs_softc *ocs = csio->ccb_h.ccb_ocs_ptr;
1503 bus_dmamap_sync(ocs->buf_dmat, io->tgt_io.dmap, op);
1505 bus_dmamap_unload(ocs->buf_dmat, io->tgt_io.dmap);
1667 * @param ocs the driver instance's software context
1676 ocs_build_scsi_sgl(struct ocs_softc *ocs, union ccb *ccb, ocs_io_t *io,
1682 if (!ocs || !ccb || !io || !sgl) {
1684 ocs, ccb, io, sgl);
1695 err = bus_dmamap_load_ccb(ocs->buf_dmat, io->tgt_io.dmap, ccb,
1700 ocs->dev, "%s: bus_dmamap_load_ccb error (%d %d)\n",
1713 * @param ocs the driver instance's software context
1719 ocs_target_io(struct ocs_softc *ocs, union ccb *ccb)
1728 io = ocs_scsi_find_io(ocs, csio->tag_id);
1737 /*device_printf(ocs->dev,
1759 csio->ccb_h.ccb_ocs_ptr = ocs;
1790 sgl_count = ocs_build_scsi_sgl(ocs, ccb, io, sgl, io->sgl_allocated);
1801 device_printf(ocs->dev, "%s:"
1808 device_printf(ocs->dev, "%s: building SGL failed\n",
1814 device_printf(ocs->dev, "%s: Wrong value xfer and sendstatus"
1824 device_printf(ocs->dev, "%s: CTIO state=%d tag=%#x\n",
1839 /*device_printf(io->ocs->dev, "%s: tag=%x io=%p s=%#x\n",
1850 * @param ocs the driver instance's software context
1856 ocs_initiator_io(struct ocs_softc *ocs, union ccb *ccb)
1867 fcp = FCPORT(ocs, cam_sim_bus(xpt_path_sim((ccb)->ccb_h.path)));
1870 device_printf(ocs->dev, "%s: device LOST %d\n", __func__,
1876 device_printf(ocs->dev, "%s: device not ready %d\n", __func__,
1881 node = ocs_node_get_instance(ocs, fcp->tgt[ccb_h->target_id].node_id);
1883 device_printf(ocs->dev, "%s: no device %d\n", __func__,
1889 device_printf(ocs->dev, "%s: not target device %d\n", __func__,
1896 device_printf(ocs->dev, "%s: unable to alloc IO\n", __func__);
1904 csio->ccb_h.ccb_ocs_ptr = ocs;
1908 sgl_count = ocs_build_scsi_sgl(ocs, ccb, io, sgl, io->sgl_allocated);
1911 device_printf(ocs->dev, "%s: building SGL failed\n", __func__);
1982 ocs_fcp_change_role(struct ocs_softc *ocs, ocs_fcport *fcp, uint32_t new_role)
1988 for (was = 0, i = 0; i < (ocs->num_vports + 1); i++) {
1989 if (FCPORT(ocs, i)->role != KNOB_ROLE_NONE)
1997 ocs->enable_ini = (new_role & KNOB_ROLE_INITIATOR)? 1:0;
1998 ocs->enable_tgt = (new_role & KNOB_ROLE_TARGET)? 1:0;
2004 rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_OFFLINE);
2006 ocs_log_debug(ocs, "port offline failed : %d\n", rc);
2009 rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_ONLINE);
2011 ocs_log_debug(ocs, "port online failed : %d\n", rc);
2022 return ocs_sport_vport_del(ocs, ocs->domain, vport->wwpn, vport->wwnn);
2031 return ocs_sport_vport_alloc(ocs->domain, vport);
2053 struct ocs_softc *ocs = (struct ocs_softc *)cam_sim_softc(sim);
2070 rc = ocs_initiator_io(ocs, ccb);
2096 ocs_fcport *fcp = FCPORT(ocs, bus);
2106 if (ocs->ocs_xport == OCS_XPORT_FC) {
2115 ocs_xport_status(ocs->xport, OCS_XPORT_LINK_SPEED, &value);
2118 wwn = *((uint64_t *)ocs_scsi_get_property_ptr(ocs, OCS_SCSI_WWPN));
2121 wwn = *((uint64_t *)ocs_scsi_get_property_ptr(ocs, OCS_SCSI_WWNN));
2126 if (ocs->config_tgt) {
2136 cpi->initiator_id = ocs->max_remote_nodes + 1;
2138 if (!ocs->enable_ini) {
2153 (ocs_scsi_get_property(ocs, OCS_SCSI_MAX_SGL) - 1);
2170 ocs_fcport *fcp = FCPORT(ocs, bus);
2173 if (ocs->ocs_xport != OCS_XPORT_FC) {
2201 ocs_xport_status(ocs->xport, OCS_XPORT_LINK_SPEED, &value);
2233 ocs_fcport *fcp = FCPORT(ocs, bus);
2235 if (ocs->ocs_xport != OCS_XPORT_FC) {
2242 wwn = *((uint64_t *)ocs_scsi_get_property_ptr(ocs,
2246 wwn = *((uint64_t *)ocs_scsi_get_property_ptr(ocs,
2266 ocs_fcport *fcp = FCPORT(ocs, bus);
2268 if (ocs->ocs_xport != OCS_XPORT_FC) {
2275 device_printf(ocs->dev,
2305 device_printf(ocs->dev,
2311 device_printf(ocs->dev,
2315 ocs_fcp_change_role(ocs, fcp, knob->xport_specific.fc.role);
2331 ocs_abort_atio(ocs, ccb);
2334 ocs_abort_inot(ocs, ccb);
2337 rc = ocs_abort_initiator_io(ocs, accb);
2354 if (ocs_xport_control(ocs->xport, OCS_XPORT_PORT_OFFLINE) == 0) {
2355 rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_ONLINE);
2357 ocs_log_debug(ocs, "Failed to bring port online"
2371 ocs_fcport *fcp = FCPORT(ocs, bus);
2373 node = ocs_node_get_instance(ocs, fcp->tgt[ccb_h->target_id].node_id);
2375 device_printf(ocs->dev, "%s: no device %d\n",
2384 device_printf(ocs->dev, "%s: unable to alloc IO\n",
2413 ocs_fcport *fcp = FCPORT(ocs, bus);
2415 device_printf(ocs->dev, "XPT_EN_LUN %sable %d:%d\n",
2426 ocs_tgt_resource_abort(ocs, trsrc);
2458 ocs_fcport *fcp = FCPORT(ocs, bus);
2483 ccb->ccb_h.ccb_ocs_ptr = ocs;
2499 io = ocs_scsi_find_io(ocs, ccb->cna2.tag_id);
2501 device_printf(ocs->dev,
2512 device_printf(ocs->dev,
2529 if (ocs_target_io(ocs, ccb)) {
2530 device_printf(ocs->dev,
2537 device_printf(ocs->dev, "unhandled func_code = %#x\n",
2570 ocs_log_test(io->ocs, "check response without data?!?\n");
2576 ocs_log_test(io->ocs, "TMF status %08x\n",
2583 ocs_log_test(io->ocs, "status=%#x\n", scsi_status);
2599 * @param ocs the driver instance's software context
2630 ocs_tgt_resource_abort(struct ocs_softc *ocs, ocs_tgt_resource_t *trsrc)
2656 ocs_abort_atio(struct ocs_softc *ocs, union ccb *ccb)
2666 ocs_fcport *fcp = FCPORT(ocs, bus);
2693 device_printf(ocs->dev,
2704 device_printf(ocs->dev, "%s: abort not received or io completed \n", __func__);
2717 ocs_abort_inot(struct ocs_softc *ocs, union ccb *ccb)
2725 ocs_fcport *fcp = FCPORT(ocs, bus);
2747 ocs_abort_initiator_io(struct ocs_softc *ocs, union ccb *accb)
2755 ocs_fcport *fcp = FCPORT(ocs, cam_sim_bus(xpt_path_sim((accb)->ccb_h.path)));
2756 node = ocs_node_get_instance(ocs, fcp->tgt[accb->ccb_h.target_id].node_id);
2758 device_printf(ocs->dev, "%s: no device %d\n",
2767 device_printf(ocs->dev,
2789 //ocs_t *ocs = obj;
2819 //ocs_t *ocs = obj;
2890 lcrn = ocs_malloc(node->ocs, sizeof(struct ocs_lun_crn),
2920 ocs_free(node->ocs, lcrn, sizeof(*lcrn));