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 | * |
Swen Schillig | 42428f7 | 2009-08-18 15:43:18 +0200 | [diff] [blame] | 6 | * Copyright IBM Corporation 2002, 2009 |
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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include "zfcp_ext.h" |
| 13 | |
Christof Schmitt | 5d4e226 | 2008-07-02 10:56:34 +0200 | [diff] [blame] | 14 | #define QBUFF_PER_PAGE (PAGE_SIZE / sizeof(struct qdio_buffer)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 16 | static int zfcp_qdio_buffers_enqueue(struct qdio_buffer **sbal) |
Swen Schillig | b4e4459 | 2007-07-18 10:55:13 +0200 | [diff] [blame] | 17 | { |
| 18 | int pos; |
| 19 | |
| 20 | 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] | 21 | sbal[pos] = (struct qdio_buffer *) get_zeroed_page(GFP_KERNEL); |
| 22 | if (!sbal[pos]) |
Swen Schillig | b4e4459 | 2007-07-18 10:55:13 +0200 | [diff] [blame] | 23 | return -ENOMEM; |
Swen Schillig | b4e4459 | 2007-07-18 10:55:13 +0200 | [diff] [blame] | 24 | } |
| 25 | for (pos = 0; pos < QDIO_MAX_BUFFERS_PER_Q; pos++) |
| 26 | if (pos % QBUFF_PER_PAGE) |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 27 | sbal[pos] = sbal[pos - 1] + 1; |
Swen Schillig | b4e4459 | 2007-07-18 10:55:13 +0200 | [diff] [blame] | 28 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | } |
| 30 | |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 31 | static struct qdio_buffer_element * |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 32 | zfcp_qdio_sbale(struct zfcp_qdio_queue *q, int sbal_idx, int sbale_idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | { |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 34 | return &q->sbal[sbal_idx]->element[sbale_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | } |
| 36 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 37 | static void zfcp_qdio_handler_error(struct zfcp_qdio *qdio, char *id) |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 38 | { |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 39 | struct zfcp_adapter *adapter = qdio->adapter; |
| 40 | |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 41 | dev_warn(&adapter->ccw_device->dev, "A QDIO problem occurred\n"); |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 42 | |
| 43 | zfcp_erp_adapter_reopen(adapter, |
| 44 | ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED | |
| 45 | ZFCP_STATUS_COMMON_ERP_FAILED, id, NULL); |
| 46 | } |
| 47 | |
Christof Schmitt | 5d4e226 | 2008-07-02 10:56:34 +0200 | [diff] [blame] | 48 | static void zfcp_qdio_zero_sbals(struct qdio_buffer *sbal[], int first, int cnt) |
| 49 | { |
| 50 | int i, sbal_idx; |
| 51 | |
| 52 | for (i = first; i < first + cnt; i++) { |
| 53 | sbal_idx = i % QDIO_MAX_BUFFERS_PER_Q; |
| 54 | memset(sbal[sbal_idx], 0, sizeof(struct qdio_buffer)); |
| 55 | } |
| 56 | } |
| 57 | |
Martin Peschke | 94506fd | 2009-03-02 13:08:56 +0100 | [diff] [blame] | 58 | /* this needs to be called prior to updating the queue fill level */ |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 59 | static void zfcp_qdio_account(struct zfcp_qdio *qdio) |
Martin Peschke | 94506fd | 2009-03-02 13:08:56 +0100 | [diff] [blame] | 60 | { |
| 61 | ktime_t now; |
| 62 | s64 span; |
| 63 | int free, used; |
| 64 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 65 | spin_lock(&qdio->stat_lock); |
Martin Peschke | 94506fd | 2009-03-02 13:08:56 +0100 | [diff] [blame] | 66 | now = ktime_get(); |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 67 | span = ktime_us_delta(now, qdio->req_q_time); |
| 68 | free = max(0, atomic_read(&qdio->req_q.count)); |
Martin Peschke | 94506fd | 2009-03-02 13:08:56 +0100 | [diff] [blame] | 69 | used = QDIO_MAX_BUFFERS_PER_Q - free; |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 70 | qdio->req_q_util += used * span; |
| 71 | qdio->req_q_time = now; |
| 72 | spin_unlock(&qdio->stat_lock); |
Martin Peschke | 94506fd | 2009-03-02 13:08:56 +0100 | [diff] [blame] | 73 | } |
| 74 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 75 | static void zfcp_qdio_int_req(struct ccw_device *cdev, unsigned int qdio_err, |
| 76 | int queue_no, int first, int count, |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 77 | unsigned long parm) |
| 78 | { |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 79 | struct zfcp_qdio *qdio = (struct zfcp_qdio *) parm; |
| 80 | struct zfcp_qdio_queue *queue = &qdio->req_q; |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 81 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 82 | if (unlikely(qdio_err)) { |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 83 | zfcp_dbf_hba_qdio(qdio->adapter->dbf, qdio_err, first, |
| 84 | count); |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 85 | zfcp_qdio_handler_error(qdio, "qdireq1"); |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 86 | return; |
| 87 | } |
| 88 | |
| 89 | /* cleanup all SBALs being program-owned now */ |
| 90 | zfcp_qdio_zero_sbals(queue->sbal, first, count); |
| 91 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 92 | zfcp_qdio_account(qdio); |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 93 | atomic_add(count, &queue->count); |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 94 | wake_up(&qdio->req_q_wq); |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 95 | } |
| 96 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 97 | static void zfcp_qdio_resp_put_back(struct zfcp_qdio *qdio, int processed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | { |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 99 | struct zfcp_qdio_queue *queue = &qdio->resp_q; |
| 100 | struct ccw_device *cdev = qdio->adapter->ccw_device; |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 101 | u8 count, start = queue->first; |
| 102 | unsigned int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 104 | count = atomic_read(&queue->count) + processed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 106 | retval = do_QDIO(cdev, QDIO_FLAG_SYNC_INPUT, 0, start, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 108 | if (unlikely(retval)) { |
| 109 | atomic_set(&queue->count, count); |
| 110 | /* FIXME: Recover this with an adapter reopen? */ |
| 111 | } else { |
| 112 | queue->first += count; |
| 113 | queue->first %= QDIO_MAX_BUFFERS_PER_Q; |
| 114 | atomic_set(&queue->count, 0); |
| 115 | } |
| 116 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 118 | static void zfcp_qdio_int_resp(struct ccw_device *cdev, unsigned int qdio_err, |
| 119 | int queue_no, int first, int count, |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 120 | unsigned long parm) |
| 121 | { |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 122 | struct zfcp_qdio *qdio = (struct zfcp_qdio *) parm; |
Swen Schillig | bd63eaf | 2009-08-18 15:43:13 +0200 | [diff] [blame] | 123 | int sbal_idx, sbal_no; |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 124 | |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 125 | if (unlikely(qdio_err)) { |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 126 | zfcp_dbf_hba_qdio(qdio->adapter->dbf, qdio_err, first, |
| 127 | count); |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 128 | zfcp_qdio_handler_error(qdio, "qdires1"); |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 129 | return; |
| 130 | } |
| 131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | /* |
| 133 | * go through all SBALs from input queue currently |
| 134 | * returned by QDIO layer |
| 135 | */ |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 136 | for (sbal_no = 0; sbal_no < count; sbal_no++) { |
| 137 | sbal_idx = (first + sbal_no) % QDIO_MAX_BUFFERS_PER_Q; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | /* go through all SBALEs of SBAL */ |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 139 | zfcp_fsf_reqid_check(qdio, sbal_idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | /* |
| 143 | * put range of SBALs back to response queue |
| 144 | * (including SBALs which have already been free before) |
| 145 | */ |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 146 | zfcp_qdio_resp_put_back(qdio, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | /** |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 150 | * zfcp_qdio_sbale_req - return ptr to SBALE of req_q for a struct zfcp_fsf_req |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 151 | * @qdio: pointer to struct zfcp_qdio |
Swen Schillig | 42428f7 | 2009-08-18 15:43:18 +0200 | [diff] [blame] | 152 | * @q_rec: pointer to struct zfcp_queue_rec |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 153 | * Returns: pointer to qdio_buffer_element (SBALE) structure |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | */ |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 155 | struct qdio_buffer_element *zfcp_qdio_sbale_req(struct zfcp_qdio *qdio, |
Swen Schillig | 42428f7 | 2009-08-18 15:43:18 +0200 | [diff] [blame] | 156 | struct zfcp_queue_req *q_req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | { |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 158 | return zfcp_qdio_sbale(&qdio->req_q, q_req->sbal_last, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | /** |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 162 | * zfcp_qdio_sbale_curr - return curr SBALE on req_q for a struct zfcp_fsf_req |
| 163 | * @fsf_req: pointer to struct fsf_req |
| 164 | * Returns: pointer to qdio_buffer_element (SBALE) structure |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | */ |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 166 | struct qdio_buffer_element *zfcp_qdio_sbale_curr(struct zfcp_qdio *qdio, |
Swen Schillig | 42428f7 | 2009-08-18 15:43:18 +0200 | [diff] [blame] | 167 | struct zfcp_queue_req *q_req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | { |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 169 | return zfcp_qdio_sbale(&qdio->req_q, q_req->sbal_last, |
Swen Schillig | 42428f7 | 2009-08-18 15:43:18 +0200 | [diff] [blame] | 170 | q_req->sbale_curr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 173 | static void zfcp_qdio_sbal_limit(struct zfcp_qdio *qdio, |
Swen Schillig | 42428f7 | 2009-08-18 15:43:18 +0200 | [diff] [blame] | 174 | struct zfcp_queue_req *q_req, int max_sbals) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | { |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 176 | int count = atomic_read(&qdio->req_q.count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | count = min(count, max_sbals); |
Swen Schillig | 42428f7 | 2009-08-18 15:43:18 +0200 | [diff] [blame] | 178 | q_req->sbal_limit = (q_req->sbal_first + count - 1) |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 179 | % QDIO_MAX_BUFFERS_PER_Q; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 182 | static struct qdio_buffer_element * |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 183 | zfcp_qdio_sbal_chain(struct zfcp_qdio *qdio, struct zfcp_queue_req *q_req, |
Swen Schillig | 42428f7 | 2009-08-18 15:43:18 +0200 | [diff] [blame] | 184 | unsigned long sbtype) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | { |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 186 | struct qdio_buffer_element *sbale; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
| 188 | /* set last entry flag in current SBALE of current SBAL */ |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 189 | sbale = zfcp_qdio_sbale_curr(qdio, q_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | sbale->flags |= SBAL_FLAGS_LAST_ENTRY; |
| 191 | |
| 192 | /* don't exceed last allowed SBAL */ |
Swen Schillig | 42428f7 | 2009-08-18 15:43:18 +0200 | [diff] [blame] | 193 | if (q_req->sbal_last == q_req->sbal_limit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | return NULL; |
| 195 | |
| 196 | /* set chaining flag in first SBALE of current SBAL */ |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 197 | sbale = zfcp_qdio_sbale_req(qdio, q_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | sbale->flags |= SBAL_FLAGS0_MORE_SBALS; |
| 199 | |
| 200 | /* calculate index of next SBAL */ |
Swen Schillig | 42428f7 | 2009-08-18 15:43:18 +0200 | [diff] [blame] | 201 | q_req->sbal_last++; |
| 202 | q_req->sbal_last %= QDIO_MAX_BUFFERS_PER_Q; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
| 204 | /* keep this requests number of SBALs up-to-date */ |
Swen Schillig | 42428f7 | 2009-08-18 15:43:18 +0200 | [diff] [blame] | 205 | q_req->sbal_number++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
| 207 | /* start at first SBALE of new SBAL */ |
Swen Schillig | 42428f7 | 2009-08-18 15:43:18 +0200 | [diff] [blame] | 208 | q_req->sbale_curr = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
| 210 | /* set storage-block type for new SBAL */ |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 211 | sbale = zfcp_qdio_sbale_curr(qdio, q_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | sbale->flags |= sbtype; |
| 213 | |
| 214 | return sbale; |
| 215 | } |
| 216 | |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 217 | static struct qdio_buffer_element * |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 218 | zfcp_qdio_sbale_next(struct zfcp_qdio *qdio, struct zfcp_queue_req *q_req, |
Swen Schillig | 42428f7 | 2009-08-18 15:43:18 +0200 | [diff] [blame] | 219 | unsigned int sbtype) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | { |
Swen Schillig | 42428f7 | 2009-08-18 15:43:18 +0200 | [diff] [blame] | 221 | if (q_req->sbale_curr == ZFCP_LAST_SBALE_PER_SBAL) |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 222 | return zfcp_qdio_sbal_chain(qdio, q_req, sbtype); |
Swen Schillig | 42428f7 | 2009-08-18 15:43:18 +0200 | [diff] [blame] | 223 | q_req->sbale_curr++; |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 224 | return zfcp_qdio_sbale_curr(qdio, q_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 227 | static void zfcp_qdio_undo_sbals(struct zfcp_qdio *qdio, |
Swen Schillig | 42428f7 | 2009-08-18 15:43:18 +0200 | [diff] [blame] | 228 | struct zfcp_queue_req *q_req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | { |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 230 | struct qdio_buffer **sbal = qdio->req_q.sbal; |
Swen Schillig | 42428f7 | 2009-08-18 15:43:18 +0200 | [diff] [blame] | 231 | int first = q_req->sbal_first; |
| 232 | int last = q_req->sbal_last; |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 233 | int count = (last - first + QDIO_MAX_BUFFERS_PER_Q) % |
| 234 | QDIO_MAX_BUFFERS_PER_Q + 1; |
| 235 | zfcp_qdio_zero_sbals(sbal, first, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 238 | static int zfcp_qdio_fill_sbals(struct zfcp_qdio *qdio, |
Swen Schillig | 42428f7 | 2009-08-18 15:43:18 +0200 | [diff] [blame] | 239 | struct zfcp_queue_req *q_req, |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 240 | unsigned int sbtype, void *start_addr, |
| 241 | unsigned int total_length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | { |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 243 | struct qdio_buffer_element *sbale; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | unsigned long remaining, length; |
| 245 | void *addr; |
| 246 | |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 247 | /* split segment up */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | for (addr = start_addr, remaining = total_length; remaining > 0; |
| 249 | addr += length, remaining -= length) { |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 250 | sbale = zfcp_qdio_sbale_next(qdio, q_req, sbtype); |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 251 | if (!sbale) { |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 252 | atomic_inc(&qdio->req_q_full); |
| 253 | zfcp_qdio_undo_sbals(qdio, q_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | return -EINVAL; |
| 255 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 257 | /* new piece must not exceed next page boundary */ |
| 258 | length = min(remaining, |
| 259 | (PAGE_SIZE - ((unsigned long)addr & |
| 260 | (PAGE_SIZE - 1)))); |
| 261 | sbale->addr = addr; |
| 262 | sbale->length = length; |
| 263 | } |
| 264 | return 0; |
| 265 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
| 267 | /** |
| 268 | * zfcp_qdio_sbals_from_sg - fill SBALs from scatter-gather list |
| 269 | * @fsf_req: request to be processed |
| 270 | * @sbtype: SBALE flags |
| 271 | * @sg: scatter-gather list |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | * @max_sbals: upper bound for number of SBALs to be used |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 273 | * Returns: number of bytes, or error (negativ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | */ |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 275 | int zfcp_qdio_sbals_from_sg(struct zfcp_qdio *qdio, |
Swen Schillig | 42428f7 | 2009-08-18 15:43:18 +0200 | [diff] [blame] | 276 | struct zfcp_queue_req *q_req, |
| 277 | unsigned long sbtype, struct scatterlist *sg, |
| 278 | int max_sbals) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | { |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 280 | struct qdio_buffer_element *sbale; |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 281 | int retval, bytes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | |
| 283 | /* figure out last allowed SBAL */ |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 284 | zfcp_qdio_sbal_limit(qdio, q_req, max_sbals); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 286 | /* set storage-block type for this request */ |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 287 | sbale = zfcp_qdio_sbale_req(qdio, q_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | sbale->flags |= sbtype; |
| 289 | |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 290 | for (; sg; sg = sg_next(sg)) { |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 291 | retval = zfcp_qdio_fill_sbals(qdio, q_req, sbtype, |
Swen Schillig | 42428f7 | 2009-08-18 15:43:18 +0200 | [diff] [blame] | 292 | sg_virt(sg), sg->length); |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 293 | if (retval < 0) |
| 294 | return retval; |
| 295 | bytes += sg->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | } |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 297 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | /* assume that no other SBALEs are to follow in the same SBAL */ |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 299 | sbale = zfcp_qdio_sbale_curr(qdio, q_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | sbale->flags |= SBAL_FLAGS_LAST_ENTRY; |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 301 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | return bytes; |
| 303 | } |
| 304 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | /** |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 306 | * 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] | 307 | * @qdio: pointer to struct zfcp_qdio |
| 308 | * @q_req: pointer to struct zfcp_queue_req |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 309 | * Returns: 0 on success, error otherwise |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | */ |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 311 | int zfcp_qdio_send(struct zfcp_qdio *qdio, struct zfcp_queue_req *q_req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | { |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 313 | struct zfcp_qdio_queue *req_q = &qdio->req_q; |
Swen Schillig | 42428f7 | 2009-08-18 15:43:18 +0200 | [diff] [blame] | 314 | int first = q_req->sbal_first; |
| 315 | int count = q_req->sbal_number; |
Christof Schmitt | 21ddaa5 | 2009-03-02 13:09:05 +0100 | [diff] [blame] | 316 | int retval; |
| 317 | unsigned int qdio_flags = QDIO_FLAG_SYNC_OUTPUT; |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 318 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 319 | zfcp_qdio_account(qdio); |
Martin Peschke | 94506fd | 2009-03-02 13:08:56 +0100 | [diff] [blame] | 320 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 321 | retval = do_QDIO(qdio->adapter->ccw_device, qdio_flags, 0, first, |
| 322 | count); |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 323 | if (unlikely(retval)) { |
| 324 | zfcp_qdio_zero_sbals(req_q->sbal, first, count); |
| 325 | return retval; |
| 326 | } |
| 327 | |
| 328 | /* account for transferred buffers */ |
| 329 | atomic_sub(count, &req_q->count); |
| 330 | req_q->first += count; |
| 331 | req_q->first %= QDIO_MAX_BUFFERS_PER_Q; |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 332 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 335 | |
| 336 | static void zfcp_qdio_setup_init_data(struct qdio_initialize *id, |
| 337 | struct zfcp_qdio *qdio) |
| 338 | { |
| 339 | |
| 340 | id->cdev = qdio->adapter->ccw_device; |
| 341 | id->q_format = QDIO_ZFCP_QFMT; |
| 342 | memcpy(id->adapter_name, dev_name(&id->cdev->dev), 8); |
| 343 | ASCEBC(id->adapter_name, 8); |
| 344 | id->qib_param_field_format = 0; |
| 345 | id->qib_param_field = NULL; |
| 346 | id->input_slib_elements = NULL; |
| 347 | id->output_slib_elements = NULL; |
| 348 | id->no_input_qs = 1; |
| 349 | id->no_output_qs = 1; |
| 350 | id->input_handler = zfcp_qdio_int_resp; |
| 351 | id->output_handler = zfcp_qdio_int_req; |
| 352 | id->int_parm = (unsigned long) qdio; |
| 353 | id->flags = QDIO_INBOUND_0COPY_SBALS | |
| 354 | QDIO_OUTBOUND_0COPY_SBALS | QDIO_USE_OUTBOUND_PCIS; |
| 355 | id->input_sbal_addr_array = (void **) (qdio->resp_q.sbal); |
| 356 | id->output_sbal_addr_array = (void **) (qdio->req_q.sbal); |
| 357 | |
| 358 | } |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 359 | /** |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 360 | * zfcp_qdio_allocate - allocate queue memory and initialize QDIO data |
| 361 | * @adapter: pointer to struct zfcp_adapter |
| 362 | * Returns: -ENOMEM on memory allocation error or return value from |
| 363 | * qdio_allocate |
| 364 | */ |
Swen Schillig | d5a282a | 2009-08-18 15:43:22 +0200 | [diff] [blame^] | 365 | static int zfcp_qdio_allocate(struct zfcp_qdio *qdio) |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 366 | { |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 367 | struct qdio_initialize init_data; |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 368 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 369 | if (zfcp_qdio_buffers_enqueue(qdio->req_q.sbal) || |
| 370 | zfcp_qdio_buffers_enqueue(qdio->resp_q.sbal)) |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 371 | return -ENOMEM; |
| 372 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 373 | zfcp_qdio_setup_init_data(&init_data, qdio); |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 374 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 375 | return qdio_allocate(&init_data); |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | /** |
| 379 | * zfcp_close_qdio - close qdio queues for an adapter |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 380 | * @qdio: pointer to structure zfcp_qdio |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 381 | */ |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 382 | void zfcp_qdio_close(struct zfcp_qdio *qdio) |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 383 | { |
| 384 | struct zfcp_qdio_queue *req_q; |
| 385 | int first, count; |
| 386 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 387 | if (!(atomic_read(&qdio->adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 388 | return; |
| 389 | |
| 390 | /* clear QDIOUP flag, thus do_QDIO is not called during qdio_shutdown */ |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 391 | req_q = &qdio->req_q; |
| 392 | spin_lock_bh(&qdio->req_q_lock); |
| 393 | atomic_clear_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &qdio->adapter->status); |
| 394 | spin_unlock_bh(&qdio->req_q_lock); |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 395 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 396 | qdio_shutdown(qdio->adapter->ccw_device, |
| 397 | QDIO_FLAG_CLEANUP_USING_CLEAR); |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 398 | |
| 399 | /* cleanup used outbound sbals */ |
| 400 | count = atomic_read(&req_q->count); |
| 401 | if (count < QDIO_MAX_BUFFERS_PER_Q) { |
| 402 | first = (req_q->first + count) % QDIO_MAX_BUFFERS_PER_Q; |
| 403 | count = QDIO_MAX_BUFFERS_PER_Q - count; |
| 404 | zfcp_qdio_zero_sbals(req_q->sbal, first, count); |
| 405 | } |
| 406 | req_q->first = 0; |
| 407 | atomic_set(&req_q->count, 0); |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 408 | qdio->resp_q.first = 0; |
| 409 | atomic_set(&qdio->resp_q.count, 0); |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | /** |
| 413 | * zfcp_qdio_open - prepare and initialize response queue |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 414 | * @qdio: pointer to struct zfcp_qdio |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 415 | * Returns: 0 on success, otherwise -EIO |
| 416 | */ |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 417 | int zfcp_qdio_open(struct zfcp_qdio *qdio) |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 418 | { |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 419 | struct qdio_buffer_element *sbale; |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 420 | struct qdio_initialize init_data; |
| 421 | struct ccw_device *cdev = qdio->adapter->ccw_device; |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 422 | int cc; |
| 423 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 424 | if (atomic_read(&qdio->adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP) |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 425 | return -EIO; |
| 426 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 427 | zfcp_qdio_setup_init_data(&init_data, qdio); |
| 428 | |
| 429 | if (qdio_establish(&init_data)) |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 430 | goto failed_establish; |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 431 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 432 | if (qdio_activate(cdev)) |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 433 | goto failed_qdio; |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 434 | |
| 435 | for (cc = 0; cc < QDIO_MAX_BUFFERS_PER_Q; cc++) { |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 436 | sbale = &(qdio->resp_q.sbal[cc]->element[0]); |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 437 | sbale->length = 0; |
| 438 | sbale->flags = SBAL_FLAGS_LAST_ENTRY; |
| 439 | sbale->addr = NULL; |
| 440 | } |
| 441 | |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 442 | if (do_QDIO(cdev, QDIO_FLAG_SYNC_INPUT, 0, 0, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 443 | QDIO_MAX_BUFFERS_PER_Q)) |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 444 | goto failed_qdio; |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 445 | |
| 446 | /* set index of first avalable SBALS / number of available SBALS */ |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 447 | qdio->req_q.first = 0; |
| 448 | atomic_set(&qdio->req_q.count, QDIO_MAX_BUFFERS_PER_Q); |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 449 | |
| 450 | return 0; |
| 451 | |
| 452 | failed_qdio: |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 453 | qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR); |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 454 | failed_establish: |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 455 | dev_err(&cdev->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 456 | "Setting up the QDIO connection to the FCP adapter failed\n"); |
Swen Schillig | 00bab91 | 2008-06-10 18:20:57 +0200 | [diff] [blame] | 457 | return -EIO; |
| 458 | } |
Swen Schillig | d5a282a | 2009-08-18 15:43:22 +0200 | [diff] [blame^] | 459 | |
| 460 | void zfcp_qdio_destroy(struct zfcp_qdio *qdio) |
| 461 | { |
| 462 | struct qdio_buffer **sbal_req, **sbal_resp; |
| 463 | int p; |
| 464 | |
| 465 | if (!qdio) |
| 466 | return; |
| 467 | |
| 468 | if (qdio->adapter->ccw_device) |
| 469 | qdio_free(qdio->adapter->ccw_device); |
| 470 | |
| 471 | sbal_req = qdio->req_q.sbal; |
| 472 | sbal_resp = qdio->resp_q.sbal; |
| 473 | |
| 474 | for (p = 0; p < QDIO_MAX_BUFFERS_PER_Q; p += QBUFF_PER_PAGE) { |
| 475 | free_page((unsigned long) sbal_req[p]); |
| 476 | free_page((unsigned long) sbal_resp[p]); |
| 477 | } |
| 478 | |
| 479 | kfree(qdio); |
| 480 | } |
| 481 | |
| 482 | int zfcp_qdio_setup(struct zfcp_adapter *adapter) |
| 483 | { |
| 484 | struct zfcp_qdio *qdio; |
| 485 | |
| 486 | qdio = kzalloc(sizeof(struct zfcp_qdio), GFP_KERNEL); |
| 487 | if (!qdio) |
| 488 | return -ENOMEM; |
| 489 | |
| 490 | qdio->adapter = adapter; |
| 491 | |
| 492 | if (zfcp_qdio_allocate(qdio)) { |
| 493 | zfcp_qdio_destroy(qdio); |
| 494 | return -ENOMEM; |
| 495 | } |
| 496 | |
| 497 | spin_lock_init(&qdio->req_q_lock); |
| 498 | spin_lock_init(&qdio->stat_lock); |
| 499 | |
| 500 | adapter->qdio = qdio; |
| 501 | return 0; |
| 502 | } |
| 503 | |