1/* 2 * Copyright (c) 2004-07 Applied Micro Circuits Corporation. 3 * Copyright (c) 2004-05 Vinod Kashyap 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 *
| 1/* 2 * Copyright (c) 2004-07 Applied Micro Circuits Corporation. 3 * Copyright (c) 2004-05 Vinod Kashyap 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 *
|
136 TW_UINT8 reset_in_progress; /* Controller is being reset. */ 137 TW_UINT8 reset_phase1_in_progress; /* In 'phase 1' of reset. */ 138 TW_UINT32 flags; /* controller settings */ 139 TW_UINT32 sg_size_factor; /* SG element size should be a 140 multiple of this */ 141 142 /* Request queues and arrays. */ 143 struct tw_cl_link req_q_head[TW_CLI_Q_COUNT]; 144 145 TW_UINT8 *internal_req_data;/* internal req data buf */ 146 TW_UINT64 internal_req_data_phys;/* phys addr of internal 147 req data buf */ 148 TW_UINT32 max_simult_reqs; /* max simultaneous requests 149 supported */ 150 TW_UINT32 max_aens_supported;/* max AEN's supported */ 151 /* AEN handler fields. */ 152 struct tw_cl_event_packet *aen_queue; /* circular queue of AENs from 153 firmware/CL/OSL */ 154 TW_UINT32 aen_head; /* AEN queue head */ 155 TW_UINT32 aen_tail; /* AEN queue tail */ 156 TW_UINT32 aen_cur_seq_id; /* index of the last event+1 */ 157 TW_UINT32 aen_q_overflow; /* indicates if unretrieved 158 events were overwritten */ 159 TW_UINT32 aen_q_wrapped; /* indicates if AEN queue ever 160 wrapped */ 161 162 TW_UINT16 working_srl; /* driver & firmware negotiated 163 srl */ 164 TW_UINT16 working_branch; /* branch # of the firmware 165 that the driver is compatible with */ 166 TW_UINT16 working_build; /* build # of the firmware 167 that the driver is compatible with */ 168 TW_UINT16 fw_on_ctlr_srl; /* srl of running firmware */ 169 TW_UINT16 fw_on_ctlr_branch;/* branch # of running 170 firmware */ 171 TW_UINT16 fw_on_ctlr_build;/* build # of running 172 firmware */ 173 TW_UINT32 operating_mode; /* base mode/current mode */ 174 175 TW_INT32 host_intr_pending;/* host intr processing 176 needed */ 177 TW_INT32 attn_intr_pending;/* attn intr processing 178 needed */ 179 TW_INT32 cmd_intr_pending;/* cmd intr processing 180 needed */ 181 TW_INT32 resp_intr_pending;/* resp intr processing 182 needed */ 183 184 TW_LOCK_HANDLE gen_lock_handle;/* general purpose lock */ 185 TW_LOCK_HANDLE *gen_lock;/* ptr to general purpose lock */ 186 TW_LOCK_HANDLE io_lock_handle; /* lock held during cmd 187 submission */ 188 TW_LOCK_HANDLE *io_lock;/* ptr to lock held during cmd 189 submission */ 190 191#ifdef TW_OSL_CAN_SLEEP 192 TW_SLEEP_HANDLE sleep_handle; /* handle to co-ordinate sleeps 193 & wakeups */ 194#endif /* TW_OSL_CAN_SLEEP */ 195 196 struct { 197 TW_UINT32 lock; /* lock state */ 198 TW_TIME timeout; /* time at which the lock will 199 become available, even if not 200 explicitly released */ 201 } ioctl_lock; /* lock for use by user applications, for 202 synchronization between ioctl calls */ 203#ifdef TW_OSL_DEBUG 204 struct tw_cli_q_stats q_stats[TW_CLI_Q_COUNT];/* queue statistics */ 205#endif /* TW_OSL_DEBUG */ 206}; 207 208 209 210/* 211 * Queue primitives 212 */ 213 214#ifdef TW_OSL_DEBUG 215 216#define TW_CLI_Q_INIT(ctlr, q_type) do { \ 217 (ctlr)->q_stats[q_type].cur_len = 0; \ 218 (ctlr)->q_stats[q_type].max_len = 0; \ 219} while (0) 220 221 222#define TW_CLI_Q_INSERT(ctlr, q_type) do { \ 223 struct tw_cli_q_stats *q_stats = &((ctlr)->q_stats[q_type]); \ 224 \ 225 if (++(q_stats->cur_len) > q_stats->max_len) \ 226 q_stats->max_len = q_stats->cur_len; \ 227} while (0) 228 229 230#define TW_CLI_Q_REMOVE(ctlr, q_type) \ 231 (ctlr)->q_stats[q_type].cur_len-- 232 233#else /* TW_OSL_DEBUG */ 234 235#define TW_CLI_Q_INIT(ctlr, q_index) 236#define TW_CLI_Q_INSERT(ctlr, q_index) 237#define TW_CLI_Q_REMOVE(ctlr, q_index) 238 239#endif /* TW_OSL_DEBUG */ 240 241 242/* Initialize a queue of requests. */ 243static __inline TW_VOID 244tw_cli_req_q_init(struct tw_cli_ctlr_context *ctlr, TW_UINT8 q_type) 245{ 246 TW_CL_Q_INIT(&(ctlr->req_q_head[q_type])); 247 TW_CLI_Q_INIT(ctlr, q_type); 248} 249 250 251 252/* Insert the given request at the head of the given queue (q_type). */ 253static __inline TW_VOID 254tw_cli_req_q_insert_head(struct tw_cli_req_context *req, TW_UINT8 q_type) 255{ 256 struct tw_cli_ctlr_context *ctlr = req->ctlr; 257 258 tw_osl_get_lock(ctlr->ctlr_handle, ctlr->gen_lock); 259 TW_CL_Q_INSERT_HEAD(&(ctlr->req_q_head[q_type]), &(req->link)); 260 TW_CLI_Q_INSERT(ctlr, q_type); 261 tw_osl_free_lock(ctlr->ctlr_handle, ctlr->gen_lock); 262} 263 264 265 266/* Insert the given request at the tail of the given queue (q_type). */ 267static __inline TW_VOID 268tw_cli_req_q_insert_tail(struct tw_cli_req_context *req, TW_UINT8 q_type) 269{ 270 struct tw_cli_ctlr_context *ctlr = req->ctlr; 271 272 tw_osl_get_lock(ctlr->ctlr_handle, ctlr->gen_lock); 273 TW_CL_Q_INSERT_TAIL(&(ctlr->req_q_head[q_type]), &(req->link)); 274 TW_CLI_Q_INSERT(ctlr, q_type); 275 tw_osl_free_lock(ctlr->ctlr_handle, ctlr->gen_lock); 276} 277 278 279 280/* Remove and return the request at the head of the given queue (q_type). */ 281static __inline struct tw_cli_req_context * 282tw_cli_req_q_remove_head(struct tw_cli_ctlr_context *ctlr, TW_UINT8 q_type) 283{ 284 struct tw_cli_req_context *req = TW_CL_NULL; 285 struct tw_cl_link *link; 286 287 tw_osl_get_lock(ctlr->ctlr_handle, ctlr->gen_lock); 288 if ((link = TW_CL_Q_FIRST_ITEM(&(ctlr->req_q_head[q_type]))) != 289 TW_CL_NULL) { 290 req = TW_CL_STRUCT_HEAD(link, 291 struct tw_cli_req_context, link); 292 TW_CL_Q_REMOVE_ITEM(&(ctlr->req_q_head[q_type]), &(req->link)); 293 TW_CLI_Q_REMOVE(ctlr, q_type); 294 } 295 tw_osl_free_lock(ctlr->ctlr_handle, ctlr->gen_lock); 296 return(req); 297} 298 299 300 301/* Remove the given request from the given queue (q_type). */ 302static __inline TW_VOID 303tw_cli_req_q_remove_item(struct tw_cli_req_context *req, TW_UINT8 q_type) 304{ 305 struct tw_cli_ctlr_context *ctlr = req->ctlr; 306 307 tw_osl_get_lock(ctlr->ctlr_handle, ctlr->gen_lock); 308 TW_CL_Q_REMOVE_ITEM(&(ctlr->req_q_head[q_type]), &(req->link)); 309 TW_CLI_Q_REMOVE(ctlr, q_type); 310 tw_osl_free_lock(ctlr->ctlr_handle, ctlr->gen_lock); 311} 312 313 314 315/* Create an event packet for an event/error posted by the controller. */ 316#define tw_cli_create_ctlr_event(ctlr, event_src, cmd_hdr) do { \ 317 TW_UINT8 severity = \ 318 GET_SEVERITY((cmd_hdr)->status_block.res__severity); \ 319 \ 320 tw_cl_create_event(ctlr->ctlr_handle, TW_CL_TRUE, event_src, \ 321 (cmd_hdr)->status_block.error, \ 322 severity, \ 323 tw_cli_severity_string_table[severity], \ 324 (cmd_hdr)->err_specific_desc + \ 325 tw_osl_strlen((cmd_hdr)->err_specific_desc) + 1, \ 326 (cmd_hdr)->err_specific_desc); \ 327 /* Print 18 bytes of sense information. */ \ 328 tw_cli_dbg_printf(2, ctlr->ctlr_handle, \ 329 tw_osl_cur_func(), \ 330 "sense info: %x %x %x %x %x %x %x %x %x " \ 331 "%x %x %x %x %x %x %x %x %x", \ 332 (cmd_hdr)->sense_data[0], (cmd_hdr)->sense_data[1], \ 333 (cmd_hdr)->sense_data[2], (cmd_hdr)->sense_data[3], \ 334 (cmd_hdr)->sense_data[4], (cmd_hdr)->sense_data[5], \ 335 (cmd_hdr)->sense_data[6], (cmd_hdr)->sense_data[7], \ 336 (cmd_hdr)->sense_data[8], (cmd_hdr)->sense_data[9], \ 337 (cmd_hdr)->sense_data[10], (cmd_hdr)->sense_data[11], \ 338 (cmd_hdr)->sense_data[12], (cmd_hdr)->sense_data[13], \ 339 (cmd_hdr)->sense_data[14], (cmd_hdr)->sense_data[15], \ 340 (cmd_hdr)->sense_data[16], (cmd_hdr)->sense_data[17]); \ 341} while (0) 342 343 344 345#endif /* TW_CL_H */
| 138 TW_UINT8 reset_in_progress; /* Controller is being reset. */ 139 TW_UINT8 reset_phase1_in_progress; /* In 'phase 1' of reset. */ 140 TW_UINT32 flags; /* controller settings */ 141 TW_UINT32 sg_size_factor; /* SG element size should be a 142 multiple of this */ 143 144 /* Request queues and arrays. */ 145 struct tw_cl_link req_q_head[TW_CLI_Q_COUNT]; 146 147 TW_UINT8 *internal_req_data;/* internal req data buf */ 148 TW_UINT64 internal_req_data_phys;/* phys addr of internal 149 req data buf */ 150 TW_UINT32 max_simult_reqs; /* max simultaneous requests 151 supported */ 152 TW_UINT32 max_aens_supported;/* max AEN's supported */ 153 /* AEN handler fields. */ 154 struct tw_cl_event_packet *aen_queue; /* circular queue of AENs from 155 firmware/CL/OSL */ 156 TW_UINT32 aen_head; /* AEN queue head */ 157 TW_UINT32 aen_tail; /* AEN queue tail */ 158 TW_UINT32 aen_cur_seq_id; /* index of the last event+1 */ 159 TW_UINT32 aen_q_overflow; /* indicates if unretrieved 160 events were overwritten */ 161 TW_UINT32 aen_q_wrapped; /* indicates if AEN queue ever 162 wrapped */ 163 164 TW_UINT16 working_srl; /* driver & firmware negotiated 165 srl */ 166 TW_UINT16 working_branch; /* branch # of the firmware 167 that the driver is compatible with */ 168 TW_UINT16 working_build; /* build # of the firmware 169 that the driver is compatible with */ 170 TW_UINT16 fw_on_ctlr_srl; /* srl of running firmware */ 171 TW_UINT16 fw_on_ctlr_branch;/* branch # of running 172 firmware */ 173 TW_UINT16 fw_on_ctlr_build;/* build # of running 174 firmware */ 175 TW_UINT32 operating_mode; /* base mode/current mode */ 176 177 TW_INT32 host_intr_pending;/* host intr processing 178 needed */ 179 TW_INT32 attn_intr_pending;/* attn intr processing 180 needed */ 181 TW_INT32 cmd_intr_pending;/* cmd intr processing 182 needed */ 183 TW_INT32 resp_intr_pending;/* resp intr processing 184 needed */ 185 186 TW_LOCK_HANDLE gen_lock_handle;/* general purpose lock */ 187 TW_LOCK_HANDLE *gen_lock;/* ptr to general purpose lock */ 188 TW_LOCK_HANDLE io_lock_handle; /* lock held during cmd 189 submission */ 190 TW_LOCK_HANDLE *io_lock;/* ptr to lock held during cmd 191 submission */ 192 193#ifdef TW_OSL_CAN_SLEEP 194 TW_SLEEP_HANDLE sleep_handle; /* handle to co-ordinate sleeps 195 & wakeups */ 196#endif /* TW_OSL_CAN_SLEEP */ 197 198 struct { 199 TW_UINT32 lock; /* lock state */ 200 TW_TIME timeout; /* time at which the lock will 201 become available, even if not 202 explicitly released */ 203 } ioctl_lock; /* lock for use by user applications, for 204 synchronization between ioctl calls */ 205#ifdef TW_OSL_DEBUG 206 struct tw_cli_q_stats q_stats[TW_CLI_Q_COUNT];/* queue statistics */ 207#endif /* TW_OSL_DEBUG */ 208}; 209 210 211 212/* 213 * Queue primitives 214 */ 215 216#ifdef TW_OSL_DEBUG 217 218#define TW_CLI_Q_INIT(ctlr, q_type) do { \ 219 (ctlr)->q_stats[q_type].cur_len = 0; \ 220 (ctlr)->q_stats[q_type].max_len = 0; \ 221} while (0) 222 223 224#define TW_CLI_Q_INSERT(ctlr, q_type) do { \ 225 struct tw_cli_q_stats *q_stats = &((ctlr)->q_stats[q_type]); \ 226 \ 227 if (++(q_stats->cur_len) > q_stats->max_len) \ 228 q_stats->max_len = q_stats->cur_len; \ 229} while (0) 230 231 232#define TW_CLI_Q_REMOVE(ctlr, q_type) \ 233 (ctlr)->q_stats[q_type].cur_len-- 234 235#else /* TW_OSL_DEBUG */ 236 237#define TW_CLI_Q_INIT(ctlr, q_index) 238#define TW_CLI_Q_INSERT(ctlr, q_index) 239#define TW_CLI_Q_REMOVE(ctlr, q_index) 240 241#endif /* TW_OSL_DEBUG */ 242 243 244/* Initialize a queue of requests. */ 245static __inline TW_VOID 246tw_cli_req_q_init(struct tw_cli_ctlr_context *ctlr, TW_UINT8 q_type) 247{ 248 TW_CL_Q_INIT(&(ctlr->req_q_head[q_type])); 249 TW_CLI_Q_INIT(ctlr, q_type); 250} 251 252 253 254/* Insert the given request at the head of the given queue (q_type). */ 255static __inline TW_VOID 256tw_cli_req_q_insert_head(struct tw_cli_req_context *req, TW_UINT8 q_type) 257{ 258 struct tw_cli_ctlr_context *ctlr = req->ctlr; 259 260 tw_osl_get_lock(ctlr->ctlr_handle, ctlr->gen_lock); 261 TW_CL_Q_INSERT_HEAD(&(ctlr->req_q_head[q_type]), &(req->link)); 262 TW_CLI_Q_INSERT(ctlr, q_type); 263 tw_osl_free_lock(ctlr->ctlr_handle, ctlr->gen_lock); 264} 265 266 267 268/* Insert the given request at the tail of the given queue (q_type). */ 269static __inline TW_VOID 270tw_cli_req_q_insert_tail(struct tw_cli_req_context *req, TW_UINT8 q_type) 271{ 272 struct tw_cli_ctlr_context *ctlr = req->ctlr; 273 274 tw_osl_get_lock(ctlr->ctlr_handle, ctlr->gen_lock); 275 TW_CL_Q_INSERT_TAIL(&(ctlr->req_q_head[q_type]), &(req->link)); 276 TW_CLI_Q_INSERT(ctlr, q_type); 277 tw_osl_free_lock(ctlr->ctlr_handle, ctlr->gen_lock); 278} 279 280 281 282/* Remove and return the request at the head of the given queue (q_type). */ 283static __inline struct tw_cli_req_context * 284tw_cli_req_q_remove_head(struct tw_cli_ctlr_context *ctlr, TW_UINT8 q_type) 285{ 286 struct tw_cli_req_context *req = TW_CL_NULL; 287 struct tw_cl_link *link; 288 289 tw_osl_get_lock(ctlr->ctlr_handle, ctlr->gen_lock); 290 if ((link = TW_CL_Q_FIRST_ITEM(&(ctlr->req_q_head[q_type]))) != 291 TW_CL_NULL) { 292 req = TW_CL_STRUCT_HEAD(link, 293 struct tw_cli_req_context, link); 294 TW_CL_Q_REMOVE_ITEM(&(ctlr->req_q_head[q_type]), &(req->link)); 295 TW_CLI_Q_REMOVE(ctlr, q_type); 296 } 297 tw_osl_free_lock(ctlr->ctlr_handle, ctlr->gen_lock); 298 return(req); 299} 300 301 302 303/* Remove the given request from the given queue (q_type). */ 304static __inline TW_VOID 305tw_cli_req_q_remove_item(struct tw_cli_req_context *req, TW_UINT8 q_type) 306{ 307 struct tw_cli_ctlr_context *ctlr = req->ctlr; 308 309 tw_osl_get_lock(ctlr->ctlr_handle, ctlr->gen_lock); 310 TW_CL_Q_REMOVE_ITEM(&(ctlr->req_q_head[q_type]), &(req->link)); 311 TW_CLI_Q_REMOVE(ctlr, q_type); 312 tw_osl_free_lock(ctlr->ctlr_handle, ctlr->gen_lock); 313} 314 315 316 317/* Create an event packet for an event/error posted by the controller. */ 318#define tw_cli_create_ctlr_event(ctlr, event_src, cmd_hdr) do { \ 319 TW_UINT8 severity = \ 320 GET_SEVERITY((cmd_hdr)->status_block.res__severity); \ 321 \ 322 tw_cl_create_event(ctlr->ctlr_handle, TW_CL_TRUE, event_src, \ 323 (cmd_hdr)->status_block.error, \ 324 severity, \ 325 tw_cli_severity_string_table[severity], \ 326 (cmd_hdr)->err_specific_desc + \ 327 tw_osl_strlen((cmd_hdr)->err_specific_desc) + 1, \ 328 (cmd_hdr)->err_specific_desc); \ 329 /* Print 18 bytes of sense information. */ \ 330 tw_cli_dbg_printf(2, ctlr->ctlr_handle, \ 331 tw_osl_cur_func(), \ 332 "sense info: %x %x %x %x %x %x %x %x %x " \ 333 "%x %x %x %x %x %x %x %x %x", \ 334 (cmd_hdr)->sense_data[0], (cmd_hdr)->sense_data[1], \ 335 (cmd_hdr)->sense_data[2], (cmd_hdr)->sense_data[3], \ 336 (cmd_hdr)->sense_data[4], (cmd_hdr)->sense_data[5], \ 337 (cmd_hdr)->sense_data[6], (cmd_hdr)->sense_data[7], \ 338 (cmd_hdr)->sense_data[8], (cmd_hdr)->sense_data[9], \ 339 (cmd_hdr)->sense_data[10], (cmd_hdr)->sense_data[11], \ 340 (cmd_hdr)->sense_data[12], (cmd_hdr)->sense_data[13], \ 341 (cmd_hdr)->sense_data[14], (cmd_hdr)->sense_data[15], \ 342 (cmd_hdr)->sense_data[16], (cmd_hdr)->sense_data[17]); \ 343} while (0) 344 345 346 347#endif /* TW_CL_H */
|