*/
static int send_tmf(struct afu *afu, struct scsi_cmnd *scp, u64 tmfcmd)
{
- u32 port_sel = scp->device->channel + 1;
struct cxlflash_cfg *cfg = shost_priv(scp->device->host);
struct afu_cmd *cmd = sc_to_afucz(scp);
struct device *dev = &cfg->dev->dev;
cmd->rcb.ctx_id = afu->ctx_hndl;
cmd->rcb.msi = SISL_MSI_RRQ_UPDATED;
- cmd->rcb.port_sel = port_sel;
+ cmd->rcb.port_sel = CHAN2PORTMASK(scp->device->channel);
cmd->rcb.lun_id = lun_to_lunid(scp->device->lun);
cmd->rcb.req_flags = (SISL_REQ_FLAGS_PORT_LUN_ID |
SISL_REQ_FLAGS_SUP_UNDERRUN |
struct device *dev = &cfg->dev->dev;
struct afu_cmd *cmd = sc_to_afucz(scp);
struct scatterlist *sg = scsi_sglist(scp);
- u32 port_sel = scp->device->channel + 1;
u16 req_flags = SISL_REQ_FLAGS_SUP_UNDERRUN;
ulong lock_flags;
int nseg = 0;
cmd->rcb.ctx_id = afu->ctx_hndl;
cmd->rcb.msi = SISL_MSI_RRQ_UPDATED;
- cmd->rcb.port_sel = port_sel;
+ cmd->rcb.port_sel = CHAN2PORTMASK(scp->device->channel);
cmd->rcb.lun_id = lun_to_lunid(scp->device->lun);
if (scp->sc_data_direction == DMA_TO_DEVICE)
writeq_be(PORT0, &afu->afu_map->global.regs.afu_port_sel);
num_ports = 0;
} else {
- writeq_be(BOTH_PORTS, &afu->afu_map->global.regs.afu_port_sel);
+ writeq_be(PORT_MASK(cfg->num_fc_ports),
+ &afu->afu_map->global.regs.afu_port_sel);
num_ports = cfg->num_fc_ports;
}
if (afu->internal_lun)
shost->max_channel = 0;
else
- shost->max_channel = cfg->num_fc_ports - 1;
+ shost->max_channel = PORTNUM2CHAN(cfg->num_fc_ports);
afu_reset(cfg);
scsi_scan_host(cfg->host);
host->max_id = CXLFLASH_MAX_NUM_TARGETS_PER_BUS;
host->max_lun = CXLFLASH_MAX_NUM_LUNS_PER_TARGET;
- host->max_channel = NUM_FC_PORTS - 1;
+ host->max_channel = PORTNUM2CHAN(NUM_FC_PORTS);
host->unique_id = host->host_no;
host->max_cmd_len = CXLFLASH_MAX_CDB_LEN;
void cxlflash_restore_luntable(struct cxlflash_cfg *cfg)
{
struct llun_info *lli, *temp;
- u32 chan;
u32 lind;
+ int k;
struct afu *afu = cfg->afu;
struct device *dev = &cfg->dev->dev;
struct sisl_global_map __iomem *agm = &afu->afu_map->global;
continue;
lind = lli->lun_index;
+ dev_dbg(dev, "%s: Virtual LUNs on slot %d:\n", __func__, lind);
- if (lli->port_sel == BOTH_PORTS) {
- writeq_be(lli->lun_id[0], &agm->fc_port[0][lind]);
- writeq_be(lli->lun_id[1], &agm->fc_port[1][lind]);
- dev_dbg(dev, "%s: Virtual LUN on slot %d id0=%llx "
- "id1=%llx\n", __func__, lind,
- lli->lun_id[0], lli->lun_id[1]);
- } else {
- chan = PORT2CHAN(lli->port_sel);
- writeq_be(lli->lun_id[chan], &agm->fc_port[chan][lind]);
- dev_dbg(dev, "%s: Virtual LUN on slot %d chan=%d "
- "id=%llx\n", __func__, lind, chan,
- lli->lun_id[chan]);
- }
+ for (k = 0; k < cfg->num_fc_ports; k++)
+ if (lli->port_sel & (1 << k)) {
+ writeq_be(lli->lun_id[k],
+ &agm->fc_port[k][lind]);
+ dev_dbg(dev, "\t%d=%llx\n", k, lli->lun_id[k]);
+ }
}
mutex_unlock(&global.mutex);
}
+/**
+ * get_num_ports() - compute number of ports from port selection mask
+ * @psm: Port selection mask.
+ *
+ * Return: Population count of port selection mask
+ */
+static inline u8 get_num_ports(u32 psm)
+{
+ static const u8 bits[16] = { 0, 1, 1, 2, 1, 2, 2, 3,
+ 1, 2, 2, 3, 2, 3, 3, 4 };
+
+ return bits[psm & 0xf];
+}
+
/**
* init_luntable() - write an entry in the LUN table
* @cfg: Internal structure associated with the host.
* @lli: Per adapter LUN information structure.
*
- * On successful return, a LUN table entry is created.
- * At the top for LUNs visible on both ports.
- * At the bottom for LUNs visible only on one port.
+ * On successful return, a LUN table entry is created:
+ * - at the top for LUNs visible on multiple ports.
+ * - at the bottom for LUNs visible only on one port.
*
* Return: 0 on success, -errno on failure
*/
{
u32 chan;
u32 lind;
+ u32 nports;
int rc = 0;
+ int k;
struct afu *afu = cfg->afu;
struct device *dev = &cfg->dev->dev;
struct sisl_global_map __iomem *agm = &afu->afu_map->global;
if (lli->in_table)
goto out;
- if (lli->port_sel == BOTH_PORTS) {
+ nports = get_num_ports(lli->port_sel);
+ if (nports == 0 || nports > cfg->num_fc_ports) {
+ WARN(1, "Unsupported port configuration nports=%u", nports);
+ rc = -EIO;
+ goto out;
+ }
+
+ if (nports > 1) {
/*
- * If this LUN is visible from both ports, we will put
+ * When LUN is visible from multiple ports, we will put
* it in the top half of the LUN table.
*/
- if ((cfg->promote_lun_index == cfg->last_lun_index[0]) ||
- (cfg->promote_lun_index == cfg->last_lun_index[1])) {
- rc = -ENOSPC;
- goto out;
+ for (k = 0; k < cfg->num_fc_ports; k++) {
+ if (!(lli->port_sel & (1 << k)))
+ continue;
+
+ if (cfg->promote_lun_index == cfg->last_lun_index[k]) {
+ rc = -ENOSPC;
+ goto out;
+ }
}
lind = lli->lun_index = cfg->promote_lun_index;
- writeq_be(lli->lun_id[0], &agm->fc_port[0][lind]);
- writeq_be(lli->lun_id[1], &agm->fc_port[1][lind]);
+ dev_dbg(dev, "%s: Virtual LUNs on slot %d:\n", __func__, lind);
+
+ for (k = 0; k < cfg->num_fc_ports; k++) {
+ if (!(lli->port_sel & (1 << k)))
+ continue;
+
+ writeq_be(lli->lun_id[k], &agm->fc_port[k][lind]);
+ dev_dbg(dev, "\t%d=%llx\n", k, lli->lun_id[k]);
+ }
+
cfg->promote_lun_index++;
- dev_dbg(dev, "%s: Virtual LUN on slot %d id0=%llx id1=%llx\n",
- __func__, lind, lli->lun_id[0], lli->lun_id[1]);
} else {
/*
- * If this LUN is visible only from one port, we will put
+ * When LUN is visible only from one port, we will put
* it in the bottom half of the LUN table.
*/
- chan = PORT2CHAN(lli->port_sel);
+ chan = PORTMASK2CHAN(lli->port_sel);
if (cfg->promote_lun_index == cfg->last_lun_index[chan]) {
rc = -ENOSPC;
goto out;
lind = lli->lun_index = cfg->last_lun_index[chan];
writeq_be(lli->lun_id[chan], &agm->fc_port[chan][lind]);
cfg->last_lun_index[chan]--;
- dev_dbg(dev, "%s: Virtual LUN on slot %d chan=%d id=%llx\n",
+ dev_dbg(dev, "%s: Virtual LUNs on slot %d:\n\t%d=%llx\n",
__func__, lind, chan, lli->lun_id[chan]);
}
virt->last_lba = last_lba;
virt->rsrc_handle = rsrc_handle;
- if (lli->port_sel == BOTH_PORTS)
+ if (get_num_ports(lli->port_sel) > 1)
virt->hdr.return_flags |= DK_CXLFLASH_ALL_PORTS_ACTIVE;
out:
if (likely(ctxi))