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