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