2 * Copyright (c) 2004-07 Applied Micro Circuits Corporation.
3 * Copyright (c) 2004-05 Vinod Kashyap
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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
31 * AMCC'S 3ware driver for 9000 series storage controllers.
33 * Author: Vinod Kashyap
34 * Modifications by: Adam Radford
35 * Modifications by: Manjunath Ranganathaiah
40 * Common Layer initialization functions.
44 #include "tw_osl_share.h"
45 #include "tw_cl_share.h"
46 #include "tw_cl_fwif.h"
47 #include "tw_cl_ioctl.h"
49 #include "tw_cl_externs.h"
50 #include "tw_osl_ioctl.h"
54 * Function name: tw_cl_ctlr_supported
55 * Description: Determines if a controller is supported.
57 * Input: vendor_id -- vendor id of the controller
58 * device_id -- device id of the controller
60 * Return value: TW_CL_TRUE-- controller supported
61 * TW_CL_FALSE-- controller not supported
64 tw_cl_ctlr_supported(TW_INT32 vendor_id, TW_INT32 device_id)
66 if ((vendor_id == TW_CL_VENDOR_ID) &&
67 ((device_id == TW_CL_DEVICE_ID_9K) ||
68 (device_id == TW_CL_DEVICE_ID_9K_X) ||
69 (device_id == TW_CL_DEVICE_ID_9K_E) ||
70 (device_id == TW_CL_DEVICE_ID_9K_SA)))
78 * Function name: tw_cl_get_pci_bar_info
79 * Description: Returns PCI BAR info.
81 * Input: device_id -- device id of the controller
82 * bar_type -- type of PCI BAR in question
83 * Output: bar_num -- PCI BAR number corresponding to bar_type
84 * bar0_offset -- byte offset from BAR 0 (0x10 in
86 * bar_size -- size, in bytes, of the BAR in question
87 * Return value: 0 -- success
91 tw_cl_get_pci_bar_info(TW_INT32 device_id, TW_INT32 bar_type,
92 TW_INT32 *bar_num, TW_INT32 *bar0_offset, TW_INT32 *bar_size)
94 TW_INT32 error = TW_OSL_ESUCCESS;
97 case TW_CL_DEVICE_ID_9K:
99 case TW_CL_BAR_TYPE_IO:
105 case TW_CL_BAR_TYPE_MEM:
111 case TW_CL_BAR_TYPE_SBUF:
119 case TW_CL_DEVICE_ID_9K_X:
120 case TW_CL_DEVICE_ID_9K_E:
121 case TW_CL_DEVICE_ID_9K_SA:
123 case TW_CL_BAR_TYPE_IO:
129 case TW_CL_BAR_TYPE_MEM:
135 case TW_CL_BAR_TYPE_SBUF:
144 error = TW_OSL_ENOTTY;
154 * Function name: tw_cl_get_mem_requirements
155 * Description: Provides info about Common Layer requirements for a
156 * controller, given the controller type (in 'flags').
157 * Input: ctlr_handle -- controller handle
158 * flags -- more info passed by the OS Layer
159 * device_id -- device id of the controller
160 * max_simult_reqs -- maximum # of simultaneous
161 * requests that the OS Layer expects
162 * the Common Layer to support
163 * max_aens -- maximun # of AEN's needed to be supported
164 * Output: alignment -- alignment needed for all DMA'able
166 * sg_size_factor -- every SG element should have a size
167 * that's a multiple of this number
168 * non_dma_mem_size -- # of bytes of memory needed for
170 * dma_mem_size -- # of bytes of DMA'able memory needed
171 * per_req_dma_mem_size -- # of bytes of DMA'able memory
172 * needed per request, if applicable
173 * per_req_non_dma_mem_size -- # of bytes of memory needed
174 * per request for non-DMA purposes,
177 * Return value: 0 -- success
181 tw_cl_get_mem_requirements(struct tw_cl_ctlr_handle *ctlr_handle,
182 TW_UINT32 flags, TW_INT32 device_id, TW_INT32 max_simult_reqs,
183 TW_INT32 max_aens, TW_UINT32 *alignment, TW_UINT32 *sg_size_factor,
184 TW_UINT32 *non_dma_mem_size, TW_UINT32 *dma_mem_size
188 device_id = TW_CL_DEVICE_ID_9K;
190 if (max_simult_reqs > TW_CL_MAX_SIMULTANEOUS_REQUESTS) {
191 tw_cl_create_event(ctlr_handle, TW_CL_FALSE,
192 TW_CL_MESSAGE_SOURCE_COMMON_LAYER_ERROR,
193 0x1000, 0x1, TW_CL_SEVERITY_ERROR_STRING,
194 "Too many simultaneous requests to support!",
195 "requested = %d, supported = %d, error = %d\n",
196 max_simult_reqs, TW_CL_MAX_SIMULTANEOUS_REQUESTS,
201 *alignment = TWA_ALIGNMENT(device_id);
202 *sg_size_factor = TWA_SG_ELEMENT_SIZE_FACTOR(device_id);
205 * Total non-DMA memory needed is the sum total of memory needed for
206 * the controller context, request packets (including the 1 needed for
207 * CL internal requests), and event packets.
210 *non_dma_mem_size = sizeof(struct tw_cli_ctlr_context) +
211 (sizeof(struct tw_cli_req_context) * max_simult_reqs) +
212 (sizeof(struct tw_cl_event_packet) * max_aens);
216 * Total DMA'able memory needed is the sum total of memory needed for
217 * all command packets (including the 1 needed for CL internal
218 * requests), and memory needed to hold the payload for internal
222 *dma_mem_size = (sizeof(struct tw_cl_command_packet) *
223 (max_simult_reqs)) + (TW_CLI_SECTOR_SIZE);
231 * Function name: tw_cl_init_ctlr
232 * Description: Initializes driver data structures for the controller.
234 * Input: ctlr_handle -- controller handle
235 * flags -- more info passed by the OS Layer
236 * device_id -- device id of the controller
237 * max_simult_reqs -- maximum # of simultaneous requests
238 * that the OS Layer expects the Common
240 * max_aens -- maximun # of AEN's needed to be supported
241 * non_dma_mem -- ptr to allocated non-DMA memory
242 * dma_mem -- ptr to allocated DMA'able memory
243 * dma_mem_phys -- physical address of dma_mem
245 * Return value: 0 -- success
249 tw_cl_init_ctlr(struct tw_cl_ctlr_handle *ctlr_handle, TW_UINT32 flags,
250 TW_INT32 device_id, TW_INT32 max_simult_reqs, TW_INT32 max_aens,
251 TW_VOID *non_dma_mem, TW_VOID *dma_mem, TW_UINT64 dma_mem_phys
254 struct tw_cli_ctlr_context *ctlr;
255 struct tw_cli_req_context *req;
256 TW_UINT8 *free_non_dma_mem;
257 TW_INT32 error = TW_OSL_ESUCCESS;
260 tw_cli_dbg_printf(3, ctlr_handle, tw_osl_cur_func(), "entered");
262 if (flags & TW_CL_START_CTLR_ONLY) {
263 ctlr = (struct tw_cli_ctlr_context *)
264 (ctlr_handle->cl_ctlr_ctxt);
268 if (max_simult_reqs > TW_CL_MAX_SIMULTANEOUS_REQUESTS) {
269 tw_cl_create_event(ctlr_handle, TW_CL_FALSE,
270 TW_CL_MESSAGE_SOURCE_COMMON_LAYER_ERROR,
271 0x1000, 0x1, TW_CL_SEVERITY_ERROR_STRING,
272 "Too many simultaneous requests to support!",
273 "requested = %d, supported = %d, error = %d\n",
274 max_simult_reqs, TW_CL_MAX_SIMULTANEOUS_REQUESTS,
279 if ((non_dma_mem == TW_CL_NULL) || (dma_mem == TW_CL_NULL)
281 tw_cl_create_event(ctlr_handle, TW_CL_FALSE,
282 TW_CL_MESSAGE_SOURCE_COMMON_LAYER_ERROR,
283 0x1001, 0x1, TW_CL_SEVERITY_ERROR_STRING,
284 "Insufficient memory for Common Layer's internal usage",
285 "error = %d\n", TW_OSL_ENOMEM);
286 return(TW_OSL_ENOMEM);
289 tw_osl_memzero(non_dma_mem, sizeof(struct tw_cli_ctlr_context) +
290 (sizeof(struct tw_cli_req_context) * max_simult_reqs) +
291 (sizeof(struct tw_cl_event_packet) * max_aens));
293 tw_osl_memzero(dma_mem,
294 (sizeof(struct tw_cl_command_packet) *
298 free_non_dma_mem = (TW_UINT8 *)non_dma_mem;
300 ctlr = (struct tw_cli_ctlr_context *)free_non_dma_mem;
301 free_non_dma_mem += sizeof(struct tw_cli_ctlr_context);
303 ctlr_handle->cl_ctlr_ctxt = ctlr;
304 ctlr->ctlr_handle = ctlr_handle;
306 ctlr->device_id = (TW_UINT32)device_id;
307 ctlr->arch_id = TWA_ARCH_ID(device_id);
309 ctlr->sg_size_factor = TWA_SG_ELEMENT_SIZE_FACTOR(device_id);
310 ctlr->max_simult_reqs = max_simult_reqs;
311 ctlr->max_aens_supported = max_aens;
313 /* Initialize queues of CL internal request context packets. */
314 tw_cli_req_q_init(ctlr, TW_CLI_FREE_Q);
315 tw_cli_req_q_init(ctlr, TW_CLI_BUSY_Q);
316 tw_cli_req_q_init(ctlr, TW_CLI_PENDING_Q);
317 tw_cli_req_q_init(ctlr, TW_CLI_COMPLETE_Q);
318 tw_cli_req_q_init(ctlr, TW_CLI_RESET_Q);
320 /* Initialize all locks used by CL. */
321 ctlr->gen_lock = &(ctlr->gen_lock_handle);
322 tw_osl_init_lock(ctlr_handle, "tw_cl_gen_lock", ctlr->gen_lock);
323 ctlr->io_lock = &(ctlr->io_lock_handle);
324 tw_osl_init_lock(ctlr_handle, "tw_cl_io_lock", ctlr->io_lock);
326 /* Initialize CL internal request context packets. */
327 ctlr->req_ctxt_buf = (struct tw_cli_req_context *)free_non_dma_mem;
328 free_non_dma_mem += (sizeof(struct tw_cli_req_context) *
331 ctlr->cmd_pkt_buf = (struct tw_cl_command_packet *)dma_mem;
332 ctlr->cmd_pkt_phys = dma_mem_phys;
334 ctlr->internal_req_data = (TW_UINT8 *)
337 ctlr->internal_req_data_phys = ctlr->cmd_pkt_phys +
338 (sizeof(struct tw_cl_command_packet) *
341 for (i = 0; i < max_simult_reqs; i++) {
342 req = &(ctlr->req_ctxt_buf[i]);
344 req->cmd_pkt = &(ctlr->cmd_pkt_buf[i]);
345 req->cmd_pkt_phys = ctlr->cmd_pkt_phys +
346 (i * sizeof(struct tw_cl_command_packet));
351 /* Insert request into the free queue. */
352 tw_cli_req_q_insert_tail(req, TW_CLI_FREE_Q);
355 /* Initialize the AEN queue. */
356 ctlr->aen_queue = (struct tw_cl_event_packet *)free_non_dma_mem;
361 * Disable interrupts. Interrupts will be enabled in tw_cli_start_ctlr
362 * (only) if initialization succeeded.
364 tw_cli_disable_interrupts(ctlr);
366 /* Initialize the controller. */
367 if ((error = tw_cli_start_ctlr(ctlr))) {
368 /* Soft reset the controller, and try one more time. */
369 tw_cl_create_event(ctlr_handle, TW_CL_FALSE,
370 TW_CL_MESSAGE_SOURCE_COMMON_LAYER_ERROR,
371 0x1002, 0x1, TW_CL_SEVERITY_ERROR_STRING,
372 "Controller initialization failed. Retrying...",
373 "error = %d\n", error);
374 if ((error = tw_cli_soft_reset(ctlr))) {
375 tw_cl_create_event(ctlr_handle, TW_CL_FALSE,
376 TW_CL_MESSAGE_SOURCE_COMMON_LAYER_ERROR,
377 0x1003, 0x1, TW_CL_SEVERITY_ERROR_STRING,
378 "Controller soft reset failed",
379 "error = %d\n", error);
381 } else if ((error = tw_cli_start_ctlr(ctlr))) {
382 tw_cl_create_event(ctlr_handle, TW_CL_FALSE,
383 TW_CL_MESSAGE_SOURCE_COMMON_LAYER_ERROR,
384 0x1004, 0x1, TW_CL_SEVERITY_ERROR_STRING,
385 "Controller initialization retry failed",
386 "error = %d\n", error);
390 /* Notify some info about the controller to the OSL. */
391 tw_cli_notify_ctlr_info(ctlr);
393 /* Mark the controller active. */
394 ctlr->active = TW_CL_TRUE;
399 * Function name: tw_cli_start_ctlr
400 * Description: Establishes a logical connection with the controller.
401 * Determines whether or not the driver is compatible
402 * with the firmware on the controller, before proceeding
405 * Input: ctlr -- ptr to per ctlr structure
407 * Return value: 0 -- success
411 tw_cli_start_ctlr(struct tw_cli_ctlr_context *ctlr)
413 TW_UINT16 fw_on_ctlr_srl = 0;
414 TW_UINT16 fw_on_ctlr_arch_id = 0;
415 TW_UINT16 fw_on_ctlr_branch = 0;
416 TW_UINT16 fw_on_ctlr_build = 0;
417 TW_UINT32 init_connect_result = 0;
418 TW_INT32 error = TW_OSL_ESUCCESS;
420 tw_cli_dbg_printf(3, ctlr->ctlr_handle, tw_osl_cur_func(), "entered");
422 /* Wait for the controller to become ready. */
423 if ((error = tw_cli_poll_status(ctlr,
424 TWA_STATUS_MICROCONTROLLER_READY,
425 TW_CLI_REQUEST_TIMEOUT_PERIOD))) {
426 tw_cl_create_event(ctlr->ctlr_handle, TW_CL_FALSE,
427 TW_CL_MESSAGE_SOURCE_COMMON_LAYER_ERROR,
428 0x1009, 0x1, TW_CL_SEVERITY_ERROR_STRING,
429 "Microcontroller not ready",
430 "error = %d", error);
433 /* Drain the response queue. */
434 if ((error = tw_cli_drain_response_queue(ctlr))) {
435 tw_cl_create_event(ctlr->ctlr_handle, TW_CL_FALSE,
436 TW_CL_MESSAGE_SOURCE_COMMON_LAYER_ERROR,
437 0x100A, 0x1, TW_CL_SEVERITY_ERROR_STRING,
438 "Can't drain response queue",
439 "error = %d", error);
442 /* Establish a logical connection with the controller. */
443 if ((error = tw_cli_init_connection(ctlr,
444 (TW_UINT16)(ctlr->max_simult_reqs),
445 TWA_EXTENDED_INIT_CONNECT, TWA_CURRENT_FW_SRL,
446 (TW_UINT16)(ctlr->arch_id),
447 TWA_CURRENT_FW_BRANCH(ctlr->arch_id),
448 TWA_CURRENT_FW_BUILD(ctlr->arch_id),
449 &fw_on_ctlr_srl, &fw_on_ctlr_arch_id,
450 &fw_on_ctlr_branch, &fw_on_ctlr_build,
451 &init_connect_result))) {
452 tw_cl_create_event(ctlr->ctlr_handle, TW_CL_FALSE,
453 TW_CL_MESSAGE_SOURCE_COMMON_LAYER_ERROR,
454 0x100B, 0x2, TW_CL_SEVERITY_WARNING_STRING,
455 "Can't initialize connection in current mode",
456 "error = %d", error);
460 /* See if we can at least work with the firmware on the
461 * controller in the current mode.
463 if (init_connect_result & TWA_CTLR_FW_COMPATIBLE) {
464 /* Yes, we can. Make note of the operating mode. */
465 if (init_connect_result & TWA_CTLR_FW_SAME_OR_NEWER) {
466 ctlr->working_srl = TWA_CURRENT_FW_SRL;
467 ctlr->working_branch =
468 TWA_CURRENT_FW_BRANCH(ctlr->arch_id);
469 ctlr->working_build =
470 TWA_CURRENT_FW_BUILD(ctlr->arch_id);
472 ctlr->working_srl = fw_on_ctlr_srl;
473 ctlr->working_branch = fw_on_ctlr_branch;
474 ctlr->working_build = fw_on_ctlr_build;
478 * No, we can't. See if we can at least work with
479 * it in the base mode.
481 tw_cl_create_event(ctlr->ctlr_handle, TW_CL_FALSE,
482 TW_CL_MESSAGE_SOURCE_COMMON_LAYER_ERROR,
483 0x1010, 0x2, TW_CL_SEVERITY_WARNING_STRING,
484 "Driver/Firmware mismatch. "
485 "Negotiating for base level...",
487 if ((error = tw_cli_init_connection(ctlr,
488 (TW_UINT16)(ctlr->max_simult_reqs),
489 TWA_EXTENDED_INIT_CONNECT,
491 (TW_UINT16)(ctlr->arch_id),
492 TWA_BASE_FW_BRANCH, TWA_BASE_FW_BUILD,
493 &fw_on_ctlr_srl, &fw_on_ctlr_arch_id,
494 &fw_on_ctlr_branch, &fw_on_ctlr_build,
495 &init_connect_result))) {
496 tw_cl_create_event(ctlr->ctlr_handle,
498 TW_CL_MESSAGE_SOURCE_COMMON_LAYER_ERROR,
500 TW_CL_SEVERITY_ERROR_STRING,
501 "Can't initialize connection in "
506 if (!(init_connect_result & TWA_CTLR_FW_COMPATIBLE)) {
508 * The firmware on the controller is not even
509 * compatible with our base mode. We cannot
510 * work with it. Bail...
515 * We can work with this firmware, but only in
518 ctlr->working_srl = TWA_BASE_FW_SRL;
519 ctlr->working_branch = TWA_BASE_FW_BRANCH;
520 ctlr->working_build = TWA_BASE_FW_BUILD;
521 ctlr->operating_mode = TWA_BASE_MODE;
523 ctlr->fw_on_ctlr_srl = fw_on_ctlr_srl;
524 ctlr->fw_on_ctlr_branch = fw_on_ctlr_branch;
525 ctlr->fw_on_ctlr_build = fw_on_ctlr_build;
528 /* Drain the AEN queue */
529 if ((error = tw_cli_drain_aen_queue(ctlr)))
531 * We will just print that we couldn't drain the AEN queue.
532 * There's no need to bail out.
534 tw_cl_create_event(ctlr->ctlr_handle, TW_CL_FALSE,
535 TW_CL_MESSAGE_SOURCE_COMMON_LAYER_ERROR,
536 0x1014, 0x2, TW_CL_SEVERITY_WARNING_STRING,
537 "Can't drain AEN queue",
538 "error = %d", error);
540 /* Enable interrupts. */
541 tw_cli_enable_interrupts(ctlr);
543 return(TW_OSL_ESUCCESS);
548 * Function name: tw_cl_shutdown_ctlr
549 * Description: Closes logical connection with the controller.
551 * Input: ctlr -- ptr to per ctlr structure
552 * flags -- more info passed by the OS Layer
554 * Return value: 0 -- success
558 tw_cl_shutdown_ctlr(struct tw_cl_ctlr_handle *ctlr_handle, TW_UINT32 flags)
560 struct tw_cli_ctlr_context *ctlr =
561 (struct tw_cli_ctlr_context *)(ctlr_handle->cl_ctlr_ctxt);
564 tw_cli_dbg_printf(3, ctlr_handle, tw_osl_cur_func(), "entered");
566 * Mark the controller as inactive, disable any further interrupts,
567 * and notify the controller that we are going down.
569 ctlr->active = TW_CL_FALSE;
571 tw_cli_disable_interrupts(ctlr);
573 /* Let the controller know that we are going down. */
574 if ((error = tw_cli_init_connection(ctlr, TWA_SHUTDOWN_MESSAGE_CREDITS,
575 0, 0, 0, 0, 0, TW_CL_NULL, TW_CL_NULL, TW_CL_NULL,
576 TW_CL_NULL, TW_CL_NULL)))
577 tw_cl_create_event(ctlr_handle, TW_CL_FALSE,
578 TW_CL_MESSAGE_SOURCE_COMMON_LAYER_ERROR,
579 0x1015, 0x1, TW_CL_SEVERITY_ERROR_STRING,
580 "Can't close connection with controller",
581 "error = %d", error);
583 if (flags & TW_CL_STOP_CTLR_ONLY)
586 /* Destroy all locks used by CL. */
587 tw_osl_destroy_lock(ctlr_handle, ctlr->gen_lock);
588 tw_osl_destroy_lock(ctlr_handle, ctlr->io_lock);
597 * Function name: tw_cli_init_connection
598 * Description: Sends init_connection cmd to firmware
600 * Input: ctlr -- ptr to per ctlr structure
601 * message_credits -- max # of requests that we might send
602 * down simultaneously. This will be
603 * typically set to 256 at init-time or
604 * after a reset, and to 1 at shutdown-time
605 * set_features -- indicates if we intend to use 64-bit
606 * sg, also indicates if we want to do a
607 * basic or an extended init_connection;
609 * Note: The following input/output parameters are valid, only in case of an
610 * extended init_connection:
612 * current_fw_srl -- srl of fw we are bundled
613 * with, if any; 0 otherwise
614 * current_fw_arch_id -- arch_id of fw we are bundled
615 * with, if any; 0 otherwise
616 * current_fw_branch -- branch # of fw we are bundled
617 * with, if any; 0 otherwise
618 * current_fw_build -- build # of fw we are bundled
619 * with, if any; 0 otherwise
620 * Output: fw_on_ctlr_srl -- srl of fw on ctlr
621 * fw_on_ctlr_arch_id -- arch_id of fw on ctlr
622 * fw_on_ctlr_branch -- branch # of fw on ctlr
623 * fw_on_ctlr_build -- build # of fw on ctlr
624 * init_connect_result -- result bitmap of fw response
625 * Return value: 0 -- success
629 tw_cli_init_connection(struct tw_cli_ctlr_context *ctlr,
630 TW_UINT16 message_credits, TW_UINT32 set_features,
631 TW_UINT16 current_fw_srl, TW_UINT16 current_fw_arch_id,
632 TW_UINT16 current_fw_branch, TW_UINT16 current_fw_build,
633 TW_UINT16 *fw_on_ctlr_srl, TW_UINT16 *fw_on_ctlr_arch_id,
634 TW_UINT16 *fw_on_ctlr_branch, TW_UINT16 *fw_on_ctlr_build,
635 TW_UINT32 *init_connect_result)
637 struct tw_cli_req_context *req;
638 struct tw_cl_command_init_connect *init_connect;
639 TW_INT32 error = TW_OSL_EBUSY;
641 tw_cli_dbg_printf(3, ctlr->ctlr_handle, tw_osl_cur_func(), "entered");
643 /* Get a request packet. */
644 if ((req = tw_cli_get_request(ctlr
648 req->flags |= TW_CLI_REQ_FLAGS_INTERNAL;
650 /* Build the cmd pkt. */
651 init_connect = &(req->cmd_pkt->command.cmd_pkt_7k.init_connect);
653 req->cmd_pkt->cmd_hdr.header_desc.size_header = 128;
655 init_connect->res1__opcode =
656 BUILD_RES__OPCODE(0, TWA_FW_CMD_INIT_CONNECTION);
657 init_connect->request_id =
658 (TW_UINT8)(TW_CL_SWAP16(req->request_id));
659 init_connect->message_credits = TW_CL_SWAP16(message_credits);
660 init_connect->features = TW_CL_SWAP32(set_features);
661 if (ctlr->flags & TW_CL_64BIT_ADDRESSES)
662 init_connect->features |= TW_CL_SWAP32(TWA_64BIT_SG_ADDRESSES);
663 if (set_features & TWA_EXTENDED_INIT_CONNECT) {
665 * Fill in the extra fields needed for an extended
668 init_connect->size = 6;
669 init_connect->fw_srl = TW_CL_SWAP16(current_fw_srl);
670 init_connect->fw_arch_id = TW_CL_SWAP16(current_fw_arch_id);
671 init_connect->fw_branch = TW_CL_SWAP16(current_fw_branch);
672 init_connect->fw_build = TW_CL_SWAP16(current_fw_build);
674 init_connect->size = 3;
676 /* Submit the command, and wait for it to complete. */
677 error = tw_cli_submit_and_poll_request(req,
678 TW_CLI_REQUEST_TIMEOUT_PERIOD);
681 if ((error = init_connect->status)) {
683 tw_cli_create_ctlr_event(ctlr,
684 TW_CL_MESSAGE_SOURCE_CONTROLLER_ERROR,
685 &(req->cmd_pkt->cmd_hdr));
689 if (set_features & TWA_EXTENDED_INIT_CONNECT) {
690 *fw_on_ctlr_srl = TW_CL_SWAP16(init_connect->fw_srl);
691 *fw_on_ctlr_arch_id = TW_CL_SWAP16(init_connect->fw_arch_id);
692 *fw_on_ctlr_branch = TW_CL_SWAP16(init_connect->fw_branch);
693 *fw_on_ctlr_build = TW_CL_SWAP16(init_connect->fw_build);
694 *init_connect_result = TW_CL_SWAP32(init_connect->result);
696 tw_cli_req_q_insert_tail(req, TW_CLI_FREE_Q);
700 tw_cl_create_event(ctlr->ctlr_handle, TW_CL_FALSE,
701 TW_CL_MESSAGE_SOURCE_COMMON_LAYER_ERROR,
702 0x1016, 0x1, TW_CL_SEVERITY_ERROR_STRING,
703 "init_connection failed",
704 "error = %d", error);
706 tw_cli_req_q_insert_tail(req, TW_CLI_FREE_Q);