| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * QLogic Fibre Channel HBA Driver |
|---|
| 3 | 4 | * Copyright (c) 2003-2014 QLogic Corporation |
|---|
| 4 | | - * |
|---|
| 5 | | - * See LICENSE.qla2xxx for copyright and licensing details. |
|---|
| 6 | 5 | */ |
|---|
| 7 | 6 | |
|---|
| 8 | 7 | #include "qla_target.h" |
|---|
| .. | .. |
|---|
| 11 | 10 | * Continuation Type 1 IOCBs to allocate. |
|---|
| 12 | 11 | * |
|---|
| 13 | 12 | * @vha: HA context |
|---|
| 14 | | - * @dsds: number of data segment decriptors needed |
|---|
| 13 | + * @dsds: number of data segment descriptors needed |
|---|
| 15 | 14 | * |
|---|
| 16 | 15 | * Returns the number of IOCB entries needed to store @dsds. |
|---|
| 17 | 16 | */ |
|---|
| .. | .. |
|---|
| 40 | 39 | * register value. |
|---|
| 41 | 40 | */ |
|---|
| 42 | 41 | static __inline__ uint16_t |
|---|
| 43 | | -qla2x00_debounce_register(volatile uint16_t __iomem *addr) |
|---|
| 42 | +qla2x00_debounce_register(volatile __le16 __iomem *addr) |
|---|
| 44 | 43 | { |
|---|
| 45 | 44 | volatile uint16_t first; |
|---|
| 46 | 45 | volatile uint16_t second; |
|---|
| 47 | 46 | |
|---|
| 48 | 47 | do { |
|---|
| 49 | | - first = RD_REG_WORD(addr); |
|---|
| 48 | + first = rd_reg_word(addr); |
|---|
| 50 | 49 | barrier(); |
|---|
| 51 | 50 | cpu_relax(); |
|---|
| 52 | | - second = RD_REG_WORD(addr); |
|---|
| 51 | + second = rd_reg_word(addr); |
|---|
| 53 | 52 | } while (first != second); |
|---|
| 54 | 53 | |
|---|
| 55 | 54 | return (first); |
|---|
| .. | .. |
|---|
| 91 | 90 | } |
|---|
| 92 | 91 | |
|---|
| 93 | 92 | static inline void |
|---|
| 94 | | -qla2x00_set_reserved_loop_ids(struct qla_hw_data *ha) |
|---|
| 95 | | -{ |
|---|
| 96 | | - int i; |
|---|
| 97 | | - |
|---|
| 98 | | - if (IS_FWI2_CAPABLE(ha)) |
|---|
| 99 | | - return; |
|---|
| 100 | | - |
|---|
| 101 | | - for (i = 0; i < SNS_FIRST_LOOP_ID; i++) |
|---|
| 102 | | - set_bit(i, ha->loop_id_map); |
|---|
| 103 | | - set_bit(MANAGEMENT_SERVER, ha->loop_id_map); |
|---|
| 104 | | - set_bit(BROADCAST, ha->loop_id_map); |
|---|
| 105 | | -} |
|---|
| 106 | | - |
|---|
| 107 | | -static inline int |
|---|
| 108 | | -qla2x00_is_reserved_id(scsi_qla_host_t *vha, uint16_t loop_id) |
|---|
| 109 | | -{ |
|---|
| 110 | | - struct qla_hw_data *ha = vha->hw; |
|---|
| 111 | | - if (IS_FWI2_CAPABLE(ha)) |
|---|
| 112 | | - return (loop_id > NPH_LAST_HANDLE); |
|---|
| 113 | | - |
|---|
| 114 | | - return ((loop_id > ha->max_loop_id && loop_id < SNS_FIRST_LOOP_ID) || |
|---|
| 115 | | - loop_id == MANAGEMENT_SERVER || loop_id == BROADCAST); |
|---|
| 116 | | -} |
|---|
| 117 | | - |
|---|
| 118 | | -static inline void |
|---|
| 119 | | -qla2x00_clear_loop_id(fc_port_t *fcport) { |
|---|
| 120 | | - struct qla_hw_data *ha = fcport->vha->hw; |
|---|
| 121 | | - |
|---|
| 122 | | - if (fcport->loop_id == FC_NO_LOOP_ID || |
|---|
| 123 | | - qla2x00_is_reserved_id(fcport->vha, fcport->loop_id)) |
|---|
| 124 | | - return; |
|---|
| 125 | | - |
|---|
| 126 | | - clear_bit(fcport->loop_id, ha->loop_id_map); |
|---|
| 127 | | - fcport->loop_id = FC_NO_LOOP_ID; |
|---|
| 128 | | -} |
|---|
| 129 | | - |
|---|
| 130 | | -static inline void |
|---|
| 131 | 93 | qla2x00_clean_dsd_pool(struct qla_hw_data *ha, struct crc_context *ctx) |
|---|
| 132 | 94 | { |
|---|
| 133 | 95 | struct dsd_dma *dsd, *tdsd; |
|---|
| .. | .. |
|---|
| 143 | 105 | } |
|---|
| 144 | 106 | |
|---|
| 145 | 107 | static inline void |
|---|
| 146 | | -qla2x00_set_fcport_state(fc_port_t *fcport, int state) |
|---|
| 108 | +qla2x00_set_fcport_disc_state(fc_port_t *fcport, int state) |
|---|
| 147 | 109 | { |
|---|
| 148 | | - int old_state; |
|---|
| 110 | + int old_val; |
|---|
| 111 | + uint8_t shiftbits, mask; |
|---|
| 149 | 112 | |
|---|
| 150 | | - old_state = atomic_read(&fcport->state); |
|---|
| 151 | | - atomic_set(&fcport->state, state); |
|---|
| 113 | + /* This will have to change when the max no. of states > 16 */ |
|---|
| 114 | + shiftbits = 4; |
|---|
| 115 | + mask = (1 << shiftbits) - 1; |
|---|
| 152 | 116 | |
|---|
| 153 | | - /* Don't print state transitions during initial allocation of fcport */ |
|---|
| 154 | | - if (old_state && old_state != state) { |
|---|
| 155 | | - ql_dbg(ql_dbg_disc, fcport->vha, 0x207d, |
|---|
| 156 | | - "FCPort %8phC state transitioned from %s to %s - " |
|---|
| 157 | | - "portid=%02x%02x%02x.\n", fcport->port_name, |
|---|
| 158 | | - port_state_str[old_state], port_state_str[state], |
|---|
| 159 | | - fcport->d_id.b.domain, fcport->d_id.b.area, |
|---|
| 160 | | - fcport->d_id.b.al_pa); |
|---|
| 117 | + fcport->disc_state = state; |
|---|
| 118 | + while (1) { |
|---|
| 119 | + old_val = atomic_read(&fcport->shadow_disc_state); |
|---|
| 120 | + if (old_val == atomic_cmpxchg(&fcport->shadow_disc_state, |
|---|
| 121 | + old_val, (old_val << shiftbits) | state)) { |
|---|
| 122 | + ql_dbg(ql_dbg_disc, fcport->vha, 0x2134, |
|---|
| 123 | + "FCPort %8phC disc_state transition: %s to %s - portid=%06x.\n", |
|---|
| 124 | + fcport->port_name, port_dstate_str[old_val & mask], |
|---|
| 125 | + port_dstate_str[state], fcport->d_id.b24); |
|---|
| 126 | + return; |
|---|
| 127 | + } |
|---|
| 161 | 128 | } |
|---|
| 162 | 129 | } |
|---|
| 163 | 130 | |
|---|
| .. | .. |
|---|
| 208 | 175 | return (qla2x00_reset_active(vha) || !vha->hw->flags.fw_started); |
|---|
| 209 | 176 | } |
|---|
| 210 | 177 | |
|---|
| 178 | +static void qla2xxx_init_sp(srb_t *sp, scsi_qla_host_t *vha, |
|---|
| 179 | + struct qla_qpair *qpair, fc_port_t *fcport) |
|---|
| 180 | +{ |
|---|
| 181 | + memset(sp, 0, sizeof(*sp)); |
|---|
| 182 | + sp->fcport = fcport; |
|---|
| 183 | + sp->iocbs = 1; |
|---|
| 184 | + sp->vha = vha; |
|---|
| 185 | + sp->qpair = qpair; |
|---|
| 186 | + sp->cmd_type = TYPE_SRB; |
|---|
| 187 | + INIT_LIST_HEAD(&sp->elem); |
|---|
| 188 | +} |
|---|
| 189 | + |
|---|
| 211 | 190 | static inline srb_t * |
|---|
| 212 | | -qla2xxx_get_qpair_sp(struct qla_qpair *qpair, fc_port_t *fcport, gfp_t flag) |
|---|
| 191 | +qla2xxx_get_qpair_sp(scsi_qla_host_t *vha, struct qla_qpair *qpair, |
|---|
| 192 | + fc_port_t *fcport, gfp_t flag) |
|---|
| 213 | 193 | { |
|---|
| 214 | 194 | srb_t *sp = NULL; |
|---|
| 215 | 195 | uint8_t bail; |
|---|
| .. | .. |
|---|
| 219 | 199 | return NULL; |
|---|
| 220 | 200 | |
|---|
| 221 | 201 | sp = mempool_alloc(qpair->srb_mempool, flag); |
|---|
| 222 | | - if (!sp) |
|---|
| 223 | | - goto done; |
|---|
| 224 | | - |
|---|
| 225 | | - memset(sp, 0, sizeof(*sp)); |
|---|
| 226 | | - sp->fcport = fcport; |
|---|
| 227 | | - sp->iocbs = 1; |
|---|
| 228 | | - sp->vha = qpair->vha; |
|---|
| 229 | | - INIT_LIST_HEAD(&sp->elem); |
|---|
| 230 | | - |
|---|
| 231 | | -done: |
|---|
| 232 | | - if (!sp) |
|---|
| 202 | + if (sp) |
|---|
| 203 | + qla2xxx_init_sp(sp, vha, qpair, fcport); |
|---|
| 204 | + else |
|---|
| 233 | 205 | QLA_QPAIR_MARK_NOT_BUSY(qpair); |
|---|
| 234 | 206 | return sp; |
|---|
| 235 | 207 | } |
|---|
| 236 | 208 | |
|---|
| 209 | +void qla2xxx_rel_done_warning(srb_t *sp, int res); |
|---|
| 210 | +void qla2xxx_rel_free_warning(srb_t *sp); |
|---|
| 211 | + |
|---|
| 237 | 212 | static inline void |
|---|
| 238 | 213 | qla2xxx_rel_qpair_sp(struct qla_qpair *qpair, srb_t *sp) |
|---|
| 239 | 214 | { |
|---|
| 215 | + sp->qpair = NULL; |
|---|
| 216 | + sp->done = qla2xxx_rel_done_warning; |
|---|
| 217 | + sp->free = qla2xxx_rel_free_warning; |
|---|
| 240 | 218 | mempool_free(sp, qpair->srb_mempool); |
|---|
| 241 | 219 | QLA_QPAIR_MARK_NOT_BUSY(qpair); |
|---|
| 242 | 220 | } |
|---|
| .. | .. |
|---|
| 246 | 224 | { |
|---|
| 247 | 225 | srb_t *sp = NULL; |
|---|
| 248 | 226 | uint8_t bail; |
|---|
| 227 | + struct qla_qpair *qpair; |
|---|
| 249 | 228 | |
|---|
| 250 | 229 | QLA_VHA_MARK_BUSY(vha, bail); |
|---|
| 251 | 230 | if (unlikely(bail)) |
|---|
| 252 | 231 | return NULL; |
|---|
| 253 | 232 | |
|---|
| 254 | | - sp = mempool_alloc(vha->hw->srb_mempool, flag); |
|---|
| 233 | + qpair = vha->hw->base_qpair; |
|---|
| 234 | + sp = qla2xxx_get_qpair_sp(vha, qpair, fcport, flag); |
|---|
| 255 | 235 | if (!sp) |
|---|
| 256 | 236 | goto done; |
|---|
| 257 | 237 | |
|---|
| 258 | | - memset(sp, 0, sizeof(*sp)); |
|---|
| 259 | | - sp->fcport = fcport; |
|---|
| 260 | | - sp->cmd_type = TYPE_SRB; |
|---|
| 261 | | - sp->iocbs = 1; |
|---|
| 262 | 238 | sp->vha = vha; |
|---|
| 263 | 239 | done: |
|---|
| 264 | 240 | if (!sp) |
|---|
| .. | .. |
|---|
| 270 | 246 | qla2x00_rel_sp(srb_t *sp) |
|---|
| 271 | 247 | { |
|---|
| 272 | 248 | QLA_VHA_MARK_NOT_BUSY(sp->vha); |
|---|
| 273 | | - mempool_free(sp, sp->vha->hw->srb_mempool); |
|---|
| 274 | | -} |
|---|
| 275 | | - |
|---|
| 276 | | -static inline void |
|---|
| 277 | | -qla2x00_init_timer(srb_t *sp, unsigned long tmo) |
|---|
| 278 | | -{ |
|---|
| 279 | | - timer_setup(&sp->u.iocb_cmd.timer, qla2x00_sp_timeout, 0); |
|---|
| 280 | | - sp->u.iocb_cmd.timer.expires = jiffies + tmo * HZ; |
|---|
| 281 | | - sp->free = qla2x00_sp_free; |
|---|
| 282 | | - init_completion(&sp->comp); |
|---|
| 283 | | - if (IS_QLAFX00(sp->vha->hw) && (sp->type == SRB_FXIOCB_DCMD)) |
|---|
| 284 | | - init_completion(&sp->u.iocb_cmd.u.fxiocb.fxiocb_comp); |
|---|
| 285 | | - add_timer(&sp->u.iocb_cmd.timer); |
|---|
| 249 | + qla2xxx_rel_qpair_sp(sp->qpair, sp); |
|---|
| 286 | 250 | } |
|---|
| 287 | 251 | |
|---|
| 288 | 252 | static inline int |
|---|
| .. | .. |
|---|
| 306 | 270 | } |
|---|
| 307 | 271 | |
|---|
| 308 | 272 | static inline void |
|---|
| 309 | | -qla2x00_set_retry_delay_timestamp(fc_port_t *fcport, uint16_t retry_delay) |
|---|
| 273 | +qla2x00_set_retry_delay_timestamp(fc_port_t *fcport, uint16_t sts_qual) |
|---|
| 310 | 274 | { |
|---|
| 311 | | - if (retry_delay) |
|---|
| 312 | | - fcport->retry_delay_timestamp = jiffies + |
|---|
| 313 | | - (retry_delay * HZ / 10); |
|---|
| 275 | + u8 scope; |
|---|
| 276 | + u16 qual; |
|---|
| 277 | +#define SQ_SCOPE_MASK 0xc000 /* SAM-6 rev5 5.3.2 */ |
|---|
| 278 | +#define SQ_SCOPE_SHIFT 14 |
|---|
| 279 | +#define SQ_QUAL_MASK 0x3fff |
|---|
| 280 | + |
|---|
| 281 | +#define SQ_MAX_WAIT_SEC 60 /* Max I/O hold off time in seconds. */ |
|---|
| 282 | +#define SQ_MAX_WAIT_TIME (SQ_MAX_WAIT_SEC * 10) /* in 100ms. */ |
|---|
| 283 | + |
|---|
| 284 | + if (!sts_qual) /* Common case. */ |
|---|
| 285 | + return; |
|---|
| 286 | + |
|---|
| 287 | + scope = (sts_qual & SQ_SCOPE_MASK) >> SQ_SCOPE_SHIFT; |
|---|
| 288 | + /* Handle only scope 1 or 2, which is for I-T nexus. */ |
|---|
| 289 | + if (scope != 1 && scope != 2) |
|---|
| 290 | + return; |
|---|
| 291 | + |
|---|
| 292 | + /* Skip processing, if retry delay timer is already in effect. */ |
|---|
| 293 | + if (fcport->retry_delay_timestamp && |
|---|
| 294 | + time_before(jiffies, fcport->retry_delay_timestamp)) |
|---|
| 295 | + return; |
|---|
| 296 | + |
|---|
| 297 | + qual = sts_qual & SQ_QUAL_MASK; |
|---|
| 298 | + if (qual < 1 || qual > 0x3fef) |
|---|
| 299 | + return; |
|---|
| 300 | + qual = min(qual, (u16)SQ_MAX_WAIT_TIME); |
|---|
| 301 | + |
|---|
| 302 | + /* qual is expressed in 100ms increments. */ |
|---|
| 303 | + fcport->retry_delay_timestamp = jiffies + (qual * HZ / 10); |
|---|
| 304 | + |
|---|
| 305 | + ql_log(ql_log_warn, fcport->vha, 0x5101, |
|---|
| 306 | + "%8phC: I/O throttling requested (status qualifier = %04xh), holding off I/Os for %ums.\n", |
|---|
| 307 | + fcport->port_name, sts_qual, qual * 100); |
|---|
| 314 | 308 | } |
|---|
| 315 | 309 | |
|---|
| 316 | 310 | static inline bool |
|---|
| 317 | 311 | qla_is_exch_offld_enabled(struct scsi_qla_host *vha) |
|---|
| 318 | 312 | { |
|---|
| 319 | 313 | if (qla_ini_mode_enabled(vha) && |
|---|
| 320 | | - (ql2xiniexchg > FW_DEF_EXCHANGES_CNT)) |
|---|
| 314 | + (vha->ql2xiniexchg > FW_DEF_EXCHANGES_CNT)) |
|---|
| 321 | 315 | return true; |
|---|
| 322 | 316 | else if (qla_tgt_mode_enabled(vha) && |
|---|
| 323 | | - (ql2xexchoffld > FW_DEF_EXCHANGES_CNT)) |
|---|
| 317 | + (vha->ql2xexchoffld > FW_DEF_EXCHANGES_CNT)) |
|---|
| 324 | 318 | return true; |
|---|
| 325 | 319 | else if (qla_dual_mode_enabled(vha) && |
|---|
| 326 | | - ((ql2xiniexchg + ql2xexchoffld) > FW_DEF_EXCHANGES_CNT)) |
|---|
| 320 | + ((vha->ql2xiniexchg + vha->ql2xexchoffld) > FW_DEF_EXCHANGES_CNT)) |
|---|
| 327 | 321 | return true; |
|---|
| 328 | 322 | else |
|---|
| 329 | 323 | return false; |
|---|
| .. | .. |
|---|
| 369 | 363 | } else |
|---|
| 370 | 364 | req->ring_ptr++; |
|---|
| 371 | 365 | |
|---|
| 372 | | - WRT_REG_DWORD(req->req_q_in, req->ring_index); |
|---|
| 366 | + wrt_reg_dword(req->req_q_in, req->ring_index); |
|---|
| 367 | +} |
|---|
| 368 | + |
|---|
| 369 | +static inline int |
|---|
| 370 | +qla2xxx_get_fc4_priority(struct scsi_qla_host *vha) |
|---|
| 371 | +{ |
|---|
| 372 | + uint32_t data; |
|---|
| 373 | + |
|---|
| 374 | + data = |
|---|
| 375 | + ((uint8_t *)vha->hw->nvram)[NVRAM_DUAL_FCP_NVME_FLAG_OFFSET]; |
|---|
| 376 | + |
|---|
| 377 | + |
|---|
| 378 | + return (data >> 6) & BIT_0 ? FC4_PRIORITY_FCP : FC4_PRIORITY_NVME; |
|---|
| 379 | +} |
|---|
| 380 | + |
|---|
| 381 | +enum { |
|---|
| 382 | + RESOURCE_NONE, |
|---|
| 383 | + RESOURCE_INI, |
|---|
| 384 | +}; |
|---|
| 385 | + |
|---|
| 386 | +static inline int |
|---|
| 387 | +qla_get_iocbs(struct qla_qpair *qp, struct iocb_resource *iores) |
|---|
| 388 | +{ |
|---|
| 389 | + u16 iocbs_used, i; |
|---|
| 390 | + struct qla_hw_data *ha = qp->vha->hw; |
|---|
| 391 | + |
|---|
| 392 | + if (!ql2xenforce_iocb_limit) { |
|---|
| 393 | + iores->res_type = RESOURCE_NONE; |
|---|
| 394 | + return 0; |
|---|
| 395 | + } |
|---|
| 396 | + |
|---|
| 397 | + if ((iores->iocb_cnt + qp->fwres.iocbs_used) < qp->fwres.iocbs_qp_limit) { |
|---|
| 398 | + qp->fwres.iocbs_used += iores->iocb_cnt; |
|---|
| 399 | + return 0; |
|---|
| 400 | + } else { |
|---|
| 401 | + /* no need to acquire qpair lock. It's just rough calculation */ |
|---|
| 402 | + iocbs_used = ha->base_qpair->fwres.iocbs_used; |
|---|
| 403 | + for (i = 0; i < ha->max_qpairs; i++) { |
|---|
| 404 | + if (ha->queue_pair_map[i]) |
|---|
| 405 | + iocbs_used += ha->queue_pair_map[i]->fwres.iocbs_used; |
|---|
| 406 | + } |
|---|
| 407 | + |
|---|
| 408 | + if ((iores->iocb_cnt + iocbs_used) < qp->fwres.iocbs_limit) { |
|---|
| 409 | + qp->fwres.iocbs_used += iores->iocb_cnt; |
|---|
| 410 | + return 0; |
|---|
| 411 | + } else { |
|---|
| 412 | + iores->res_type = RESOURCE_NONE; |
|---|
| 413 | + return -ENOSPC; |
|---|
| 414 | + } |
|---|
| 415 | + } |
|---|
| 416 | +} |
|---|
| 417 | + |
|---|
| 418 | +static inline void |
|---|
| 419 | +qla_put_iocbs(struct qla_qpair *qp, struct iocb_resource *iores) |
|---|
| 420 | +{ |
|---|
| 421 | + switch (iores->res_type) { |
|---|
| 422 | + case RESOURCE_NONE: |
|---|
| 423 | + break; |
|---|
| 424 | + default: |
|---|
| 425 | + if (qp->fwres.iocbs_used >= iores->iocb_cnt) { |
|---|
| 426 | + qp->fwres.iocbs_used -= iores->iocb_cnt; |
|---|
| 427 | + } else { |
|---|
| 428 | + // should not happen |
|---|
| 429 | + qp->fwres.iocbs_used = 0; |
|---|
| 430 | + } |
|---|
| 431 | + break; |
|---|
| 432 | + } |
|---|
| 433 | + iores->res_type = RESOURCE_NONE; |
|---|
| 373 | 434 | } |
|---|