2 * Copyright (c) 2017 Broadcom. All rights reserved.
3 * The term "Broadcom" refers to Broadcom Limited and/or its subsidiaries.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
15 * 3. Neither the name of the copyright holder nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
34 #define OCS_COPYRIGHT "Copyright (C) 2017 Broadcom. All rights reserved."
38 * Implementation of required FreeBSD PCI interface functions
43 #include <sys/sysctl.h>
44 #include <sys/malloc.h>
46 static MALLOC_DEFINE(M_OCS, "OCS", "OneCore Storage data");
48 #include <dev/pci/pcireg.h>
49 #include <dev/pci/pcivar.h>
51 #include <machine/bus.h>
54 * Tunable parameters for transport
59 int loglevel = LOG_INFO;
60 int ramlog_size = 1*1024*1024;
61 int ddump_saved_size = 0;
62 static const char *queue_topology = "eq cq rq cq mq $nulp($nwq(cq wq:ulp=$rpt1)) cq wq:len=256:class=1";
64 static void ocs_release_bus(struct ocs_softc *);
65 static int32_t ocs_intr_alloc(struct ocs_softc *);
66 static int32_t ocs_intr_setup(struct ocs_softc *);
67 static int32_t ocs_intr_teardown(struct ocs_softc *);
68 static int ocs_pci_intx_filter(void *);
69 static void ocs_pci_intr(void *);
70 static int32_t ocs_init_dma_tag(struct ocs_softc *ocs);
72 static int32_t ocs_setup_fcports(ocs_t *ocs);
74 ocs_t *ocs_devices[MAX_OCS_DEVICES];
77 * @brief Check support for the given device
79 * Determine support for a given device by examining the PCI vendor and
82 * @param dev device abstraction
84 * @return 0 if device is supported, ENXIO otherwise
87 ocs_pci_probe(device_t dev)
91 if (pci_get_vendor(dev) != PCI_VENDOR_EMULEX) {
95 switch (pci_get_device(dev)) {
96 case PCI_PRODUCT_EMULEX_OCE16001:
97 desc = "Emulex LightPulse FC Adapter";
99 case PCI_PRODUCT_EMULEX_LPE31004:
100 desc = "Emulex LightPulse FC Adapter";
102 case PCI_PRODUCT_EMULEX_OCE50102:
103 desc = "Emulex LightPulse 10GbE FCoE/NIC Adapter";
109 device_set_desc(dev, desc);
111 return BUS_PROBE_DEFAULT;
115 ocs_map_bars(device_t dev, struct ocs_softc *ocs)
119 * Map PCI BAR0 register into the CPU's space.
122 ocs->reg[0].rid = PCIR_BAR(PCI_64BIT_BAR0);
123 ocs->reg[0].res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
124 &ocs->reg[0].rid, RF_ACTIVE);
126 if (ocs->reg[0].res == NULL) {
127 device_printf(dev, "bus_alloc_resource failed rid=%#x\n",
132 ocs->reg[0].btag = rman_get_bustag(ocs->reg[0].res);
133 ocs->reg[0].bhandle = rman_get_bushandle(ocs->reg[0].res);
139 ocs_setup_params(struct ocs_softc *ocs)
142 const char *hw_war_version;
143 /* Setup tunable parameters */
144 ocs->ctrlmask = ctrlmask;
147 ocs->ethernet_license = 0;
148 ocs->num_scsi_ios = 8192;
150 ocs->hlm_group_size = 8;
151 ocs->logmask = logmask;
153 ocs->config_tgt = FALSE;
154 if (0 == resource_int_value(device_get_name(ocs->dev), device_get_unit(ocs->dev),
157 ocs->config_tgt = TRUE;
158 device_printf(ocs->dev, "Enabling target\n");
162 ocs->config_ini = TRUE;
163 if (0 == resource_int_value(device_get_name(ocs->dev), device_get_unit(ocs->dev),
166 ocs->config_ini = FALSE;
167 device_printf(ocs->dev, "Disabling initiator\n");
170 ocs->enable_ini = ocs->config_ini;
172 if (!ocs->config_ini && !ocs->config_tgt) {
173 device_printf(ocs->dev, "Unsupported, both initiator and target mode disabled.\n");
178 if (0 == resource_int_value(device_get_name(ocs->dev), device_get_unit(ocs->dev),
179 "logmask", &logmask)) {
180 device_printf(ocs->dev, "logmask = %#x\n", logmask);
183 if (0 == resource_int_value(device_get_name(ocs->dev), device_get_unit(ocs->dev),
184 "logdest", &logdest)) {
185 device_printf(ocs->dev, "logdest = %#x\n", logdest);
188 if (0 == resource_int_value(device_get_name(ocs->dev), device_get_unit(ocs->dev),
189 "loglevel", &loglevel)) {
190 device_printf(ocs->dev, "loglevel = %#x\n", loglevel);
193 if (0 == resource_int_value(device_get_name(ocs->dev), device_get_unit(ocs->dev),
194 "ramlog_size", &ramlog_size)) {
195 device_printf(ocs->dev, "ramlog_size = %#x\n", ramlog_size);
198 if (0 == resource_int_value(device_get_name(ocs->dev), device_get_unit(ocs->dev),
199 "ddump_saved_size", &ddump_saved_size)) {
200 device_printf(ocs->dev, "ddump_saved_size= %#x\n", ddump_saved_size);
203 /* If enabled, initailize a RAM logging buffer */
205 ocs->ramlog = ocs_ramlog_init(ocs, ramlog_size/OCS_RAMLOG_DEFAULT_BUFFERS,
206 OCS_RAMLOG_DEFAULT_BUFFERS);
207 /* If NULL was returned, then we'll simply skip using the ramlog but */
208 /* set logdest to 1 to ensure that we at least get default logging. */
209 if (ocs->ramlog == NULL) {
214 /* initialize a saved ddump */
215 if (ddump_saved_size) {
216 if (ocs_textbuf_alloc(ocs, &ocs->ddump_saved, ddump_saved_size)) {
217 ocs_log_err(ocs, "failed to allocate memory for saved ddump\n");
221 if (0 == resource_string_value(device_get_name(ocs->dev), device_get_unit(ocs->dev),
222 "hw_war_version", &hw_war_version)) {
223 device_printf(ocs->dev, "hw_war_version = %s\n", hw_war_version);
224 ocs->hw_war_version = strdup(hw_war_version, M_OCS);
227 if (0 == resource_int_value(device_get_name(ocs->dev), device_get_unit(ocs->dev),
228 "explicit_buffer_list", &i)) {
229 ocs->explicit_buffer_list = i;
232 if (0 == resource_int_value(device_get_name(ocs->dev), device_get_unit(ocs->dev),
233 "ethernet_license", &i)) {
234 ocs->ethernet_license = i;
237 if (0 == resource_int_value(device_get_name(ocs->dev), device_get_unit(ocs->dev),
239 device_printf(ocs->dev, "speed = %d Mbps\n", i);
242 ocs->desc = device_get_desc(ocs->dev);
244 ocs_device_lock_init(ocs);
245 ocs->driver_version = STR_BE_MAJOR "." STR_BE_MINOR "." STR_BE_BUILD "." STR_BE_BRANCH;
246 ocs->model = ocs_pci_model(ocs->pci_vendor, ocs->pci_device);
248 if (0 == resource_int_value(device_get_name(ocs->dev), device_get_unit(ocs->dev),
250 device_printf(ocs->dev, "enable_hlm = %d\n", i);
252 if (ocs->enable_hlm) {
253 ocs->hlm_group_size = 8;
255 if (0 == resource_int_value(device_get_name(ocs->dev), device_get_unit(ocs->dev),
256 "hlm_group_size", &i)) {
257 ocs->hlm_group_size = i;
259 device_printf(ocs->dev, "hlm_group_size = %d\n", i);
263 if (0 == resource_int_value(device_get_name(ocs->dev), device_get_unit(ocs->dev),
264 "num_scsi_ios", &i)) {
265 ocs->num_scsi_ios = i;
266 device_printf(ocs->dev, "num_scsi_ios = %d\n", ocs->num_scsi_ios);
268 ocs->num_scsi_ios = 8192;
271 if (0 == resource_int_value(device_get_name(ocs->dev), device_get_unit(ocs->dev),
274 device_printf(ocs->dev, "Setting topology=%#x\n", i);
277 if (0 == resource_int_value(device_get_name(ocs->dev), device_get_unit(ocs->dev),
279 if (i >= 0 && i <= 254) {
280 device_printf(ocs->dev, "num_vports = %d\n", i);
283 device_printf(ocs->dev, "num_vports: %d not supported \n", i);
288 if (0 == resource_int_value(device_get_name(ocs->dev), device_get_unit(ocs->dev),
289 "external_loopback", &i)) {
290 device_printf(ocs->dev, "external_loopback = %d\n", i);
291 ocs->external_loopback = i;
294 if (0 == resource_int_value(device_get_name(ocs->dev), device_get_unit(ocs->dev),
295 "tgt_rscn_delay", &i)) {
296 device_printf(ocs->dev, "tgt_rscn_delay = %d\n", i);
297 ocs->tgt_rscn_delay_msec = i * 1000;
300 if (0 == resource_int_value(device_get_name(ocs->dev), device_get_unit(ocs->dev),
301 "tgt_rscn_period", &i)) {
302 device_printf(ocs->dev, "tgt_rscn_period = %d\n", i);
303 ocs->tgt_rscn_period_msec = i * 1000;
306 if (0 == resource_int_value(device_get_name(ocs->dev), device_get_unit(ocs->dev),
307 "target_io_timer", &i)) {
308 device_printf(ocs->dev, "target_io_timer = %d\n", i);
309 ocs->target_io_timer_sec = i;
312 hw_global.queue_topology_string = queue_topology;
313 ocs->rq_selection_policy = 0;
315 ocs->filter_def = "0,0,0,0";
321 ocs_setup_fcports(ocs_t *ocs)
323 uint32_t i = 0, role = 0;
324 uint64_t sli_wwpn, sli_wwnn;
326 ocs_xport_t *xport = ocs->xport;
327 ocs_vport_spec_t *vport;
328 ocs_fcport *fcp = NULL;
330 size = sizeof(ocs_fcport) * (ocs->num_vports + 1);
332 ocs->fcports = ocs_malloc(ocs, size, M_ZERO|M_NOWAIT);
333 if (ocs->fcports == NULL) {
334 device_printf(ocs->dev, "Can't allocate fcport \n");
338 role = (ocs->enable_ini)? KNOB_ROLE_INITIATOR: 0 |
339 (ocs->enable_tgt)? KNOB_ROLE_TARGET: 0;
341 fcp = FCPORT(ocs, i);
345 ocs_list_foreach(&xport->vport_list, vport) {
346 fcp = FCPORT(ocs, i);
347 vport->tgt_data = fcp;
351 if (ocs_hw_get_def_wwn(ocs, i, &sli_wwpn, &sli_wwnn)) {
352 ocs_log_err(ocs, "Get default wwn failed \n");
357 vport->wwpn = ocs_be64toh(sli_wwpn);
358 vport->wwnn = ocs_be64toh(sli_wwnn);
360 ocs_log_debug(ocs, "VPort wwpn: %lx wwnn: %lx \n", vport->wwpn, vport->wwnn);
367 ocs_device_attach(ocs_t *ocs)
373 ocs_log_warn(ocs, "%s: Device is already attached\n", __func__);
377 /* Allocate transport object and bring online */
378 ocs->xport = ocs_xport_alloc(ocs);
379 if (ocs->xport == NULL) {
380 device_printf(ocs->dev, "failed to allocate transport object\n");
382 } else if (ocs_xport_attach(ocs->xport) != 0) {
383 device_printf(ocs->dev, "%s: failed to attach transport object\n", __func__);
384 goto fail_xport_attach;
385 } else if (ocs_xport_initialize(ocs->xport) != 0) {
386 device_printf(ocs->dev, "%s: failed to initialize transport object\n", __func__);
387 goto fail_xport_init;
390 if (ocs_init_dma_tag(ocs)) {
391 goto fail_intr_setup;
394 for (i = 0; (io = ocs_io_get_instance(ocs, i)); i++) {
395 if (bus_dmamap_create(ocs->buf_dmat, 0, &io->tgt_io.dmap)) {
396 device_printf(ocs->dev, "%s: bad dma map create\n", __func__);
399 io->tgt_io.state = OCS_CAM_IO_FREE;
402 if (ocs_setup_fcports(ocs)) {
403 device_printf(ocs->dev, "FCports creation failed\n");
404 goto fail_intr_setup;
407 if(ocs_cam_attach(ocs)) {
408 device_printf(ocs->dev, "cam attach failed \n");
409 goto fail_intr_setup;
412 if (ocs_intr_setup(ocs)) {
413 device_printf(ocs->dev, "Interrupt setup failed\n");
414 goto fail_intr_setup;
417 if (ocs->enable_ini || ocs->enable_tgt) {
418 if (ocs_xport_control(ocs->xport, OCS_XPORT_PORT_ONLINE)) {
419 device_printf(ocs->dev, "Can't init port\n");
420 goto fail_xport_online;
424 ocs->attached = true;
429 if (ocs_xport_control(ocs->xport, OCS_XPORT_SHUTDOWN)) {
430 device_printf(ocs->dev, "Transport Shutdown timed out\n");
432 ocs_intr_teardown(ocs);
435 ocs_xport_detach(ocs->xport);
437 ocs_scsi_tgt_del_device(ocs);
439 ocs_xport_free(ocs->xport);
443 ocs_free(ocs, ocs->xport, sizeof(*(ocs->xport)));
449 * @brief Connect the driver to the given device
451 * If the probe routine is successful, the OS will give the driver
452 * the opportunity to connect itself to the device. This routine
453 * maps PCI resources (memory BARs and interrupts) and initialize a
456 * @param dev device abstraction
458 * @return 0 if the driver attaches to the device, ENXIO otherwise
462 ocs_pci_attach(device_t dev)
464 struct ocs_softc *ocs;
467 instance = device_get_unit(dev);
469 ocs = (struct ocs_softc *)device_get_softc(dev);
471 device_printf(dev, "cannot allocate softc\n");
474 memset(ocs, 0, sizeof(struct ocs_softc));
476 if (instance < ARRAY_SIZE(ocs_devices)) {
477 ocs_devices[instance] = ocs;
479 device_printf(dev, "got unexpected ocs instance number %d\n", instance);
482 ocs->instance_index = instance;
486 pci_enable_io(dev, SYS_RES_MEMORY);
487 pci_enable_busmaster(dev);
489 ocs->pci_vendor = pci_get_vendor(dev);
490 ocs->pci_device = pci_get_device(dev);
491 snprintf(ocs->businfo, sizeof(ocs->businfo), "%02X:%02X:%02X",
492 pci_get_bus(dev), pci_get_slot(dev), pci_get_function(dev));
494 /* Map all memory BARs */
495 if (ocs_map_bars(dev, ocs)) {
496 device_printf(dev, "Failed to map pci bars\n");
500 /* create a root DMA tag for the device */
501 if (bus_dma_tag_create(bus_get_dma_tag(dev),
502 1, /* byte alignment */
503 0, /* no boundary restrictions */
504 BUS_SPACE_MAXADDR, /* no minimum low address */
505 BUS_SPACE_MAXADDR, /* no maximum high address */
506 NULL, /* no filter function */
507 NULL, /* or arguments */
508 BUS_SPACE_MAXSIZE, /* max size covered by tag */
509 BUS_SPACE_UNRESTRICTED, /* no segment count restrictions */
510 BUS_SPACE_MAXSIZE, /* no segment length restrictions */
512 NULL, /* no lock manipulation function */
513 NULL, /* or arguments */
515 device_printf(dev, "parent DMA tag allocation failed\n");
519 if (ocs_intr_alloc(ocs)) {
520 device_printf(dev, "Interrupt allocation failed\n");
524 if (PCIC_SERIALBUS == pci_get_class(dev) &&
525 PCIS_SERIALBUS_FC == pci_get_subclass(dev))
526 ocs->ocs_xport = OCS_XPORT_FC;
528 device_printf(dev, "unsupported class (%#x : %#x)\n",
534 /* Setup tunable parameters */
535 if (ocs_setup_params(ocs)) {
536 device_printf(ocs->dev, "failed to setup params\n");
540 if (ocs_device_attach(ocs)) {
541 device_printf(ocs->dev, "failed to attach device\n");
545 ocs->fc_type = FC_TYPE_FCP;
547 ocs_debug_attach(ocs);
552 ocs_ramlog_free(ocs, ocs->ramlog);
553 ocs_device_lock_free(ocs);
554 free(ocs->hw_war_version, M_OCS);
556 ocs_release_bus(ocs);
561 * @brief free resources when pci device detach
563 * @param ocs pointer to ocs structure
565 * @return 0 for success, a negative error code value for failure.
569 ocs_device_detach(ocs_t *ocs)
575 if (!ocs->attached) {
576 ocs_log_warn(ocs, "%s: Device is not attached\n", __func__);
580 ocs->attached = FALSE;
582 rc = ocs_xport_control(ocs->xport, OCS_XPORT_SHUTDOWN);
584 ocs_log_err(ocs, "%s: Transport Shutdown timed out\n", __func__);
587 ocs_intr_teardown(ocs);
589 if (ocs_xport_detach(ocs->xport) != 0) {
590 ocs_log_err(ocs, "%s: Transport detach failed\n", __func__);
594 ocs_free(ocs, ocs->fcports, sizeof(*(ocs->fcports)));
596 for (i = 0; (io = ocs_io_get_instance(ocs, i)); i++) {
597 if (bus_dmamap_destroy(ocs->buf_dmat, io->tgt_io.dmap)) {
598 device_printf(ocs->dev, "%s: bad dma map destroy\n", __func__);
601 bus_dma_tag_destroy(ocs->dmat);
602 ocs_xport_free(ocs->xport);
612 * @brief Detach the driver from the given device
614 * If the driver is a loadable module, this routine gets called at unload
615 * time. This routine will stop the device and free any allocated resources.
617 * @param dev device abstraction
619 * @return 0 if the driver detaches from the device, ENXIO otherwise
622 ocs_pci_detach(device_t dev)
624 struct ocs_softc *ocs;
626 ocs = (struct ocs_softc *)device_get_softc(dev);
628 device_printf(dev, "no driver context?!?\n");
632 if (ocs->config_tgt && ocs->enable_tgt) {
633 device_printf(dev, "can't detach with target mode enabled\n");
637 ocs_device_detach(ocs);
640 * Workaround for OCS SCSI Transport quirk.
642 * CTL requires that target mode is disabled prior to unloading the
643 * driver (ie ocs->enable_tgt = FALSE), but once the target is disabled,
644 * the transport will not call ocs_scsi_tgt_del_device() which deallocates
645 * CAM resources. The workaround is to explicitly make the call here.
648 ocs_scsi_tgt_del_device(ocs);
650 /* free strdup created buffer.*/
651 free(ocs->hw_war_version, M_OCS);
653 ocs_device_lock_free(ocs);
655 ocs_debug_detach(ocs);
657 ocs_ramlog_free(ocs, ocs->ramlog);
659 ocs_release_bus(ocs);
665 * @brief Notify driver of system shutdown
667 * @param dev device abstraction
669 * @return 0 if the driver attaches to the device, ENXIO otherwise
672 ocs_pci_shutdown(device_t dev)
674 device_printf(dev, "%s\n", __func__);
679 * @brief Release bus resources allocated within the soft context
681 * @param ocs Pointer to the driver's context
686 ocs_release_bus(struct ocs_softc *ocs)
692 ocs_intr_teardown(ocs);
695 bus_release_resource(ocs->dev, SYS_RES_IRQ,
696 rman_get_rid(ocs->irq), ocs->irq);
699 pci_release_msi(ocs->dev);
706 bus_dma_tag_destroy(ocs->dmat);
708 for (i = 0; i < PCI_MAX_BAR; i++) {
709 if (ocs->reg[i].res) {
710 bus_release_resource(ocs->dev, SYS_RES_MEMORY,
719 * @brief Allocate and initialize interrupts
721 * @param ocs Pointer to the driver's context
726 ocs_intr_alloc(struct ocs_softc *ocs)
730 if (pci_alloc_msix(ocs->dev, &ocs->n_vec)) {
731 device_printf(ocs->dev, "MSI-X allocation failed\n");
732 if (pci_alloc_msi(ocs->dev, &ocs->n_vec)) {
733 device_printf(ocs->dev, "MSI allocation failed \n");
742 ocs->irq = bus_alloc_resource_any(ocs->dev, SYS_RES_IRQ, &ocs->irqid,
743 RF_ACTIVE | RF_SHAREABLE);
744 if (NULL == ocs->irq) {
745 device_printf(ocs->dev, "could not allocate interrupt\n");
749 ocs->intr_ctx.vec = 0;
750 ocs->intr_ctx.softc = ocs;
751 snprintf(ocs->intr_ctx.name, sizeof(ocs->intr_ctx.name),
753 device_get_nameunit(ocs->dev),
760 * @brief Create and attach an interrupt handler
762 * @param ocs Pointer to the driver's context
764 * @return 0 on success, non-zero otherwise
767 ocs_intr_setup(struct ocs_softc *ocs)
769 driver_filter_t *filter = NULL;
771 if (0 == ocs->n_vec) {
772 filter = ocs_pci_intx_filter;
775 if (bus_setup_intr(ocs->dev, ocs->irq, INTR_MPSAFE | INTR_TYPE_CAM,
776 filter, ocs_pci_intr, &ocs->intr_ctx,
778 device_printf(ocs->dev, "could not initialize interrupt\n");
787 * @brief Detach an interrupt handler
789 * @param ocs Pointer to the driver's context
791 * @return 0 on success, non-zero otherwise
794 ocs_intr_teardown(struct ocs_softc *ocs)
798 printf("%s: bad driver context?!?\n", __func__);
803 bus_teardown_intr(ocs->dev, ocs->irq, ocs->tag);
811 * @brief PCI interrupt handler
813 * @param arg pointer to the driver's software context
815 * @return FILTER_HANDLED if interrupt is processed, FILTER_STRAY otherwise
818 ocs_pci_intx_filter(void *arg)
820 ocs_intr_ctx_t *intr = arg;
821 struct ocs_softc *ocs = NULL;
829 #ifndef PCIM_STATUS_INTR
830 #define PCIM_STATUS_INTR 0x0008
832 val = pci_read_config(ocs->dev, PCIR_STATUS, 2);
834 device_printf(ocs->dev, "%s: pci_read_config(PCIR_STATUS) failed\n", __func__);
837 if (0 == (val & PCIM_STATUS_INTR)) {
841 val = pci_read_config(ocs->dev, PCIR_COMMAND, 2);
842 val |= PCIM_CMD_INTxDIS;
843 pci_write_config(ocs->dev, PCIR_COMMAND, val, 2);
845 return FILTER_SCHEDULE_THREAD;
849 * @brief interrupt handler
851 * @param context pointer to the interrupt context
854 ocs_pci_intr(void *context)
856 ocs_intr_ctx_t *intr = context;
857 struct ocs_softc *ocs = intr->softc;
859 mtx_lock(&ocs->sim_lock);
860 ocs_hw_process(&ocs->hw, intr->vec, OCS_OS_MAX_ISR_TIME_MSEC);
861 mtx_unlock(&ocs->sim_lock);
865 * @brief Initialize DMA tag
867 * @param ocs the driver instance's software context
869 * @return 0 on success, non-zero otherwise
872 ocs_init_dma_tag(struct ocs_softc *ocs)
874 uint32_t max_sgl = 0;
875 uint32_t max_sge = 0;
878 * IOs can't use the parent DMA tag and must create their
879 * own, based primarily on a restricted number of DMA segments.
880 * This is more of a BSD requirement than a SLI Port requirement
882 ocs_hw_get(&ocs->hw, OCS_HW_N_SGL, &max_sgl);
883 ocs_hw_get(&ocs->hw, OCS_HW_MAX_SGE, &max_sge);
885 if (bus_dma_tag_create(ocs->dmat,
886 1, /* byte alignment */
887 0, /* no boundary restrictions */
888 BUS_SPACE_MAXADDR, /* no minimum low address */
889 BUS_SPACE_MAXADDR, /* no maximum high address */
890 NULL, /* no filter function */
891 NULL, /* or arguments */
892 BUS_SPACE_MAXSIZE, /* max size covered by tag */
893 max_sgl, /* segment count restrictions */
894 max_sge, /* segment length restrictions */
896 NULL, /* no lock manipulation function */
897 NULL, /* or arguments */
899 device_printf(ocs->dev, "%s: bad bus_dma_tag_create(buf_dmat)\n", __func__);
906 ocs_get_property(const char *prop_name, char *buffer, uint32_t buffer_len)
912 * @brief return pointer to ocs structure given instance index
914 * A pointer to an ocs structure is returned given an instance index.
916 * @param index index to ocs_devices array
918 * @return ocs pointer
921 ocs_t *ocs_get_instance(uint32_t index)
923 if (index < ARRAY_SIZE(ocs_devices)) {
924 return ocs_devices[index];
930 * @brief Return instance index of an opaque ocs structure
932 * Returns the ocs instance index
934 * @param os pointer to ocs instance
936 * @return pointer to ocs instance index
939 ocs_instance(void *os)
942 return ocs->instance_index;
945 static device_method_t ocs_methods[] = {
946 DEVMETHOD(device_probe, ocs_pci_probe),
947 DEVMETHOD(device_attach, ocs_pci_attach),
948 DEVMETHOD(device_detach, ocs_pci_detach),
949 DEVMETHOD(device_shutdown, ocs_pci_shutdown),
953 static driver_t ocs_driver = {
956 sizeof(struct ocs_softc)
959 static devclass_t ocs_devclass;
961 DRIVER_MODULE(ocs_fc, pci, ocs_driver, ocs_devclass, 0, 0);
962 MODULE_VERSION(ocs_fc, 1);