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