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
27 * $FreeBSD: src/sys/dev/twa/tw_cl_init.c,v 1.6 2010/06/09 21:40:38 delphij Exp $
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);
319 /* Initialize all locks used by CL. */
320 ctlr->gen_lock = &(ctlr->gen_lock_handle);
321 tw_osl_init_lock(ctlr_handle, "tw_cl_gen_lock", ctlr->gen_lock);
322 ctlr->io_lock = &(ctlr->io_lock_handle);
323 tw_osl_init_lock(ctlr_handle, "tw_cl_io_lock", ctlr->io_lock);
325 /* Initialize CL internal request context packets. */
326 ctlr->req_ctxt_buf = (struct tw_cli_req_context *)free_non_dma_mem;
327 free_non_dma_mem += (sizeof(struct tw_cli_req_context) *
330 ctlr->cmd_pkt_buf = (struct tw_cl_command_packet *)dma_mem;
331 ctlr->cmd_pkt_phys = dma_mem_phys;
333 ctlr->internal_req_data = (TW_UINT8 *)
336 ctlr->internal_req_data_phys = ctlr->cmd_pkt_phys +
337 (sizeof(struct tw_cl_command_packet) *
340 for (i = 0; i < max_simult_reqs; i++) {
341 req = &(ctlr->req_ctxt_buf[i]);
343 req->cmd_pkt = &(ctlr->cmd_pkt_buf[i]);
344 req->cmd_pkt_phys = ctlr->cmd_pkt_phys +
345 (i * sizeof(struct tw_cl_command_packet));
350 /* Insert request into the free queue. */
351 tw_cli_req_q_insert_tail(req, TW_CLI_FREE_Q);
354 /* Initialize the AEN queue. */
355 ctlr->aen_queue = (struct tw_cl_event_packet *)free_non_dma_mem;
360 * Disable interrupts. Interrupts will be enabled in tw_cli_start_ctlr
361 * (only) if initialization succeeded.
363 tw_cli_disable_interrupts(ctlr);
365 /* Initialize the controller. */
366 if ((error = tw_cli_start_ctlr(ctlr))) {
367 /* Soft reset the controller, and try one more time. */
368 tw_cl_create_event(ctlr_handle, TW_CL_FALSE,
369 TW_CL_MESSAGE_SOURCE_COMMON_LAYER_ERROR,
370 0x1002, 0x1, TW_CL_SEVERITY_ERROR_STRING,
371 "Controller initialization failed. Retrying...",
372 "error = %d\n", error);
373 if ((error = tw_cli_soft_reset(ctlr))) {
374 tw_cl_create_event(ctlr_handle, TW_CL_FALSE,
375 TW_CL_MESSAGE_SOURCE_COMMON_LAYER_ERROR,
376 0x1003, 0x1, TW_CL_SEVERITY_ERROR_STRING,
377 "Controller soft reset failed",
378 "error = %d\n", error);
380 } else if ((error = tw_cli_start_ctlr(ctlr))) {
381 tw_cl_create_event(ctlr_handle, TW_CL_FALSE,
382 TW_CL_MESSAGE_SOURCE_COMMON_LAYER_ERROR,
383 0x1004, 0x1, TW_CL_SEVERITY_ERROR_STRING,
384 "Controller initialization retry failed",
385 "error = %d\n", error);
389 /* Notify some info about the controller to the OSL. */
390 tw_cli_notify_ctlr_info(ctlr);
392 /* Mark the controller active. */
393 ctlr->active = TW_CL_TRUE;
398 * Function name: tw_cli_start_ctlr
399 * Description: Establishes a logical connection with the controller.
400 * Determines whether or not the driver is compatible
401 * with the firmware on the controller, before proceeding
404 * Input: ctlr -- ptr to per ctlr structure
406 * Return value: 0 -- success
410 tw_cli_start_ctlr(struct tw_cli_ctlr_context *ctlr)
412 TW_UINT16 fw_on_ctlr_srl = 0;
413 TW_UINT16 fw_on_ctlr_arch_id = 0;
414 TW_UINT16 fw_on_ctlr_branch = 0;
415 TW_UINT16 fw_on_ctlr_build = 0;
416 TW_UINT32 init_connect_result = 0;
417 TW_INT32 error = TW_OSL_ESUCCESS;
419 tw_cli_dbg_printf(3, ctlr->ctlr_handle, tw_osl_cur_func(), "entered");
421 /* Wait for the controller to become ready. */
422 if ((error = tw_cli_poll_status(ctlr,
423 TWA_STATUS_MICROCONTROLLER_READY,
424 TW_CLI_REQUEST_TIMEOUT_PERIOD))) {
425 tw_cl_create_event(ctlr->ctlr_handle, TW_CL_FALSE,
426 TW_CL_MESSAGE_SOURCE_COMMON_LAYER_ERROR,
427 0x1009, 0x1, TW_CL_SEVERITY_ERROR_STRING,
428 "Microcontroller not ready",
429 "error = %d", error);
432 /* Drain the response queue. */
433 if ((error = tw_cli_drain_response_queue(ctlr))) {
434 tw_cl_create_event(ctlr->ctlr_handle, TW_CL_FALSE,
435 TW_CL_MESSAGE_SOURCE_COMMON_LAYER_ERROR,
436 0x100A, 0x1, TW_CL_SEVERITY_ERROR_STRING,
437 "Can't drain response queue",
438 "error = %d", error);
441 /* Establish a logical connection with the controller. */
442 if ((error = tw_cli_init_connection(ctlr,
443 (TW_UINT16)(ctlr->max_simult_reqs),
444 TWA_EXTENDED_INIT_CONNECT, TWA_CURRENT_FW_SRL,
445 (TW_UINT16)(ctlr->arch_id),
446 TWA_CURRENT_FW_BRANCH(ctlr->arch_id),
447 TWA_CURRENT_FW_BUILD(ctlr->arch_id),
448 &fw_on_ctlr_srl, &fw_on_ctlr_arch_id,
449 &fw_on_ctlr_branch, &fw_on_ctlr_build,
450 &init_connect_result))) {
451 tw_cl_create_event(ctlr->ctlr_handle, TW_CL_FALSE,
452 TW_CL_MESSAGE_SOURCE_COMMON_LAYER_ERROR,
453 0x100B, 0x2, TW_CL_SEVERITY_WARNING_STRING,
454 "Can't initialize connection in current mode",
455 "error = %d", error);
459 /* See if we can at least work with the firmware on the
460 * controller in the current mode.
462 if (init_connect_result & TWA_CTLR_FW_COMPATIBLE) {
463 /* Yes, we can. Make note of the operating mode. */
464 if (init_connect_result & TWA_CTLR_FW_SAME_OR_NEWER) {
465 ctlr->working_srl = TWA_CURRENT_FW_SRL;
466 ctlr->working_branch =
467 TWA_CURRENT_FW_BRANCH(ctlr->arch_id);
468 ctlr->working_build =
469 TWA_CURRENT_FW_BUILD(ctlr->arch_id);
471 ctlr->working_srl = fw_on_ctlr_srl;
472 ctlr->working_branch = fw_on_ctlr_branch;
473 ctlr->working_build = fw_on_ctlr_build;
477 * No, we can't. See if we can at least work with
478 * it in the base mode.
480 tw_cl_create_event(ctlr->ctlr_handle, TW_CL_FALSE,
481 TW_CL_MESSAGE_SOURCE_COMMON_LAYER_ERROR,
482 0x1010, 0x2, TW_CL_SEVERITY_WARNING_STRING,
483 "Driver/Firmware mismatch. "
484 "Negotiating for base level...",
486 if ((error = tw_cli_init_connection(ctlr,
487 (TW_UINT16)(ctlr->max_simult_reqs),
488 TWA_EXTENDED_INIT_CONNECT,
490 (TW_UINT16)(ctlr->arch_id),
491 TWA_BASE_FW_BRANCH, TWA_BASE_FW_BUILD,
492 &fw_on_ctlr_srl, &fw_on_ctlr_arch_id,
493 &fw_on_ctlr_branch, &fw_on_ctlr_build,
494 &init_connect_result))) {
495 tw_cl_create_event(ctlr->ctlr_handle,
497 TW_CL_MESSAGE_SOURCE_COMMON_LAYER_ERROR,
499 TW_CL_SEVERITY_ERROR_STRING,
500 "Can't initialize connection in "
505 if (!(init_connect_result & TWA_CTLR_FW_COMPATIBLE)) {
507 * The firmware on the controller is not even
508 * compatible with our base mode. We cannot
509 * work with it. Bail...
514 * We can work with this firmware, but only in
517 ctlr->working_srl = TWA_BASE_FW_SRL;
518 ctlr->working_branch = TWA_BASE_FW_BRANCH;
519 ctlr->working_build = TWA_BASE_FW_BUILD;
520 ctlr->operating_mode = TWA_BASE_MODE;
522 ctlr->fw_on_ctlr_srl = fw_on_ctlr_srl;
523 ctlr->fw_on_ctlr_branch = fw_on_ctlr_branch;
524 ctlr->fw_on_ctlr_build = fw_on_ctlr_build;
527 /* Drain the AEN queue */
528 if ((error = tw_cli_drain_aen_queue(ctlr)))
530 * We will just print that we couldn't drain the AEN queue.
531 * There's no need to bail out.
533 tw_cl_create_event(ctlr->ctlr_handle, TW_CL_FALSE,
534 TW_CL_MESSAGE_SOURCE_COMMON_LAYER_ERROR,
535 0x1014, 0x2, TW_CL_SEVERITY_WARNING_STRING,
536 "Can't drain AEN queue",
537 "error = %d", error);
539 /* Enable interrupts. */
540 tw_cli_enable_interrupts(ctlr);
542 return(TW_OSL_ESUCCESS);
547 * Function name: tw_cl_shutdown_ctlr
548 * Description: Closes logical connection with the controller.
550 * Input: ctlr -- ptr to per ctlr structure
551 * flags -- more info passed by the OS Layer
553 * Return value: 0 -- success
557 tw_cl_shutdown_ctlr(struct tw_cl_ctlr_handle *ctlr_handle, TW_UINT32 flags)
559 struct tw_cli_ctlr_context *ctlr =
560 (struct tw_cli_ctlr_context *)(ctlr_handle->cl_ctlr_ctxt);
563 tw_cli_dbg_printf(3, ctlr_handle, tw_osl_cur_func(), "entered");
565 * Mark the controller as inactive, disable any further interrupts,
566 * and notify the controller that we are going down.
568 ctlr->active = TW_CL_FALSE;
570 tw_cli_disable_interrupts(ctlr);
572 /* Let the controller know that we are going down. */
573 if ((error = tw_cli_init_connection(ctlr, TWA_SHUTDOWN_MESSAGE_CREDITS,
574 0, 0, 0, 0, 0, TW_CL_NULL, TW_CL_NULL, TW_CL_NULL,
575 TW_CL_NULL, TW_CL_NULL)))
576 tw_cl_create_event(ctlr_handle, TW_CL_FALSE,
577 TW_CL_MESSAGE_SOURCE_COMMON_LAYER_ERROR,
578 0x1015, 0x1, TW_CL_SEVERITY_ERROR_STRING,
579 "Can't close connection with controller",
580 "error = %d", error);
582 if (flags & TW_CL_STOP_CTLR_ONLY)
585 /* Destroy all locks used by CL. */
586 tw_osl_destroy_lock(ctlr_handle, ctlr->gen_lock);
587 tw_osl_destroy_lock(ctlr_handle, ctlr->io_lock);
596 * Function name: tw_cli_init_connection
597 * Description: Sends init_connection cmd to firmware
599 * Input: ctlr -- ptr to per ctlr structure
600 * message_credits -- max # of requests that we might send
601 * down simultaneously. This will be
602 * typically set to 256 at init-time or
603 * after a reset, and to 1 at shutdown-time
604 * set_features -- indicates if we intend to use 64-bit
605 * sg, also indicates if we want to do a
606 * basic or an extended init_connection;
608 * Note: The following input/output parameters are valid, only in case of an
609 * extended init_connection:
611 * current_fw_srl -- srl of fw we are bundled
612 * with, if any; 0 otherwise
613 * current_fw_arch_id -- arch_id of fw we are bundled
614 * with, if any; 0 otherwise
615 * current_fw_branch -- branch # of fw we are bundled
616 * with, if any; 0 otherwise
617 * current_fw_build -- build # of fw we are bundled
618 * with, if any; 0 otherwise
619 * Output: fw_on_ctlr_srl -- srl of fw on ctlr
620 * fw_on_ctlr_arch_id -- arch_id of fw on ctlr
621 * fw_on_ctlr_branch -- branch # of fw on ctlr
622 * fw_on_ctlr_build -- build # of fw on ctlr
623 * init_connect_result -- result bitmap of fw response
624 * Return value: 0 -- success
628 tw_cli_init_connection(struct tw_cli_ctlr_context *ctlr,
629 TW_UINT16 message_credits, TW_UINT32 set_features,
630 TW_UINT16 current_fw_srl, TW_UINT16 current_fw_arch_id,
631 TW_UINT16 current_fw_branch, TW_UINT16 current_fw_build,
632 TW_UINT16 *fw_on_ctlr_srl, TW_UINT16 *fw_on_ctlr_arch_id,
633 TW_UINT16 *fw_on_ctlr_branch, TW_UINT16 *fw_on_ctlr_build,
634 TW_UINT32 *init_connect_result)
636 struct tw_cli_req_context *req;
637 struct tw_cl_command_init_connect *init_connect;
638 TW_INT32 error = TW_OSL_EBUSY;
640 tw_cli_dbg_printf(3, ctlr->ctlr_handle, tw_osl_cur_func(), "entered");
642 /* Get a request packet. */
643 if ((req = tw_cli_get_request(ctlr
647 req->flags |= TW_CLI_REQ_FLAGS_INTERNAL;
649 /* Build the cmd pkt. */
650 init_connect = &(req->cmd_pkt->command.cmd_pkt_7k.init_connect);
652 req->cmd_pkt->cmd_hdr.header_desc.size_header = 128;
654 init_connect->res1__opcode =
655 BUILD_RES__OPCODE(0, TWA_FW_CMD_INIT_CONNECTION);
656 init_connect->request_id =
657 (TW_UINT8)(TW_CL_SWAP16(req->request_id));
658 init_connect->message_credits = TW_CL_SWAP16(message_credits);
659 init_connect->features = TW_CL_SWAP32(set_features);
660 if (ctlr->flags & TW_CL_64BIT_ADDRESSES)
661 init_connect->features |= TW_CL_SWAP32(TWA_64BIT_SG_ADDRESSES);
662 if (set_features & TWA_EXTENDED_INIT_CONNECT) {
664 * Fill in the extra fields needed for an extended
667 init_connect->size = 6;
668 init_connect->fw_srl = TW_CL_SWAP16(current_fw_srl);
669 init_connect->fw_arch_id = TW_CL_SWAP16(current_fw_arch_id);
670 init_connect->fw_branch = TW_CL_SWAP16(current_fw_branch);
671 init_connect->fw_build = TW_CL_SWAP16(current_fw_build);
673 init_connect->size = 3;
675 /* Submit the command, and wait for it to complete. */
676 error = tw_cli_submit_and_poll_request(req,
677 TW_CLI_REQUEST_TIMEOUT_PERIOD);
678 if (error == TW_OSL_ETIMEDOUT)
679 /* Clean-up done by tw_cli_submit_and_poll_request. */
683 if ((error = init_connect->status)) {
684 tw_cli_create_ctlr_event(ctlr,
685 TW_CL_MESSAGE_SOURCE_CONTROLLER_ERROR,
686 &(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);