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