Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * zfcp device driver
0004  *
0005  * Header file for zfcp qdio interface
0006  *
0007  * Copyright IBM Corp. 2010
0008  */
0009 
0010 #ifndef ZFCP_QDIO_H
0011 #define ZFCP_QDIO_H
0012 
0013 #include <linux/interrupt.h>
0014 #include <asm/qdio.h>
0015 
0016 #define ZFCP_QDIO_SBALE_LEN PAGE_SIZE
0017 
0018 /* Max SBALS for chaining */
0019 #define ZFCP_QDIO_MAX_SBALS_PER_REQ 36
0020 
0021 /**
0022  * struct zfcp_qdio - basic qdio data structure
0023  * @res_q: response queue
0024  * @req_q: request queue
0025  * @req_q_idx: index of next free buffer
0026  * @req_q_free: number of free buffers in queue
0027  * @stat_lock: lock to protect req_q_util and req_q_time
0028  * @req_q_lock: lock to serialize access to request queue
0029  * @req_q_time: time of last fill level change
0030  * @req_q_util: used for accounting
0031  * @req_q_full: queue full incidents
0032  * @req_q_wq: used to wait for SBAL availability
0033  * @irq_tasklet: used for QDIO interrupt processing
0034  * @request_tasklet: used for Request Queue completion processing
0035  * @request_timer: used to trigger the Request Queue completion processing
0036  * @adapter: adapter used in conjunction with this qdio structure
0037  * @max_sbale_per_sbal: qdio limit per sbal
0038  * @max_sbale_per_req: qdio limit per request
0039  */
0040 struct zfcp_qdio {
0041     struct qdio_buffer  *res_q[QDIO_MAX_BUFFERS_PER_Q];
0042     struct qdio_buffer  *req_q[QDIO_MAX_BUFFERS_PER_Q];
0043     u8          req_q_idx;
0044     atomic_t        req_q_free;
0045     spinlock_t      stat_lock;
0046     spinlock_t      req_q_lock;
0047     unsigned long long  req_q_time;
0048     u64         req_q_util;
0049     atomic_t        req_q_full;
0050     wait_queue_head_t   req_q_wq;
0051     struct tasklet_struct   irq_tasklet;
0052     struct tasklet_struct   request_tasklet;
0053     struct timer_list   request_timer;
0054     struct zfcp_adapter *adapter;
0055     u16         max_sbale_per_sbal;
0056     u16         max_sbale_per_req;
0057 };
0058 
0059 /**
0060  * struct zfcp_qdio_req - qdio queue related values for a request
0061  * @sbtype: sbal type flags for sbale 0
0062  * @sbal_number: number of free sbals
0063  * @sbal_first: first sbal for this request
0064  * @sbal_last: last sbal for this request
0065  * @sbal_limit: last possible sbal for this request
0066  * @sbale_curr: current sbale at creation of this request
0067  * @qdio_outb_usage: usage of outbound queue
0068  */
0069 struct zfcp_qdio_req {
0070     u8  sbtype;
0071     u8  sbal_number;
0072     u8  sbal_first;
0073     u8  sbal_last;
0074     u8  sbal_limit;
0075     u8  sbale_curr;
0076     u16 qdio_outb_usage;
0077 };
0078 
0079 /**
0080  * zfcp_qdio_sbale_req - return pointer to sbale on req_q for a request
0081  * @qdio: pointer to struct zfcp_qdio
0082  * @q_req: pointer to struct zfcp_qdio_req
0083  * Returns: pointer to qdio_buffer_element (sbale) structure
0084  */
0085 static inline struct qdio_buffer_element *
0086 zfcp_qdio_sbale_req(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req)
0087 {
0088     return &qdio->req_q[q_req->sbal_last]->element[0];
0089 }
0090 
0091 /**
0092  * zfcp_qdio_sbale_curr - return current sbale on req_q for a request
0093  * @qdio: pointer to struct zfcp_qdio
0094  * @q_req: pointer to struct zfcp_qdio_req
0095  * Returns: pointer to qdio_buffer_element (sbale) structure
0096  */
0097 static inline struct qdio_buffer_element *
0098 zfcp_qdio_sbale_curr(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req)
0099 {
0100     return &qdio->req_q[q_req->sbal_last]->element[q_req->sbale_curr];
0101 }
0102 
0103 /**
0104  * zfcp_qdio_req_init - initialize qdio request
0105  * @qdio: request queue where to start putting the request
0106  * @q_req: the qdio request to start
0107  * @req_id: The request id
0108  * @sbtype: type flags to set for all sbals
0109  * @data: First data block
0110  * @len: Length of first data block
0111  *
0112  * This is the start of putting the request into the queue, the last
0113  * step is passing the request to zfcp_qdio_send. The request queue
0114  * lock must be held during the whole process from init to send.
0115  */
0116 static inline
0117 void zfcp_qdio_req_init(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req,
0118             unsigned long req_id, u8 sbtype, void *data, u32 len)
0119 {
0120     struct qdio_buffer_element *sbale;
0121     int count = min(atomic_read(&qdio->req_q_free),
0122             ZFCP_QDIO_MAX_SBALS_PER_REQ);
0123 
0124     q_req->sbal_first = q_req->sbal_last = qdio->req_q_idx;
0125     q_req->sbal_number = 1;
0126     q_req->sbtype = sbtype;
0127     q_req->sbale_curr = 1;
0128     q_req->sbal_limit = (q_req->sbal_first + count - 1)
0129                     % QDIO_MAX_BUFFERS_PER_Q;
0130 
0131     sbale = zfcp_qdio_sbale_req(qdio, q_req);
0132     sbale->addr = req_id;
0133     sbale->eflags = 0;
0134     sbale->sflags = SBAL_SFLAGS0_COMMAND | sbtype;
0135 
0136     if (unlikely(!data))
0137         return;
0138     sbale++;
0139     sbale->addr = virt_to_phys(data);
0140     sbale->length = len;
0141 }
0142 
0143 /**
0144  * zfcp_qdio_fill_next - Fill next sbale, only for single sbal requests
0145  * @qdio: pointer to struct zfcp_qdio
0146  * @q_req: pointer to struct zfcp_queue_req
0147  * @data: pointer to data
0148  * @len: length of data
0149  *
0150  * This is only required for single sbal requests, calling it when
0151  * wrapping around to the next sbal is a bug.
0152  */
0153 static inline
0154 void zfcp_qdio_fill_next(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req,
0155              void *data, u32 len)
0156 {
0157     struct qdio_buffer_element *sbale;
0158 
0159     BUG_ON(q_req->sbale_curr == qdio->max_sbale_per_sbal - 1);
0160     q_req->sbale_curr++;
0161     sbale = zfcp_qdio_sbale_curr(qdio, q_req);
0162     sbale->addr = virt_to_phys(data);
0163     sbale->length = len;
0164 }
0165 
0166 /**
0167  * zfcp_qdio_set_sbale_last - set last entry flag in current sbale
0168  * @qdio: pointer to struct zfcp_qdio
0169  * @q_req: pointer to struct zfcp_queue_req
0170  */
0171 static inline
0172 void zfcp_qdio_set_sbale_last(struct zfcp_qdio *qdio,
0173                   struct zfcp_qdio_req *q_req)
0174 {
0175     struct qdio_buffer_element *sbale;
0176 
0177     sbale = zfcp_qdio_sbale_curr(qdio, q_req);
0178     sbale->eflags |= SBAL_EFLAGS_LAST_ENTRY;
0179 }
0180 
0181 /**
0182  * zfcp_qdio_sg_one_sbal - check if one sbale is enough for sg data
0183  * @sg: The scatterlist where to check the data size
0184  *
0185  * Returns: 1 when one sbale is enough for the data in the scatterlist,
0186  *      0 if not.
0187  */
0188 static inline
0189 int zfcp_qdio_sg_one_sbale(struct scatterlist *sg)
0190 {
0191     return sg_is_last(sg) && sg->length <= ZFCP_QDIO_SBALE_LEN;
0192 }
0193 
0194 /**
0195  * zfcp_qdio_skip_to_last_sbale - skip to last sbale in sbal
0196  * @qdio: pointer to struct zfcp_qdio
0197  * @q_req: The current zfcp_qdio_req
0198  */
0199 static inline
0200 void zfcp_qdio_skip_to_last_sbale(struct zfcp_qdio *qdio,
0201                   struct zfcp_qdio_req *q_req)
0202 {
0203     q_req->sbale_curr = qdio->max_sbale_per_sbal - 1;
0204 }
0205 
0206 /**
0207  * zfcp_qdio_sbal_limit - set the sbal limit for a request in q_req
0208  * @qdio: pointer to struct zfcp_qdio
0209  * @q_req: The current zfcp_qdio_req
0210  * @max_sbals: maximum number of SBALs allowed
0211  */
0212 static inline
0213 void zfcp_qdio_sbal_limit(struct zfcp_qdio *qdio,
0214               struct zfcp_qdio_req *q_req, int max_sbals)
0215 {
0216     int count = min(atomic_read(&qdio->req_q_free), max_sbals);
0217 
0218     q_req->sbal_limit = (q_req->sbal_first + count - 1) %
0219                 QDIO_MAX_BUFFERS_PER_Q;
0220 }
0221 
0222 /**
0223  * zfcp_qdio_set_data_div - set data division count
0224  * @qdio: pointer to struct zfcp_qdio
0225  * @q_req: The current zfcp_qdio_req
0226  * @count: The data division count
0227  */
0228 static inline
0229 void zfcp_qdio_set_data_div(struct zfcp_qdio *qdio,
0230                 struct zfcp_qdio_req *q_req, u32 count)
0231 {
0232     struct qdio_buffer_element *sbale;
0233 
0234     sbale = qdio->req_q[q_req->sbal_first]->element;
0235     sbale->length = count;
0236 }
0237 
0238 /**
0239  * zfcp_qdio_real_bytes - count bytes used
0240  * @sg: pointer to struct scatterlist
0241  */
0242 static inline
0243 unsigned int zfcp_qdio_real_bytes(struct scatterlist *sg)
0244 {
0245     unsigned int real_bytes = 0;
0246 
0247     for (; sg; sg = sg_next(sg))
0248         real_bytes += sg->length;
0249 
0250     return real_bytes;
0251 }
0252 
0253 /**
0254  * zfcp_qdio_set_scount - set SBAL count value
0255  * @qdio: pointer to struct zfcp_qdio
0256  * @q_req: The current zfcp_qdio_req
0257  */
0258 static inline
0259 void zfcp_qdio_set_scount(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req)
0260 {
0261     struct qdio_buffer_element *sbale;
0262 
0263     sbale = qdio->req_q[q_req->sbal_first]->element;
0264     sbale->scount = q_req->sbal_number - 1;
0265 }
0266 
0267 #endif /* ZFCP_QDIO_H */