aboutsummaryrefslogtreecommitdiff
path: root/sys/cam/ctl/scsi_ctl.c
Commit message (Collapse)AuthorAgeFilesLines
* cam: Remove left-over sys/cdefs.h in sys/camWarner Losh2023-11-061-1/+0
| | | | | | | These weren't removed when $FreeBSD$ was removed. They aren't needed and now are a style(9) nonconformity. Sponsored by: Netflix
* sys: Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-161-2/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* cam/ctl: Migrate to modern uintXX_t from u_intXX_tWarner Losh2023-07-251-1/+1
| | | | | | | | As per https://lists.freebsd.org/archives/freebsd-scsi/2023-July/000257.html move to the modern uintXX_t. MFC After: 3 days Sponsored by: Netflix
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-121-1/+1
| | | | | | | | | The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch up to that fact and revert to their recommended match of BSD-2-Clause. Discussed with: pfg MFC After: 3 days Sponsored by: Netflix
* CTL: Increase maximum SCSI tag size from 32 to 64 bits.Alexander Motin2022-12-031-1/+1
| | | | | | | | | | | | | | | | | | | SAM-5 specification states maximum size of command identifier (tag), defined by specific transports, should not be larger than 64 bits. While most of supported transports use 32 bits or less, it was reported that virtio-scsi uses 64 bits. Truncation to 32 bits in bhyve code caused false tag conflict errors reported and possibly other issues. This changes CTL ABI and HA protocol, so CTL_HA_VERSION is bumped. While we make HA protocol incompatible, increase default maximum number of ports in CTL from 256 to 1024, matching number of LUNs. There are many reports from people who need many iSCSI targets with only one LUN each. Increased memory consumption should be less of a problem these days. PR: 267539
* cam: clear stack-allocated CCB in the target layerEdward Tomasz Napierala2021-07-211-0/+3
| | | | | | | | | | | | | | Note that, as pointed out by scottl@, this code should really look a bit different, in that the stack allocations should be replaced with dynamic allocation, and the periph creation should be moved to a context where one can use M_WAITOK. See the review for more details. For now let's go with a minimal fix until we're done with UMA CCBs. Reviewed By: mav, imp Sponsored by: NetApp, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D30298
* Refactor CTL datamove KPI.Alexander Motin2021-02-211-2/+1
| | | | | | | | | | | | | | | - Make frontends call unified CTL core method ctl_datamove_done() to report move completion. It allows to reduce code duplication in differerent backends by accounting DMA time in common code. - Add to ctl_datamove_done() and be_move_done() callback samethr argument, reporting whether the callback is called in the same context as ctl_datamove(). It allows for some cases like iSCSI write with immediate data or camsim frontend write save one context switch, since we know that the context is sleepable. - Remove data_move_done() methods from struct ctl_backend_driver, unused since forever. MFC after: 1 month
* Microoptimize CTL I/O queues.Alexander Motin2021-02-191-1/+1
| | | | | | | | | | | | Switch OOA queue from TAILQ to LIST and change its direction, so that we traverse it forward, not backward. There is only one place where we really need other direction, and it is not critical. Use STAILQ_REMOVE_HEAD() instead of STAILQ_REMOVE() in backends. Replace few impossible conditions with assertions. MFC after: 1 month
* Move XPT_IMMEDIATE_NOTIFY handling out of periph lock.Alexander Motin2021-02-181-1/+2
| | | | | | It is a rare, but still better to not have lock dependencies. MFC after: 1 month
* Introduce support of SCSI Command Priority.Alexander Motin2020-10-251-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | SAM-3 specification introduced concept of Task Priority, that was renamed to Command Priority in SAM-4, and supported by all modern SCSI transports. It provides 15 levels of relative priorities: 1 - highest, 15 - lowest and 0 - default. SAT specification for SATA devices translates priorities 1-3 into NCQ high priority. This change adds new "priority" field into empty spots of struct ccb_scsiio and struct ccb_accept_tio of CAM and struct ctl_scsiio of CTL. Respective support is added into iscsi(4), isp(4), mpr(4), mps(4) and ocs_fc(4) drivers for both initiator and where applicable target roles. Minimal support was added to CTL to receive the priority value from different frontends, pass it between HA controllers and report in few places. This patch does not add consumers of this functionality, so nothing should really change yet, since the field is still set to 0 (default) on initiator and not actively used on target. Those are to be implemented separately. I've confirmed priority working on WD Red SATA disks connected via mpr(4) and properly transferred to CTL target via iscsi(4), isp(4) and ocs_fc(4). While there, added missing tag_action support to ocs_fc(4) initiator role. MFC after: 1 month Relnotes: yes Sponsored by: iXsystems, Inc. Notes: svn path=/head/; revision=367044
* cam: clean up empty lines in .c and .h filesMateusz Guzik2020-09-011-3/+1
| | | | Notes: svn path=/head/; revision=365225
* Return a C errno for cam_periph_acquire().Scott Long2018-02-061-5/+5
| | | | | | | | | | | | | | There's no compelling reason to return a cam_status type for this function and doing so only creates confusion with normal C coding practices. It's technically an API change, but the periph API isn't widely used. No efffective change to operation. Reviewed by: imp, mav, ken Sponsored by: Netflix Differential Revision: D14063 Notes: svn path=/head/; revision=328918
* Minimum changes for ctl to build on architectures with non-matching physical andJustin Hibbits2018-01-261-1/+1
| | | | | | | | | | | | | | | | virtual address sizes Summary: Some architectures use physical addresses larger than virtual. This is the minimal changeset needed to get CAM/CTL to build on these targets. No functional changes. More changes would likely be needed for this to be fully functional on said platforms, but they can be made when needed. Reviewed By: mav, chuck Differential Revision: https://reviews.freebsd.org/D14041 Notes: svn path=/head/; revision=328425
* sys/cam: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-271-0/+2
| | | | | | | | | | | | | | | Mainly focus on files that use BSD 2-Clause license, however the tool I was using misidentified many licenses so this was mostly a manual - error prone - task. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Notes: svn path=/head/; revision=326265
* Do not loose CCB flags after r320493.Alexander Motin2017-08-091-1/+2
| | | | | | | | | There is at least CAM_UNLOCKED that should be kept. MFC after: 3 days Notes: svn path=/head/; revision=322302
* Unify INOT/ATIO setup.Alexander Motin2017-06-301-6/+3
| | | | Notes: svn path=/head/; revision=320493
* Increase device openings to tagged maximum.Alexander Motin2017-03-111-5/+25
| | | | | | | | | | | | | | | | Some SIMs report much less untagged device openings then tagged ones. Target mode devices are not handled by regular probing routines, and so there is nothing to increase queue size for them to the SIM's maximum. To fix that resize the queue explicitly on ctl periph registration. This radically improves performance of mpt(4) in target mode. Also fetch and report device queue statistics in `ctladm dumpstructs`, since regular way of `camcontrol tags` is not usable in target mode. MFC after: 2 weeks Notes: svn path=/head/; revision=315084
* Abort all ATIOs and INOTs queued to SIM on LUN disable.Alexander Motin2017-03-101-22/+45
| | | | | | | | | | | | Some SIMs may not abort them implicitly, that either fail the LUN disable request or just make us wait for those CCBs forever. With this change I can successfully disable LUNs on mpt(4). For isp(4), which aborts them implicitly, this change should be irrelevant. MFC after: 2 weeks Notes: svn path=/head/; revision=315030
* Switch work_queue from TAILQ to STAILQ.Alexander Motin2017-03-101-14/+13
| | | | | | | | | It is mostly FIFO and we don't need random removal there. MFC after: 2 weeks Notes: svn path=/head/; revision=315025
* Request change of SIM target role only when it is different.Alexander Motin2017-03-101-51/+51
| | | | | | | | | Separate WWNs change into separate request to know what actually failed. MFC after: 2 weeks Notes: svn path=/head/; revision=315022
* Add mechanism to unload CAM periph drivers.Alexander Motin2017-03-071-8/+25
| | | | | | | | For now it allows to unload CTL kernel module if there are no target-capable SIMs in CAM. As next step full teardown of CAM targets can be implemented. Notes: svn path=/head/; revision=314870
* Add support for SIMs without autosense.Alexander Motin2017-02-261-0/+14
| | | | | | | | | | | | If we asked to send sense data by setting CAM_SEND_SENSE, but SIM didn't confirm transmission by setting CAM_SENT_SENSE, assume it was not sent. Queue the I/O back to CTL for later REQUEST SENSE with ctl_queue_sense(). This is needed for error reporting on SPI HBAs like ahc(4)/ahd(4). MFC after: 2 weeks Notes: svn path=/head/; revision=314307
* Use resid field of CTIO to detect under/overruns.Alexander Motin2017-02-261-3/+4
| | | | | | | MFC after: 2 weeks Notes: svn path=/head/; revision=314300
* Axe out some forever disabled questionable functionality.Alexander Motin2017-02-251-116/+6
| | | | | | | | | This code is complicated enough even in its base shape. MFC after: 2 weeks Notes: svn path=/head/; revision=314247
* Improve CAM target frontend reference counting.Alexander Motin2017-02-251-54/+52
| | | | | | | | | | Before this change it was possible to trigger some use-after-free panics by disabling LUNs/ports under heavy load. MFC after: 2 weeks Notes: svn path=/head/; revision=314246
* Explicitly abort ATIO if CTIO sending status has failed.Alexander Motin2017-02-241-0/+8
| | | | | | | | | This helps SIM to free related resources in questionable cases. MFC after: 2 weeks Notes: svn path=/head/; revision=314204
* We can't access periph after ctlfe_free_ccb().Alexander Motin2017-02-241-1/+3
| | | | | | | MFC after: 2 weeks Notes: svn path=/head/; revision=314200
* Unify ATIO/INOT CCBs requeuing.Alexander Motin2017-02-241-58/+48
| | | | | | | MFC after: 2 weeks Notes: svn path=/head/; revision=314196
* Some code cleanup.Alexander Motin2017-02-241-38/+15
| | | | | | | MFC after: 2 weeks Notes: svn path=/head/; revision=314193
* Do not blindly free completed ATIOs/INOTs on invalidation.Alexander Motin2017-02-211-59/+19
| | | | | | | | | | | | | | When LUN is disabled, SIM starts returning queued ATIOs/INOTs. But at the same time there can be some ATIOs/INOTs still carrying real new requests. If we free those, SIM may leak some resources, forever expecting for any response from us. So try to be careful, separating ATIOs/INOTs carrying requests which still must be processed, from ATIOs/INOTs completed with errors which can be freed. MFC after: 2 weeks Notes: svn path=/head/; revision=314027
* Remove max_targets and max_target_id CTL port variables; they were unused.Edward Tomasz Napierala2017-01-221-6/+0
| | | | | | | | | This changes the CTL frontend ABI and thus shouldn't be MFC-ed. Reviewed by: mav@ Notes: svn path=/head/; revision=312651
* Add initial support for CTL module unloading.Alexander Motin2017-01-211-6/+8
| | | | | | | | | | | It is only a first step and not perfect, but better then nothing. The main blocker is CAM target frontend, that can not be unloaded, since CAM does not have mechanism to unregister periph driver now. MFC after: 2 weeks Notes: svn path=/head/; revision=312603
* Make CTL frontends report kern_data_resid for under-/overruns.Alexander Motin2017-01-161-53/+51
| | | | | | | | | | | | | | | | | It seems like kern_data_resid was never really implemented. This change finally does it. Now frontends update this field while transferring data, while CTL/backends getting it can more flexibly handle the result. At this point behavior should not change significantly, still reporting errors on write overrun, but that may be changed later, if we decide so. CAM target frontend still does not properly handle overruns due to CAM API limitations. We may need to add some fields to struct ccb_accept_tio to pass information about initiator requested transfer size(s). MFC after: 2 weeks Notes: svn path=/head/; revision=312291
* Improve CAM_CDB_POINTER support.Alexander Motin2017-01-131-6/+4
| | | | | | | MFC after: 2 weeks Notes: svn path=/head/; revision=312026
* Allow more efficient use of private area.Alexander Motin2016-12-271-11/+14
| | | | | | | | | There are 16 bytes of space, so we may store two pointers in one. MFC after: 2 weeks Notes: svn path=/head/; revision=310649
* Pass task management response information from CTL through CAM to isp(4),Alexander Motin2016-05-201-0/+23
| | | | | | | | | | utilizing previously unused arg field of struct ccb_notify_acknowledge. This makes new QUERY TASK, QUERY TASK SET and QUERY ASYNC EVENT requests really functional for CAM target mode drivers. Notes: svn path=/head/; revision=300293
* Move to new value for XPT_GET_SIM_KNOB to avoid clash with XPT_ATA_IO.Warner Losh2016-03-101-0/+1
| | | | Notes: svn path=/head/; revision=296604
* Give CTL support for PIM_EXTLUNS when talking to CAM.Alexander Motin2015-10-241-9/+26
| | | | | | | | CTL itself still lives in flat LUN space, but it can generate extended numbers if CAM SIM reports such capability. Notes: svn path=/head/; revision=289881
* Add partial support for QUERY TMF to CAM and isp(4).Alexander Motin2015-10-231-8/+15
| | | | | | | | | | | This change allows to decode respective functions in isp(4) in target mode and pass them through CAM to CTL. Unfortunately neither CAM nor isp(4) support returning response info for those task management functions now. On the other side I just have no initiator to test this functionality. Notes: svn path=/head/; revision=289843
* Fix LUN disable in CAM broken at r285155.Alexander Motin2015-10-231-1/+1
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=289819
* Update WRITE ATOMIC(16) support to sbc4r8 draft.Alexander Motin2015-09-241-1/+0
| | | | | | | | This is only a cosmetic change. We still don't support atomic boundary field in the CDB, but at least now we do it formally. Notes: svn path=/head/; revision=288166
* Reimplement CTL High Availability.Alexander Motin2015-09-101-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | CTL HA functionality was originally implemented by Copan many years ago, but large part of the sources was never published. This change includes clean room implementation of the missing code and fixes for many bugs. This code supports dual-node HA with ALUA in four modes: - Active/Unavailable without interlink between nodes; - Active/Standby with second node handling only basic LUN discovery and reservation, synchronizing with the first node through the interlink; - Active/Active with both nodes processing commands and accessing the backing storage, synchronizing with the first node through the interlink; - Active/Active with second node working as proxy, transfering all commands to the first node for execution through the interlink. Unlike original Copan's implementation, depending on specific hardware, this code uses simple custom TCP-based protocol for interlink. It has no authentication, so it should never be enabled on public interfaces. The code may still need some polishing, but generally it is functional. Relnotes: yes Sponsored by: iXsystems, Inc. Notes: svn path=/head/; revision=287621
* Remove unused target and initiator IDs.Alexander Motin2015-09-101-7/+4
| | | | Notes: svn path=/head/; revision=287620
* Remove 600 bytes of port_priv from struct ctl_io_hdr.Alexander Motin2015-08-291-14/+27
| | | | | | | | This field used only for camtgt frontend, and once it any way preallocates all requests, let it preallocate this memory too, not bothering core code. Notes: svn path=/head/; revision=287293
* Make first step toward supporting target and initiator roles same time.Alexander Motin2015-07-051-11/+7
| | | | | | | | | | | | | | | | | | | | | | To avoid conflicts between target and initiator devices in CAM, make CTL use target ID reported by HBA as its initiator_id in XPT_PATH_INQ. That target ID is known to never be used for initiator role, so it won't conflict. For Fibre Channel and FireWire HBAs this specific ID choice is irrelevant since all target IDs there are virtual. Same time for SPI HBAs it seems could be even requirement to use same target ID for both initiator and target roles. While there are some more things to polish in isp(4) driver, first tests of using both roles same time on the same port appeared successfull: # camcontrol devlist -v scbus0 on isp0 bus 0: <FREEBSD CTLDISK 0001> at scbus0 target 1 lun 0 (da20,pass21) <> at scbus0 target 256 lun 0 (ctl0) <> at scbus0 target -1 lun ffffffff (ctl1) Notes: svn path=/head/; revision=285155
* Bring per-port LUN enable/disable code up to date:Alexander Motin2015-06-201-11/+7
| | | | | | | | | | | | | - remove last remnants of never implemented multiple targets support; - implement missing support for LUN mapping in this area. Due to existing locking constraints LUN mapping code is practically unlocked at this point. Hopefully it is not racy enough to live until somebody get idea how to call sleeping fronend methods under lock also taken by the same frontend in non-sleepable context. :( Notes: svn path=/head/; revision=284640
* Remove device queue freeze handling and replace it with dummy.Alexander Motin2015-06-201-30/+14
| | | | | | | | | | | | At this point CTL has no known use case for device queue freezes. Same time existing (considered to be broken) code was found to cause modify-after-free issues. Discussed with: ken MFC after: 1 week Notes: svn path=/head/; revision=284622
* Change ATIO/INOT counting to prevent periph destruction while requestsAlexander Motin2015-06-181-33/+28
| | | | | | | | | are still running inside CTL. MFC after: 1 week Notes: svn path=/head/; revision=284541
* Allow setting only WWNN or only WWPN.Alexander Motin2015-06-051-5/+13
| | | | | | | MFC after: 2 weeks Notes: svn path=/head/; revision=284013
* Don't count status as sent until CTIO completes successfully.Alexander Motin2015-01-161-1/+4
| | | | | | | | | | | If we aggregated status sending with data move and got error, allow status to be updated and resent again separately. Without this command may stuck without status sent at all. MFC after: 2 weeks Notes: svn path=/head/; revision=277247