hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/scsi/qla2xxx/qla_inline.h
....@@ -1,8 +1,7 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
23 * QLogic Fibre Channel HBA Driver
34 * Copyright (c) 2003-2014 QLogic Corporation
4
- *
5
- * See LICENSE.qla2xxx for copyright and licensing details.
65 */
76
87 #include "qla_target.h"
....@@ -11,7 +10,7 @@
1110 * Continuation Type 1 IOCBs to allocate.
1211 *
1312 * @vha: HA context
14
- * @dsds: number of data segment decriptors needed
13
+ * @dsds: number of data segment descriptors needed
1514 *
1615 * Returns the number of IOCB entries needed to store @dsds.
1716 */
....@@ -40,16 +39,16 @@
4039 * register value.
4140 */
4241 static __inline__ uint16_t
43
-qla2x00_debounce_register(volatile uint16_t __iomem *addr)
42
+qla2x00_debounce_register(volatile __le16 __iomem *addr)
4443 {
4544 volatile uint16_t first;
4645 volatile uint16_t second;
4746
4847 do {
49
- first = RD_REG_WORD(addr);
48
+ first = rd_reg_word(addr);
5049 barrier();
5150 cpu_relax();
52
- second = RD_REG_WORD(addr);
51
+ second = rd_reg_word(addr);
5352 } while (first != second);
5453
5554 return (first);
....@@ -91,43 +90,6 @@
9190 }
9291
9392 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
13193 qla2x00_clean_dsd_pool(struct qla_hw_data *ha, struct crc_context *ctx)
13294 {
13395 struct dsd_dma *dsd, *tdsd;
....@@ -143,21 +105,29 @@
143105 }
144106
145107 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)
147109 {
148
- int old_state;
110
+ int old_val;
111
+ uint8_t shiftbits, mask;
112
+ uint8_t port_dstate_str_sz;
149113
150
- old_state = atomic_read(&fcport->state);
151
- atomic_set(&fcport->state, state);
114
+ /* This will have to change when the max no. of states > 16 */
115
+ shiftbits = 4;
116
+ mask = (1 << shiftbits) - 1;
152117
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);
118
+ port_dstate_str_sz = sizeof(port_dstate_str) / sizeof(char *);
119
+ fcport->disc_state = state;
120
+ while (1) {
121
+ old_val = atomic_read(&fcport->shadow_disc_state);
122
+ if (old_val == atomic_cmpxchg(&fcport->shadow_disc_state,
123
+ old_val, (old_val << shiftbits) | state)) {
124
+ ql_dbg(ql_dbg_disc, fcport->vha, 0x2134,
125
+ "FCPort %8phC disc_state transition: %s to %s - portid=%06x.\n",
126
+ fcport->port_name, (old_val & mask) < port_dstate_str_sz ?
127
+ port_dstate_str[old_val & mask] : "Unknown",
128
+ port_dstate_str[state], fcport->d_id.b24);
129
+ return;
130
+ }
161131 }
162132 }
163133
....@@ -208,8 +178,21 @@
208178 return (qla2x00_reset_active(vha) || !vha->hw->flags.fw_started);
209179 }
210180
181
+static void qla2xxx_init_sp(srb_t *sp, scsi_qla_host_t *vha,
182
+ struct qla_qpair *qpair, fc_port_t *fcport)
183
+{
184
+ memset(sp, 0, sizeof(*sp));
185
+ sp->fcport = fcport;
186
+ sp->iocbs = 1;
187
+ sp->vha = vha;
188
+ sp->qpair = qpair;
189
+ sp->cmd_type = TYPE_SRB;
190
+ INIT_LIST_HEAD(&sp->elem);
191
+}
192
+
211193 static inline srb_t *
212
-qla2xxx_get_qpair_sp(struct qla_qpair *qpair, fc_port_t *fcport, gfp_t flag)
194
+qla2xxx_get_qpair_sp(scsi_qla_host_t *vha, struct qla_qpair *qpair,
195
+ fc_port_t *fcport, gfp_t flag)
213196 {
214197 srb_t *sp = NULL;
215198 uint8_t bail;
....@@ -219,24 +202,22 @@
219202 return NULL;
220203
221204 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)
205
+ if (sp)
206
+ qla2xxx_init_sp(sp, vha, qpair, fcport);
207
+ else
233208 QLA_QPAIR_MARK_NOT_BUSY(qpair);
234209 return sp;
235210 }
236211
212
+void qla2xxx_rel_done_warning(srb_t *sp, int res);
213
+void qla2xxx_rel_free_warning(srb_t *sp);
214
+
237215 static inline void
238216 qla2xxx_rel_qpair_sp(struct qla_qpair *qpair, srb_t *sp)
239217 {
218
+ sp->qpair = NULL;
219
+ sp->done = qla2xxx_rel_done_warning;
220
+ sp->free = qla2xxx_rel_free_warning;
240221 mempool_free(sp, qpair->srb_mempool);
241222 QLA_QPAIR_MARK_NOT_BUSY(qpair);
242223 }
....@@ -246,19 +227,17 @@
246227 {
247228 srb_t *sp = NULL;
248229 uint8_t bail;
230
+ struct qla_qpair *qpair;
249231
250232 QLA_VHA_MARK_BUSY(vha, bail);
251233 if (unlikely(bail))
252234 return NULL;
253235
254
- sp = mempool_alloc(vha->hw->srb_mempool, flag);
236
+ qpair = vha->hw->base_qpair;
237
+ sp = qla2xxx_get_qpair_sp(vha, qpair, fcport, flag);
255238 if (!sp)
256239 goto done;
257240
258
- memset(sp, 0, sizeof(*sp));
259
- sp->fcport = fcport;
260
- sp->cmd_type = TYPE_SRB;
261
- sp->iocbs = 1;
262241 sp->vha = vha;
263242 done:
264243 if (!sp)
....@@ -270,19 +249,7 @@
270249 qla2x00_rel_sp(srb_t *sp)
271250 {
272251 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);
252
+ qla2xxx_rel_qpair_sp(sp->qpair, sp);
286253 }
287254
288255 static inline int
....@@ -306,24 +273,54 @@
306273 }
307274
308275 static inline void
309
-qla2x00_set_retry_delay_timestamp(fc_port_t *fcport, uint16_t retry_delay)
276
+qla2x00_set_retry_delay_timestamp(fc_port_t *fcport, uint16_t sts_qual)
310277 {
311
- if (retry_delay)
312
- fcport->retry_delay_timestamp = jiffies +
313
- (retry_delay * HZ / 10);
278
+ u8 scope;
279
+ u16 qual;
280
+#define SQ_SCOPE_MASK 0xc000 /* SAM-6 rev5 5.3.2 */
281
+#define SQ_SCOPE_SHIFT 14
282
+#define SQ_QUAL_MASK 0x3fff
283
+
284
+#define SQ_MAX_WAIT_SEC 60 /* Max I/O hold off time in seconds. */
285
+#define SQ_MAX_WAIT_TIME (SQ_MAX_WAIT_SEC * 10) /* in 100ms. */
286
+
287
+ if (!sts_qual) /* Common case. */
288
+ return;
289
+
290
+ scope = (sts_qual & SQ_SCOPE_MASK) >> SQ_SCOPE_SHIFT;
291
+ /* Handle only scope 1 or 2, which is for I-T nexus. */
292
+ if (scope != 1 && scope != 2)
293
+ return;
294
+
295
+ /* Skip processing, if retry delay timer is already in effect. */
296
+ if (fcport->retry_delay_timestamp &&
297
+ time_before(jiffies, fcport->retry_delay_timestamp))
298
+ return;
299
+
300
+ qual = sts_qual & SQ_QUAL_MASK;
301
+ if (qual < 1 || qual > 0x3fef)
302
+ return;
303
+ qual = min(qual, (u16)SQ_MAX_WAIT_TIME);
304
+
305
+ /* qual is expressed in 100ms increments. */
306
+ fcport->retry_delay_timestamp = jiffies + (qual * HZ / 10);
307
+
308
+ ql_log(ql_log_warn, fcport->vha, 0x5101,
309
+ "%8phC: I/O throttling requested (status qualifier = %04xh), holding off I/Os for %ums.\n",
310
+ fcport->port_name, sts_qual, qual * 100);
314311 }
315312
316313 static inline bool
317314 qla_is_exch_offld_enabled(struct scsi_qla_host *vha)
318315 {
319316 if (qla_ini_mode_enabled(vha) &&
320
- (ql2xiniexchg > FW_DEF_EXCHANGES_CNT))
317
+ (vha->ql2xiniexchg > FW_DEF_EXCHANGES_CNT))
321318 return true;
322319 else if (qla_tgt_mode_enabled(vha) &&
323
- (ql2xexchoffld > FW_DEF_EXCHANGES_CNT))
320
+ (vha->ql2xexchoffld > FW_DEF_EXCHANGES_CNT))
324321 return true;
325322 else if (qla_dual_mode_enabled(vha) &&
326
- ((ql2xiniexchg + ql2xexchoffld) > FW_DEF_EXCHANGES_CNT))
323
+ ((vha->ql2xiniexchg + vha->ql2xexchoffld) > FW_DEF_EXCHANGES_CNT))
327324 return true;
328325 else
329326 return false;
....@@ -369,5 +366,118 @@
369366 } else
370367 req->ring_ptr++;
371368
372
- WRT_REG_DWORD(req->req_q_in, req->ring_index);
369
+ wrt_reg_dword(req->req_q_in, req->ring_index);
370
+}
371
+
372
+static inline int
373
+qla2xxx_get_fc4_priority(struct scsi_qla_host *vha)
374
+{
375
+ uint32_t data;
376
+
377
+ data =
378
+ ((uint8_t *)vha->hw->nvram)[NVRAM_DUAL_FCP_NVME_FLAG_OFFSET];
379
+
380
+
381
+ return (data >> 6) & BIT_0 ? FC4_PRIORITY_FCP : FC4_PRIORITY_NVME;
382
+}
383
+
384
+enum {
385
+ RESOURCE_NONE,
386
+ RESOURCE_INI,
387
+};
388
+
389
+static inline int
390
+qla_get_iocbs(struct qla_qpair *qp, struct iocb_resource *iores)
391
+{
392
+ u16 iocbs_used, i;
393
+ struct qla_hw_data *ha = qp->vha->hw;
394
+
395
+ if (!ql2xenforce_iocb_limit) {
396
+ iores->res_type = RESOURCE_NONE;
397
+ return 0;
398
+ }
399
+
400
+ if ((iores->iocb_cnt + qp->fwres.iocbs_used) < qp->fwres.iocbs_qp_limit) {
401
+ qp->fwres.iocbs_used += iores->iocb_cnt;
402
+ return 0;
403
+ } else {
404
+ /* no need to acquire qpair lock. It's just rough calculation */
405
+ iocbs_used = ha->base_qpair->fwres.iocbs_used;
406
+ for (i = 0; i < ha->max_qpairs; i++) {
407
+ if (ha->queue_pair_map[i])
408
+ iocbs_used += ha->queue_pair_map[i]->fwres.iocbs_used;
409
+ }
410
+
411
+ if ((iores->iocb_cnt + iocbs_used) < qp->fwres.iocbs_limit) {
412
+ qp->fwres.iocbs_used += iores->iocb_cnt;
413
+ return 0;
414
+ } else {
415
+ iores->res_type = RESOURCE_NONE;
416
+ return -ENOSPC;
417
+ }
418
+ }
419
+}
420
+
421
+static inline void
422
+qla_put_iocbs(struct qla_qpair *qp, struct iocb_resource *iores)
423
+{
424
+ switch (iores->res_type) {
425
+ case RESOURCE_NONE:
426
+ break;
427
+ default:
428
+ if (qp->fwres.iocbs_used >= iores->iocb_cnt) {
429
+ qp->fwres.iocbs_used -= iores->iocb_cnt;
430
+ } else {
431
+ // should not happen
432
+ qp->fwres.iocbs_used = 0;
433
+ }
434
+ break;
435
+ }
436
+ iores->res_type = RESOURCE_NONE;
437
+}
438
+
439
+#define ISP_REG_DISCONNECT 0xffffffffU
440
+/**************************************************************************
441
+ * qla2x00_isp_reg_stat
442
+ *
443
+ * Description:
444
+ * Read the host status register of ISP before aborting the command.
445
+ *
446
+ * Input:
447
+ * ha = pointer to host adapter structure.
448
+ *
449
+ *
450
+ * Returns:
451
+ * Either true or false.
452
+ *
453
+ * Note: Return true if there is register disconnect.
454
+ **************************************************************************/
455
+static inline
456
+uint32_t qla2x00_isp_reg_stat(struct qla_hw_data *ha)
457
+{
458
+ struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
459
+ struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
460
+
461
+ if (IS_P3P_TYPE(ha))
462
+ return ((rd_reg_dword(&reg82->host_int)) == ISP_REG_DISCONNECT);
463
+ else
464
+ return ((rd_reg_dword(&reg->host_status)) ==
465
+ ISP_REG_DISCONNECT);
466
+}
467
+
468
+static inline
469
+bool qla_pci_disconnected(struct scsi_qla_host *vha,
470
+ struct device_reg_24xx __iomem *reg)
471
+{
472
+ uint32_t stat;
473
+ bool ret = false;
474
+
475
+ stat = rd_reg_dword(&reg->host_status);
476
+ if (stat == 0xffffffff) {
477
+ ql_log(ql_log_info, vha, 0x8041,
478
+ "detected PCI disconnect.\n");
479
+ qla_schedule_eeh_work(vha);
480
+ ret = true;
481
+ }
482
+ return ret;
373483 }