^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * zfcp device driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Setup and helper functions to access QDIO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright IBM Corp. 2002, 2020
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define KMSG_COMPONENT "zfcp"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "zfcp_ext.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "zfcp_qdio.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) static bool enable_multibuffer = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) module_param_named(datarouter, enable_multibuffer, bool, 0400);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) MODULE_PARM_DESC(datarouter, "Enable hardware data router support (default on)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static void zfcp_qdio_handler_error(struct zfcp_qdio *qdio, char *dbftag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) unsigned int qdio_err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct zfcp_adapter *adapter = qdio->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) dev_warn(&adapter->ccw_device->dev, "A QDIO problem occurred\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) if (qdio_err & QDIO_ERROR_SLSB_STATE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) zfcp_qdio_siosl(adapter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) zfcp_erp_adapter_shutdown(adapter, 0, dbftag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) zfcp_erp_adapter_reopen(adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) ZFCP_STATUS_COMMON_ERP_FAILED, dbftag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static void zfcp_qdio_zero_sbals(struct qdio_buffer *sbal[], int first, int cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) int i, sbal_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) for (i = first; i < first + cnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) sbal_idx = i % QDIO_MAX_BUFFERS_PER_Q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) memset(sbal[sbal_idx], 0, sizeof(struct qdio_buffer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) /* this needs to be called prior to updating the queue fill level */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static inline void zfcp_qdio_account(struct zfcp_qdio *qdio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) unsigned long long now, span;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) int used;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) now = get_tod_clock_monotonic();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) span = (now - qdio->req_q_time) >> 12;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) used = QDIO_MAX_BUFFERS_PER_Q - atomic_read(&qdio->req_q_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) qdio->req_q_util += used * span;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) qdio->req_q_time = now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static void zfcp_qdio_int_req(struct ccw_device *cdev, unsigned int qdio_err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) int queue_no, int idx, int count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) unsigned long parm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct zfcp_qdio *qdio = (struct zfcp_qdio *) parm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) if (unlikely(qdio_err)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) zfcp_qdio_handler_error(qdio, "qdireq1", qdio_err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /* cleanup all SBALs being program-owned now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) zfcp_qdio_zero_sbals(qdio->req_q, idx, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) spin_lock_irq(&qdio->stat_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) zfcp_qdio_account(qdio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) spin_unlock_irq(&qdio->stat_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) atomic_add(count, &qdio->req_q_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) wake_up(&qdio->req_q_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) static void zfcp_qdio_int_resp(struct ccw_device *cdev, unsigned int qdio_err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) int queue_no, int idx, int count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) unsigned long parm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) struct zfcp_qdio *qdio = (struct zfcp_qdio *) parm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) struct zfcp_adapter *adapter = qdio->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) int sbal_no, sbal_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) if (unlikely(qdio_err)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) if (zfcp_adapter_multi_buffer_active(adapter)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) void *pl[ZFCP_QDIO_MAX_SBALS_PER_REQ + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct qdio_buffer_element *sbale;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) u64 req_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) u8 scount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) memset(pl, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) ZFCP_QDIO_MAX_SBALS_PER_REQ * sizeof(void *));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) sbale = qdio->res_q[idx]->element;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) req_id = sbale->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) scount = min(sbale->scount + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) ZFCP_QDIO_MAX_SBALS_PER_REQ + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /* incl. signaling SBAL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) for (sbal_no = 0; sbal_no < scount; sbal_no++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) sbal_idx = (idx + sbal_no) %
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) QDIO_MAX_BUFFERS_PER_Q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) pl[sbal_no] = qdio->res_q[sbal_idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) zfcp_dbf_hba_def_err(adapter, req_id, scount, pl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) zfcp_qdio_handler_error(qdio, "qdires1", qdio_err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * go through all SBALs from input queue currently
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * returned by QDIO layer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) for (sbal_no = 0; sbal_no < count; sbal_no++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) sbal_idx = (idx + sbal_no) % QDIO_MAX_BUFFERS_PER_Q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /* go through all SBALEs of SBAL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) zfcp_fsf_reqid_check(qdio, sbal_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * put SBALs back to response queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) if (do_QDIO(cdev, QDIO_FLAG_SYNC_INPUT, 0, idx, count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) zfcp_erp_adapter_reopen(qdio->adapter, 0, "qdires2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static struct qdio_buffer_element *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) zfcp_qdio_sbal_chain(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct qdio_buffer_element *sbale;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) /* set last entry flag in current SBALE of current SBAL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) sbale = zfcp_qdio_sbale_curr(qdio, q_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) sbale->eflags |= SBAL_EFLAGS_LAST_ENTRY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) /* don't exceed last allowed SBAL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) if (q_req->sbal_last == q_req->sbal_limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) /* set chaining flag in first SBALE of current SBAL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) sbale = zfcp_qdio_sbale_req(qdio, q_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) sbale->sflags |= SBAL_SFLAGS0_MORE_SBALS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) /* calculate index of next SBAL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) q_req->sbal_last++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) q_req->sbal_last %= QDIO_MAX_BUFFERS_PER_Q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) /* keep this requests number of SBALs up-to-date */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) q_req->sbal_number++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) BUG_ON(q_req->sbal_number > ZFCP_QDIO_MAX_SBALS_PER_REQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) /* start at first SBALE of new SBAL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) q_req->sbale_curr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) /* set storage-block type for new SBAL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) sbale = zfcp_qdio_sbale_curr(qdio, q_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) sbale->sflags |= q_req->sbtype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) return sbale;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static struct qdio_buffer_element *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) zfcp_qdio_sbale_next(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) if (q_req->sbale_curr == qdio->max_sbale_per_sbal - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) return zfcp_qdio_sbal_chain(qdio, q_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) q_req->sbale_curr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) return zfcp_qdio_sbale_curr(qdio, q_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * zfcp_qdio_sbals_from_sg - fill SBALs from scatter-gather list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) * @qdio: pointer to struct zfcp_qdio
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * @q_req: pointer to struct zfcp_qdio_req
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) * @sg: scatter-gather list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * Returns: zero or -EINVAL on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) int zfcp_qdio_sbals_from_sg(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) struct scatterlist *sg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) struct qdio_buffer_element *sbale;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) /* set storage-block type for this request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) sbale = zfcp_qdio_sbale_req(qdio, q_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) sbale->sflags |= q_req->sbtype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) for (; sg; sg = sg_next(sg)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) sbale = zfcp_qdio_sbale_next(qdio, q_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (!sbale) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) atomic_inc(&qdio->req_q_full);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) zfcp_qdio_zero_sbals(qdio->req_q, q_req->sbal_first,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) q_req->sbal_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) sbale->addr = sg_phys(sg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) sbale->length = sg->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static int zfcp_qdio_sbal_check(struct zfcp_qdio *qdio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) if (atomic_read(&qdio->req_q_free) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) !(atomic_read(&qdio->adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * zfcp_qdio_sbal_get - get free sbal in request queue, wait if necessary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) * @qdio: pointer to struct zfcp_qdio
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * The req_q_lock must be held by the caller of this function, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * this function may only be called from process context; it will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * sleep when waiting for a free sbal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * Returns: 0 on success, -EIO if there is no free sbal after waiting.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) int zfcp_qdio_sbal_get(struct zfcp_qdio *qdio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) long ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) ret = wait_event_interruptible_lock_irq_timeout(qdio->req_q_wq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) zfcp_qdio_sbal_check(qdio), qdio->req_q_lock, 5 * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) if (!(atomic_read(&qdio->adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (ret > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) atomic_inc(&qdio->req_q_full);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) /* assume hanging outbound queue, try queue recovery */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) zfcp_erp_adapter_reopen(qdio->adapter, 0, "qdsbg_1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) * zfcp_qdio_send - send req to QDIO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) * @qdio: pointer to struct zfcp_qdio
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * @q_req: pointer to struct zfcp_qdio_req
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) * Returns: 0 on success, error otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) int zfcp_qdio_send(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) u8 sbal_number = q_req->sbal_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) spin_lock(&qdio->stat_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) zfcp_qdio_account(qdio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) spin_unlock(&qdio->stat_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) atomic_sub(sbal_number, &qdio->req_q_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) retval = do_QDIO(qdio->adapter->ccw_device, QDIO_FLAG_SYNC_OUTPUT, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) q_req->sbal_first, sbal_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) if (unlikely(retval)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) /* Failed to submit the IO, roll back our modifications. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) atomic_add(sbal_number, &qdio->req_q_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) zfcp_qdio_zero_sbals(qdio->req_q, q_req->sbal_first,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) sbal_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) /* account for transferred buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) qdio->req_q_idx += sbal_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) qdio->req_q_idx %= QDIO_MAX_BUFFERS_PER_Q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) * zfcp_qdio_allocate - allocate queue memory and initialize QDIO data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) * @qdio: pointer to struct zfcp_qdio
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) * Returns: -ENOMEM on memory allocation error or return value from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) * qdio_allocate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) static int zfcp_qdio_allocate(struct zfcp_qdio *qdio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) ret = qdio_alloc_buffers(qdio->req_q, QDIO_MAX_BUFFERS_PER_Q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) ret = qdio_alloc_buffers(qdio->res_q, QDIO_MAX_BUFFERS_PER_Q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) goto free_req_q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) init_waitqueue_head(&qdio->req_q_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) ret = qdio_allocate(qdio->adapter->ccw_device, 1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) goto free_res_q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) free_res_q:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) qdio_free_buffers(qdio->res_q, QDIO_MAX_BUFFERS_PER_Q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) free_req_q:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) qdio_free_buffers(qdio->req_q, QDIO_MAX_BUFFERS_PER_Q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) * zfcp_close_qdio - close qdio queues for an adapter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) * @qdio: pointer to structure zfcp_qdio
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) void zfcp_qdio_close(struct zfcp_qdio *qdio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) struct zfcp_adapter *adapter = qdio->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) int idx, count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) /* clear QDIOUP flag, thus do_QDIO is not called during qdio_shutdown */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) spin_lock_irq(&qdio->req_q_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) atomic_andnot(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) spin_unlock_irq(&qdio->req_q_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) wake_up(&qdio->req_q_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) qdio_shutdown(adapter->ccw_device, QDIO_FLAG_CLEANUP_USING_CLEAR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) /* cleanup used outbound sbals */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) count = atomic_read(&qdio->req_q_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) if (count < QDIO_MAX_BUFFERS_PER_Q) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) idx = (qdio->req_q_idx + count) % QDIO_MAX_BUFFERS_PER_Q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) count = QDIO_MAX_BUFFERS_PER_Q - count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) zfcp_qdio_zero_sbals(qdio->req_q, idx, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) qdio->req_q_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) atomic_set(&qdio->req_q_free, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) void zfcp_qdio_shost_update(struct zfcp_adapter *const adapter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) const struct zfcp_qdio *const qdio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) struct Scsi_Host *const shost = adapter->scsi_host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) if (shost == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) shost->sg_tablesize = qdio->max_sbale_per_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) shost->max_sectors = qdio->max_sbale_per_req * 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) * zfcp_qdio_open - prepare and initialize response queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) * @qdio: pointer to struct zfcp_qdio
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) * Returns: 0 on success, otherwise -EIO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) int zfcp_qdio_open(struct zfcp_qdio *qdio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) struct qdio_buffer **input_sbals[1] = {qdio->res_q};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) struct qdio_buffer **output_sbals[1] = {qdio->req_q};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) struct qdio_buffer_element *sbale;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) struct qdio_initialize init_data = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) struct zfcp_adapter *adapter = qdio->adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) struct ccw_device *cdev = adapter->ccw_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) struct qdio_ssqd_desc ssqd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) int cc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) atomic_andnot(ZFCP_STATUS_ADAPTER_SIOSL_ISSUED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) &qdio->adapter->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) init_data.q_format = QDIO_ZFCP_QFMT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) init_data.qib_rflags = QIB_RFLAGS_ENABLE_DATA_DIV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) if (enable_multibuffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) init_data.qdr_ac |= QDR_AC_MULTI_BUFFER_ENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) init_data.no_input_qs = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) init_data.no_output_qs = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) init_data.input_handler = zfcp_qdio_int_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) init_data.output_handler = zfcp_qdio_int_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) init_data.int_parm = (unsigned long) qdio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) init_data.input_sbal_addr_array = input_sbals;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) init_data.output_sbal_addr_array = output_sbals;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) init_data.scan_threshold =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) QDIO_MAX_BUFFERS_PER_Q - ZFCP_QDIO_MAX_SBALS_PER_REQ * 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) if (qdio_establish(cdev, &init_data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) goto failed_establish;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) if (qdio_get_ssqd_desc(cdev, &ssqd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) goto failed_qdio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) if (ssqd.qdioac2 & CHSC_AC2_DATA_DIV_ENABLED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) atomic_or(ZFCP_STATUS_ADAPTER_DATA_DIV_ENABLED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) &qdio->adapter->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) if (ssqd.qdioac2 & CHSC_AC2_MULTI_BUFFER_ENABLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) atomic_or(ZFCP_STATUS_ADAPTER_MB_ACT, &adapter->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) qdio->max_sbale_per_sbal = QDIO_MAX_ELEMENTS_PER_BUFFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) atomic_andnot(ZFCP_STATUS_ADAPTER_MB_ACT, &adapter->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) qdio->max_sbale_per_sbal = QDIO_MAX_ELEMENTS_PER_BUFFER - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) qdio->max_sbale_per_req =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) ZFCP_QDIO_MAX_SBALS_PER_REQ * qdio->max_sbale_per_sbal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) - 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) if (qdio_activate(cdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) goto failed_qdio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) for (cc = 0; cc < QDIO_MAX_BUFFERS_PER_Q; cc++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) sbale = &(qdio->res_q[cc]->element[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) sbale->length = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) sbale->eflags = SBAL_EFLAGS_LAST_ENTRY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) sbale->sflags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) sbale->addr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) if (do_QDIO(cdev, QDIO_FLAG_SYNC_INPUT, 0, 0, QDIO_MAX_BUFFERS_PER_Q))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) goto failed_qdio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) /* set index of first available SBALS / number of available SBALS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) qdio->req_q_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) atomic_set(&qdio->req_q_free, QDIO_MAX_BUFFERS_PER_Q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) atomic_or(ZFCP_STATUS_ADAPTER_QDIOUP, &qdio->adapter->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) zfcp_qdio_shost_update(adapter, qdio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) failed_qdio:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) failed_establish:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) dev_err(&cdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) "Setting up the QDIO connection to the FCP adapter failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) void zfcp_qdio_destroy(struct zfcp_qdio *qdio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) if (!qdio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) if (qdio->adapter->ccw_device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) qdio_free(qdio->adapter->ccw_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) qdio_free_buffers(qdio->req_q, QDIO_MAX_BUFFERS_PER_Q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) qdio_free_buffers(qdio->res_q, QDIO_MAX_BUFFERS_PER_Q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) kfree(qdio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) int zfcp_qdio_setup(struct zfcp_adapter *adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) struct zfcp_qdio *qdio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) qdio = kzalloc(sizeof(struct zfcp_qdio), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) if (!qdio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) qdio->adapter = adapter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) if (zfcp_qdio_allocate(qdio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) kfree(qdio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) spin_lock_init(&qdio->req_q_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) spin_lock_init(&qdio->stat_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) adapter->qdio = qdio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) * zfcp_qdio_siosl - Trigger logging in FCP channel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) * @adapter: The zfcp_adapter where to trigger logging
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) * Call the cio siosl function to trigger hardware logging. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) * wrapper function sets a flag to ensure hardware logging is only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) * triggered once before going through qdio shutdown.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) * The triggers are always run from qdio tasklet context, so no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) * additional synchronization is necessary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) void zfcp_qdio_siosl(struct zfcp_adapter *adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_SIOSL_ISSUED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) rc = ccw_device_siosl(adapter->ccw_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) if (!rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) atomic_or(ZFCP_STATUS_ADAPTER_SIOSL_ISSUED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) &adapter->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) }