forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 95099d4622f8cb224d94e314c7a8e0df60b13f87
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,26 @@
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;
149112
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;
152116
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
+ }
161128 }
162129 }
163130
....@@ -208,8 +175,21 @@
208175 return (qla2x00_reset_active(vha) || !vha->hw->flags.fw_started);
209176 }
210177
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
+
211190 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)
213193 {
214194 srb_t *sp = NULL;
215195 uint8_t bail;
....@@ -219,24 +199,22 @@
219199 return NULL;
220200
221201 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
233205 QLA_QPAIR_MARK_NOT_BUSY(qpair);
234206 return sp;
235207 }
236208
209
+void qla2xxx_rel_done_warning(srb_t *sp, int res);
210
+void qla2xxx_rel_free_warning(srb_t *sp);
211
+
237212 static inline void
238213 qla2xxx_rel_qpair_sp(struct qla_qpair *qpair, srb_t *sp)
239214 {
215
+ sp->qpair = NULL;
216
+ sp->done = qla2xxx_rel_done_warning;
217
+ sp->free = qla2xxx_rel_free_warning;
240218 mempool_free(sp, qpair->srb_mempool);
241219 QLA_QPAIR_MARK_NOT_BUSY(qpair);
242220 }
....@@ -246,19 +224,17 @@
246224 {
247225 srb_t *sp = NULL;
248226 uint8_t bail;
227
+ struct qla_qpair *qpair;
249228
250229 QLA_VHA_MARK_BUSY(vha, bail);
251230 if (unlikely(bail))
252231 return NULL;
253232
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);
255235 if (!sp)
256236 goto done;
257237
258
- memset(sp, 0, sizeof(*sp));
259
- sp->fcport = fcport;
260
- sp->cmd_type = TYPE_SRB;
261
- sp->iocbs = 1;
262238 sp->vha = vha;
263239 done:
264240 if (!sp)
....@@ -270,19 +246,7 @@
270246 qla2x00_rel_sp(srb_t *sp)
271247 {
272248 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);
286250 }
287251
288252 static inline int
....@@ -306,24 +270,54 @@
306270 }
307271
308272 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)
310274 {
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);
314308 }
315309
316310 static inline bool
317311 qla_is_exch_offld_enabled(struct scsi_qla_host *vha)
318312 {
319313 if (qla_ini_mode_enabled(vha) &&
320
- (ql2xiniexchg > FW_DEF_EXCHANGES_CNT))
314
+ (vha->ql2xiniexchg > FW_DEF_EXCHANGES_CNT))
321315 return true;
322316 else if (qla_tgt_mode_enabled(vha) &&
323
- (ql2xexchoffld > FW_DEF_EXCHANGES_CNT))
317
+ (vha->ql2xexchoffld > FW_DEF_EXCHANGES_CNT))
324318 return true;
325319 else if (qla_dual_mode_enabled(vha) &&
326
- ((ql2xiniexchg + ql2xexchoffld) > FW_DEF_EXCHANGES_CNT))
320
+ ((vha->ql2xiniexchg + vha->ql2xexchoffld) > FW_DEF_EXCHANGES_CNT))
327321 return true;
328322 else
329323 return false;
....@@ -369,5 +363,72 @@
369363 } else
370364 req->ring_ptr++;
371365
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;
373434 }