mpt.c revision 213105
1139749Simp/*- 2156000Smjacob * Generic routines for LSI Fusion adapters. 3101704Smjacob * FreeBSD Version. 4101704Smjacob * 5101704Smjacob * Copyright (c) 2000, 2001 by Greg Ansley 6101704Smjacob * 7101704Smjacob * Redistribution and use in source and binary forms, with or without 8101704Smjacob * modification, are permitted provided that the following conditions 9101704Smjacob * are met: 10101704Smjacob * 1. Redistributions of source code must retain the above copyright 11101704Smjacob * notice immediately at the beginning of the file, without modification, 12101704Smjacob * this list of conditions, and the following disclaimer. 13101704Smjacob * 2. The name of the author may not be used to endorse or promote products 14101704Smjacob * derived from this software without specific prior written permission. 15101704Smjacob * 16101704Smjacob * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17101704Smjacob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18101704Smjacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19101704Smjacob * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 20101704Smjacob * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21101704Smjacob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22101704Smjacob * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23101704Smjacob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24101704Smjacob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25101704Smjacob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26101704Smjacob * SUCH DAMAGE. 27156000Smjacob */ 28156000Smjacob/*- 29156000Smjacob * Copyright (c) 2002, 2006 by Matthew Jacob 30156000Smjacob * All rights reserved. 31156104Smjacob * 32156000Smjacob * Redistribution and use in source and binary forms, with or without 33156000Smjacob * modification, are permitted provided that the following conditions are 34156000Smjacob * met: 35156000Smjacob * 1. Redistributions of source code must retain the above copyright 36156000Smjacob * notice, this list of conditions and the following disclaimer. 37156000Smjacob * 2. Redistributions in binary form must reproduce at minimum a disclaimer 38156000Smjacob * substantially similar to the "NO WARRANTY" disclaimer below 39156000Smjacob * ("Disclaimer") and any redistribution must be conditioned upon including 40156000Smjacob * a substantially similar Disclaimer requirement for further binary 41156000Smjacob * redistribution. 42156000Smjacob * 3. Neither the names of the above listed copyright holders nor the names 43156000Smjacob * of any contributors may be used to endorse or promote products derived 44156000Smjacob * from this software without specific prior written permission. 45156104Smjacob * 46156000Smjacob * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 47156000Smjacob * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 48156000Smjacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 49156000Smjacob * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 50156000Smjacob * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 51156000Smjacob * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 52156000Smjacob * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 53156000Smjacob * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 54156000Smjacob * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 55156000Smjacob * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT 56156000Smjacob * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 57147883Sscottl * 58156000Smjacob * Support from Chris Ellsworth in order to make SAS adapters work 59156000Smjacob * is gratefully acknowledged. 60159052Smjacob * 61159052Smjacob * 62159052Smjacob * Support from LSI-Logic has also gone a great deal toward making this a 63159052Smjacob * workable subsystem and is gratefully acknowledged. 64101704Smjacob */ 65156000Smjacob/*- 66147883Sscottl * Copyright (c) 2004, Avid Technology, Inc. and its contributors. 67147883Sscottl * Copyright (c) 2005, WHEEL Sp. z o.o. 68147883Sscottl * Copyright (c) 2004, 2005 Justin T. Gibbs 69147883Sscottl * All rights reserved. 70156104Smjacob * 71147883Sscottl * Redistribution and use in source and binary forms, with or without 72147883Sscottl * modification, are permitted provided that the following conditions are 73147883Sscottl * met: 74147883Sscottl * 1. Redistributions of source code must retain the above copyright 75147883Sscottl * notice, this list of conditions and the following disclaimer. 76147883Sscottl * 2. Redistributions in binary form must reproduce at minimum a disclaimer 77147883Sscottl * substantially similar to the "NO WARRANTY" disclaimer below 78147883Sscottl * ("Disclaimer") and any redistribution must be conditioned upon including 79147883Sscottl * a substantially similar Disclaimer requirement for further binary 80147883Sscottl * redistribution. 81148679Sgibbs * 3. Neither the names of the above listed copyright holders nor the names 82148679Sgibbs * of any contributors may be used to endorse or promote products derived 83148679Sgibbs * from this software without specific prior written permission. 84156104Smjacob * 85147883Sscottl * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 86147883Sscottl * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 87147883Sscottl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 88147883Sscottl * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 89147883Sscottl * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 90147883Sscottl * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 91147883Sscottl * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 92147883Sscottl * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 93147883Sscottl * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 94147883Sscottl * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT 95147883Sscottl * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 96101704Smjacob */ 97101704Smjacob 98134123Sobrien#include <sys/cdefs.h> 99134123Sobrien__FBSDID("$FreeBSD: head/sys/dev/mpt/mpt.c 213105 2010-09-24 16:40:46Z marius $"); 100134123Sobrien 101147883Sscottl#include <dev/mpt/mpt.h> 102147883Sscottl#include <dev/mpt/mpt_cam.h> /* XXX For static handler registration */ 103147883Sscottl#include <dev/mpt/mpt_raid.h> /* XXX For static handler registration */ 104102199Smjacob 105147883Sscottl#include <dev/mpt/mpilib/mpi.h> 106147883Sscottl#include <dev/mpt/mpilib/mpi_ioc.h> 107157117Smjacob#include <dev/mpt/mpilib/mpi_fc.h> 108157117Smjacob#include <dev/mpt/mpilib/mpi_targ.h> 109147883Sscottl 110147883Sscottl#include <sys/sysctl.h> 111147883Sscottl 112101704Smjacob#define MPT_MAX_TRYS 3 113101704Smjacob#define MPT_MAX_WAIT 300000 114101704Smjacob 115101704Smjacobstatic int maxwait_ack = 0; 116101704Smjacobstatic int maxwait_int = 0; 117101704Smjacobstatic int maxwait_state = 0; 118101704Smjacob 119162133Smjacobstatic TAILQ_HEAD(, mpt_softc) mpt_tailq = TAILQ_HEAD_INITIALIZER(mpt_tailq); 120147883Sscottlmpt_reply_handler_t *mpt_reply_handlers[MPT_NUM_REPLY_HANDLERS]; 121101704Smjacob 122147883Sscottlstatic mpt_reply_handler_t mpt_default_reply_handler; 123147883Sscottlstatic mpt_reply_handler_t mpt_config_reply_handler; 124147883Sscottlstatic mpt_reply_handler_t mpt_handshake_reply_handler; 125147883Sscottlstatic mpt_reply_handler_t mpt_event_reply_handler; 126147883Sscottlstatic void mpt_send_event_ack(struct mpt_softc *mpt, request_t *ack_req, 127147883Sscottl MSG_EVENT_NOTIFY_REPLY *msg, uint32_t context); 128155521Smjacobstatic int mpt_send_event_request(struct mpt_softc *mpt, int onoff); 129147883Sscottlstatic int mpt_soft_reset(struct mpt_softc *mpt); 130147883Sscottlstatic void mpt_hard_reset(struct mpt_softc *mpt); 131209960Smariusstatic int mpt_dma_buf_alloc(struct mpt_softc *mpt); 132209599Skenstatic void mpt_dma_buf_free(struct mpt_softc *mpt); 133164990Smjacobstatic int mpt_configure_ioc(struct mpt_softc *mpt, int, int); 134157117Smjacobstatic int mpt_enable_ioc(struct mpt_softc *mpt, int); 135147883Sscottl 136147883Sscottl/************************* Personality Module Support *************************/ 137147883Sscottl/* 138147883Sscottl * We include one extra entry that is guaranteed to be NULL 139147883Sscottl * to simplify our itterator. 140147883Sscottl */ 141147883Sscottlstatic struct mpt_personality *mpt_personalities[MPT_MAX_PERSONALITIES + 1]; 142147883Sscottlstatic __inline struct mpt_personality* 143147883Sscottl mpt_pers_find(struct mpt_softc *, u_int); 144147883Sscottlstatic __inline struct mpt_personality* 145147883Sscottl mpt_pers_find_reverse(struct mpt_softc *, u_int); 146147883Sscottl 147147883Sscottlstatic __inline struct mpt_personality * 148147883Sscottlmpt_pers_find(struct mpt_softc *mpt, u_int start_at) 149101704Smjacob{ 150147883Sscottl KASSERT(start_at <= MPT_MAX_PERSONALITIES, 151147883Sscottl ("mpt_pers_find: starting position out of range\n")); 152147883Sscottl 153147883Sscottl while (start_at < MPT_MAX_PERSONALITIES 154147883Sscottl && (mpt->mpt_pers_mask & (0x1 << start_at)) == 0) { 155147883Sscottl start_at++; 156147883Sscottl } 157147883Sscottl return (mpt_personalities[start_at]); 158147883Sscottl} 159147883Sscottl 160147883Sscottl/* 161157117Smjacob * Used infrequently, so no need to optimize like a forward 162147883Sscottl * traversal where we use the MAX+1 is guaranteed to be NULL 163147883Sscottl * trick. 164147883Sscottl */ 165147883Sscottlstatic __inline struct mpt_personality * 166147883Sscottlmpt_pers_find_reverse(struct mpt_softc *mpt, u_int start_at) 167147883Sscottl{ 168147883Sscottl while (start_at < MPT_MAX_PERSONALITIES 169147883Sscottl && (mpt->mpt_pers_mask & (0x1 << start_at)) == 0) { 170147883Sscottl start_at--; 171147883Sscottl } 172147883Sscottl if (start_at < MPT_MAX_PERSONALITIES) 173147883Sscottl return (mpt_personalities[start_at]); 174147883Sscottl return (NULL); 175147883Sscottl} 176147883Sscottl 177147883Sscottl#define MPT_PERS_FOREACH(mpt, pers) \ 178147883Sscottl for (pers = mpt_pers_find(mpt, /*start_at*/0); \ 179147883Sscottl pers != NULL; \ 180147883Sscottl pers = mpt_pers_find(mpt, /*start_at*/pers->id+1)) 181147883Sscottl 182147883Sscottl#define MPT_PERS_FOREACH_REVERSE(mpt, pers) \ 183147883Sscottl for (pers = mpt_pers_find_reverse(mpt, MPT_MAX_PERSONALITIES-1);\ 184147883Sscottl pers != NULL; \ 185147883Sscottl pers = mpt_pers_find_reverse(mpt, /*start_at*/pers->id-1)) 186147883Sscottl 187147883Sscottlstatic mpt_load_handler_t mpt_stdload; 188147883Sscottlstatic mpt_probe_handler_t mpt_stdprobe; 189147883Sscottlstatic mpt_attach_handler_t mpt_stdattach; 190157117Smjacobstatic mpt_enable_handler_t mpt_stdenable; 191162133Smjacobstatic mpt_ready_handler_t mpt_stdready; 192147883Sscottlstatic mpt_event_handler_t mpt_stdevent; 193147883Sscottlstatic mpt_reset_handler_t mpt_stdreset; 194147883Sscottlstatic mpt_shutdown_handler_t mpt_stdshutdown; 195147883Sscottlstatic mpt_detach_handler_t mpt_stddetach; 196147883Sscottlstatic mpt_unload_handler_t mpt_stdunload; 197147883Sscottlstatic struct mpt_personality mpt_default_personality = 198147883Sscottl{ 199147883Sscottl .load = mpt_stdload, 200147883Sscottl .probe = mpt_stdprobe, 201147883Sscottl .attach = mpt_stdattach, 202157117Smjacob .enable = mpt_stdenable, 203162133Smjacob .ready = mpt_stdready, 204147883Sscottl .event = mpt_stdevent, 205147883Sscottl .reset = mpt_stdreset, 206147883Sscottl .shutdown = mpt_stdshutdown, 207147883Sscottl .detach = mpt_stddetach, 208147883Sscottl .unload = mpt_stdunload 209147883Sscottl}; 210147883Sscottl 211147883Sscottlstatic mpt_load_handler_t mpt_core_load; 212147883Sscottlstatic mpt_attach_handler_t mpt_core_attach; 213157117Smjacobstatic mpt_enable_handler_t mpt_core_enable; 214147883Sscottlstatic mpt_reset_handler_t mpt_core_ioc_reset; 215147883Sscottlstatic mpt_event_handler_t mpt_core_event; 216147883Sscottlstatic mpt_shutdown_handler_t mpt_core_shutdown; 217147883Sscottlstatic mpt_shutdown_handler_t mpt_core_detach; 218147883Sscottlstatic mpt_unload_handler_t mpt_core_unload; 219147883Sscottlstatic struct mpt_personality mpt_core_personality = 220147883Sscottl{ 221147883Sscottl .name = "mpt_core", 222147883Sscottl .load = mpt_core_load, 223177808Sscottl// .attach = mpt_core_attach, 224177808Sscottl// .enable = mpt_core_enable, 225147883Sscottl .event = mpt_core_event, 226147883Sscottl .reset = mpt_core_ioc_reset, 227147883Sscottl .shutdown = mpt_core_shutdown, 228147883Sscottl .detach = mpt_core_detach, 229147883Sscottl .unload = mpt_core_unload, 230147883Sscottl}; 231147883Sscottl 232147883Sscottl/* 233147883Sscottl * Manual declaration so that DECLARE_MPT_PERSONALITY doesn't need 234147883Sscottl * ordering information. We want the core to always register FIRST. 235147883Sscottl * other modules are set to SI_ORDER_SECOND. 236147883Sscottl */ 237147883Sscottlstatic moduledata_t mpt_core_mod = { 238147883Sscottl "mpt_core", mpt_modevent, &mpt_core_personality 239147883Sscottl}; 240147883SscottlDECLARE_MODULE(mpt_core, mpt_core_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST); 241147883SscottlMODULE_VERSION(mpt_core, 1); 242147883Sscottl 243157117Smjacob#define MPT_PERS_ATTACHED(pers, mpt) ((mpt)->mpt_pers_mask & (0x1 << pers->id)) 244147883Sscottl 245147883Sscottlint 246147883Sscottlmpt_modevent(module_t mod, int type, void *data) 247147883Sscottl{ 248147883Sscottl struct mpt_personality *pers; 249147883Sscottl int error; 250147883Sscottl 251147883Sscottl pers = (struct mpt_personality *)data; 252147883Sscottl 253147883Sscottl error = 0; 254147883Sscottl switch (type) { 255147883Sscottl case MOD_LOAD: 256147883Sscottl { 257147883Sscottl mpt_load_handler_t **def_handler; 258147883Sscottl mpt_load_handler_t **pers_handler; 259147883Sscottl int i; 260147883Sscottl 261147883Sscottl for (i = 0; i < MPT_MAX_PERSONALITIES; i++) { 262147883Sscottl if (mpt_personalities[i] == NULL) 263147883Sscottl break; 264147883Sscottl } 265147883Sscottl if (i >= MPT_MAX_PERSONALITIES) { 266147883Sscottl error = ENOMEM; 267147883Sscottl break; 268147883Sscottl } 269147883Sscottl pers->id = i; 270147883Sscottl mpt_personalities[i] = pers; 271147883Sscottl 272147883Sscottl /* Install standard/noop handlers for any NULL entries. */ 273147883Sscottl def_handler = MPT_PERS_FIRST_HANDLER(&mpt_default_personality); 274147883Sscottl pers_handler = MPT_PERS_FIRST_HANDLER(pers); 275147883Sscottl while (pers_handler <= MPT_PERS_LAST_HANDLER(pers)) { 276147883Sscottl if (*pers_handler == NULL) 277147883Sscottl *pers_handler = *def_handler; 278147883Sscottl pers_handler++; 279147883Sscottl def_handler++; 280147883Sscottl } 281147883Sscottl 282147883Sscottl error = (pers->load(pers)); 283147883Sscottl if (error != 0) 284147883Sscottl mpt_personalities[i] = NULL; 285147883Sscottl break; 286147883Sscottl } 287147883Sscottl case MOD_SHUTDOWN: 288147883Sscottl break; 289157117Smjacob#if __FreeBSD_version >= 500000 290147883Sscottl case MOD_QUIESCE: 291147883Sscottl break; 292157117Smjacob#endif 293147883Sscottl case MOD_UNLOAD: 294147883Sscottl error = pers->unload(pers); 295147883Sscottl mpt_personalities[pers->id] = NULL; 296147883Sscottl break; 297147883Sscottl default: 298147883Sscottl error = EINVAL; 299147883Sscottl break; 300147883Sscottl } 301147883Sscottl return (error); 302147883Sscottl} 303147883Sscottl 304147883Sscottlint 305147883Sscottlmpt_stdload(struct mpt_personality *pers) 306147883Sscottl{ 307147883Sscottl /* Load is always successfull. */ 308147883Sscottl return (0); 309147883Sscottl} 310147883Sscottl 311147883Sscottlint 312147883Sscottlmpt_stdprobe(struct mpt_softc *mpt) 313147883Sscottl{ 314147883Sscottl /* Probe is always successfull. */ 315147883Sscottl return (0); 316147883Sscottl} 317147883Sscottl 318147883Sscottlint 319147883Sscottlmpt_stdattach(struct mpt_softc *mpt) 320147883Sscottl{ 321147883Sscottl /* Attach is always successfull. */ 322147883Sscottl return (0); 323147883Sscottl} 324147883Sscottl 325147883Sscottlint 326157117Smjacobmpt_stdenable(struct mpt_softc *mpt) 327157117Smjacob{ 328157117Smjacob /* Enable is always successfull. */ 329157117Smjacob return (0); 330157117Smjacob} 331157117Smjacob 332162133Smjacobvoid 333162133Smjacobmpt_stdready(struct mpt_softc *mpt) 334162133Smjacob{ 335162133Smjacob} 336162133Smjacob 337162133Smjacob 338157117Smjacobint 339155521Smjacobmpt_stdevent(struct mpt_softc *mpt, request_t *req, MSG_EVENT_NOTIFY_REPLY *msg) 340147883Sscottl{ 341155521Smjacob mpt_lprt(mpt, MPT_PRT_DEBUG, "mpt_stdevent: 0x%x\n", msg->Event & 0xFF); 342147883Sscottl /* Event was not for us. */ 343147883Sscottl return (0); 344147883Sscottl} 345147883Sscottl 346147883Sscottlvoid 347147883Sscottlmpt_stdreset(struct mpt_softc *mpt, int type) 348147883Sscottl{ 349147883Sscottl} 350147883Sscottl 351147883Sscottlvoid 352147883Sscottlmpt_stdshutdown(struct mpt_softc *mpt) 353147883Sscottl{ 354147883Sscottl} 355147883Sscottl 356147883Sscottlvoid 357147883Sscottlmpt_stddetach(struct mpt_softc *mpt) 358147883Sscottl{ 359147883Sscottl} 360147883Sscottl 361147883Sscottlint 362147883Sscottlmpt_stdunload(struct mpt_personality *pers) 363147883Sscottl{ 364147883Sscottl /* Unload is always successfull. */ 365147883Sscottl return (0); 366147883Sscottl} 367147883Sscottl 368162133Smjacob/* 369162133Smjacob * Post driver attachment, we may want to perform some global actions. 370162133Smjacob * Here is the hook to do so. 371162133Smjacob */ 372162133Smjacob 373162133Smjacobstatic void 374162133Smjacobmpt_postattach(void *unused) 375162133Smjacob{ 376162133Smjacob struct mpt_softc *mpt; 377162133Smjacob struct mpt_personality *pers; 378162133Smjacob 379162133Smjacob TAILQ_FOREACH(mpt, &mpt_tailq, links) { 380162133Smjacob MPT_PERS_FOREACH(mpt, pers) 381162133Smjacob pers->ready(mpt); 382162133Smjacob } 383162133Smjacob} 384162133SmjacobSYSINIT(mptdev, SI_SUB_CONFIGURE, SI_ORDER_MIDDLE, mpt_postattach, NULL); 385162133Smjacob 386162133Smjacob 387147883Sscottl/******************************* Bus DMA Support ******************************/ 388147883Sscottlvoid 389147883Sscottlmpt_map_rquest(void *arg, bus_dma_segment_t *segs, int nseg, int error) 390147883Sscottl{ 391147883Sscottl struct mpt_map_info *map_info; 392147883Sscottl 393147883Sscottl map_info = (struct mpt_map_info *)arg; 394147883Sscottl map_info->error = error; 395147883Sscottl map_info->phys = segs->ds_addr; 396147883Sscottl} 397147883Sscottl 398147883Sscottl/**************************** Reply/Event Handling ****************************/ 399147883Sscottlint 400147883Sscottlmpt_register_handler(struct mpt_softc *mpt, mpt_handler_type type, 401147883Sscottl mpt_handler_t handler, uint32_t *phandler_id) 402147883Sscottl{ 403147883Sscottl 404147883Sscottl switch (type) { 405147883Sscottl case MPT_HANDLER_REPLY: 406147883Sscottl { 407147883Sscottl u_int cbi; 408147883Sscottl u_int free_cbi; 409147883Sscottl 410147883Sscottl if (phandler_id == NULL) 411147883Sscottl return (EINVAL); 412147883Sscottl 413147883Sscottl free_cbi = MPT_HANDLER_ID_NONE; 414147883Sscottl for (cbi = 0; cbi < MPT_NUM_REPLY_HANDLERS; cbi++) { 415147883Sscottl /* 416147883Sscottl * If the same handler is registered multiple 417147883Sscottl * times, don't error out. Just return the 418147883Sscottl * index of the original registration. 419147883Sscottl */ 420147883Sscottl if (mpt_reply_handlers[cbi] == handler.reply_handler) { 421147883Sscottl *phandler_id = MPT_CBI_TO_HID(cbi); 422147883Sscottl return (0); 423147883Sscottl } 424147883Sscottl 425147883Sscottl /* 426147883Sscottl * Fill from the front in the hope that 427147883Sscottl * all registered handlers consume only a 428147883Sscottl * single cache line. 429147883Sscottl * 430147883Sscottl * We don't break on the first empty slot so 431147883Sscottl * that the full table is checked to see if 432147883Sscottl * this handler was previously registered. 433147883Sscottl */ 434157117Smjacob if (free_cbi == MPT_HANDLER_ID_NONE && 435157117Smjacob (mpt_reply_handlers[cbi] 436147883Sscottl == mpt_default_reply_handler)) 437147883Sscottl free_cbi = cbi; 438147883Sscottl } 439157117Smjacob if (free_cbi == MPT_HANDLER_ID_NONE) { 440147883Sscottl return (ENOMEM); 441157117Smjacob } 442147883Sscottl mpt_reply_handlers[free_cbi] = handler.reply_handler; 443147883Sscottl *phandler_id = MPT_CBI_TO_HID(free_cbi); 444147883Sscottl break; 445147883Sscottl } 446147883Sscottl default: 447147883Sscottl mpt_prt(mpt, "mpt_register_handler unknown type %d\n", type); 448147883Sscottl return (EINVAL); 449147883Sscottl } 450147883Sscottl return (0); 451147883Sscottl} 452147883Sscottl 453147883Sscottlint 454147883Sscottlmpt_deregister_handler(struct mpt_softc *mpt, mpt_handler_type type, 455147883Sscottl mpt_handler_t handler, uint32_t handler_id) 456147883Sscottl{ 457147883Sscottl 458147883Sscottl switch (type) { 459147883Sscottl case MPT_HANDLER_REPLY: 460147883Sscottl { 461147883Sscottl u_int cbi; 462147883Sscottl 463147883Sscottl cbi = MPT_CBI(handler_id); 464147883Sscottl if (cbi >= MPT_NUM_REPLY_HANDLERS 465147883Sscottl || mpt_reply_handlers[cbi] != handler.reply_handler) 466147883Sscottl return (ENOENT); 467147883Sscottl mpt_reply_handlers[cbi] = mpt_default_reply_handler; 468147883Sscottl break; 469147883Sscottl } 470147883Sscottl default: 471147883Sscottl mpt_prt(mpt, "mpt_deregister_handler unknown type %d\n", type); 472147883Sscottl return (EINVAL); 473147883Sscottl } 474147883Sscottl return (0); 475147883Sscottl} 476147883Sscottl 477147883Sscottlstatic int 478147883Sscottlmpt_default_reply_handler(struct mpt_softc *mpt, request_t *req, 479157117Smjacob uint32_t reply_desc, MSG_DEFAULT_REPLY *reply_frame) 480147883Sscottl{ 481157117Smjacob mpt_prt(mpt, 482157117Smjacob "Default Handler Called: req=%p:%u reply_descriptor=%x frame=%p\n", 483157117Smjacob req, req->serno, reply_desc, reply_frame); 484147883Sscottl 485147883Sscottl if (reply_frame != NULL) 486147883Sscottl mpt_dump_reply_frame(mpt, reply_frame); 487147883Sscottl 488157117Smjacob mpt_prt(mpt, "Reply Frame Ignored\n"); 489147883Sscottl 490147883Sscottl return (/*free_reply*/TRUE); 491147883Sscottl} 492147883Sscottl 493147883Sscottlstatic int 494147883Sscottlmpt_config_reply_handler(struct mpt_softc *mpt, request_t *req, 495157117Smjacob uint32_t reply_desc, MSG_DEFAULT_REPLY *reply_frame) 496147883Sscottl{ 497147883Sscottl if (req != NULL) { 498147883Sscottl 499147883Sscottl if (reply_frame != NULL) { 500147883Sscottl MSG_CONFIG *cfgp; 501147883Sscottl MSG_CONFIG_REPLY *reply; 502147883Sscottl 503147883Sscottl cfgp = (MSG_CONFIG *)req->req_vbuf; 504147883Sscottl reply = (MSG_CONFIG_REPLY *)reply_frame; 505147883Sscottl req->IOCStatus = le16toh(reply_frame->IOCStatus); 506147883Sscottl bcopy(&reply->Header, &cfgp->Header, 507147883Sscottl sizeof(cfgp->Header)); 508170252Sscottl cfgp->ExtPageLength = reply->ExtPageLength; 509170252Sscottl cfgp->ExtPageType = reply->ExtPageType; 510147883Sscottl } 511147883Sscottl req->state &= ~REQ_STATE_QUEUED; 512147883Sscottl req->state |= REQ_STATE_DONE; 513147883Sscottl TAILQ_REMOVE(&mpt->request_pending_list, req, links); 514157354Smjacob if ((req->state & REQ_STATE_NEED_WAKEUP) != 0) { 515147883Sscottl wakeup(req); 516160396Smjacob } else if ((req->state & REQ_STATE_TIMEDOUT) != 0) { 517160396Smjacob /* 518160396Smjacob * Whew- we can free this request (late completion) 519160396Smjacob */ 520160396Smjacob mpt_free_request(mpt, req); 521157354Smjacob } 522147883Sscottl } 523147883Sscottl 524157354Smjacob return (TRUE); 525147883Sscottl} 526147883Sscottl 527147883Sscottlstatic int 528147883Sscottlmpt_handshake_reply_handler(struct mpt_softc *mpt, request_t *req, 529157117Smjacob uint32_t reply_desc, MSG_DEFAULT_REPLY *reply_frame) 530147883Sscottl{ 531147883Sscottl /* Nothing to be done. */ 532157354Smjacob return (TRUE); 533147883Sscottl} 534147883Sscottl 535147883Sscottlstatic int 536147883Sscottlmpt_event_reply_handler(struct mpt_softc *mpt, request_t *req, 537157117Smjacob uint32_t reply_desc, MSG_DEFAULT_REPLY *reply_frame) 538147883Sscottl{ 539147883Sscottl int free_reply; 540147883Sscottl 541157354Smjacob KASSERT(reply_frame != NULL, ("null reply in mpt_event_reply_handler")); 542157354Smjacob KASSERT(req != NULL, ("null request in mpt_event_reply_handler")); 543147883Sscottl 544147883Sscottl free_reply = TRUE; 545147883Sscottl switch (reply_frame->Function) { 546147883Sscottl case MPI_FUNCTION_EVENT_NOTIFICATION: 547147883Sscottl { 548147883Sscottl MSG_EVENT_NOTIFY_REPLY *msg; 549147883Sscottl struct mpt_personality *pers; 550147883Sscottl u_int handled; 551147883Sscottl 552147883Sscottl handled = 0; 553147883Sscottl msg = (MSG_EVENT_NOTIFY_REPLY *)reply_frame; 554164315Sjb msg->EventDataLength = le16toh(msg->EventDataLength); 555164315Sjb msg->IOCStatus = le16toh(msg->IOCStatus); 556164315Sjb msg->IOCLogInfo = le32toh(msg->IOCLogInfo); 557164315Sjb msg->Event = le32toh(msg->Event); 558147883Sscottl MPT_PERS_FOREACH(mpt, pers) 559147883Sscottl handled += pers->event(mpt, req, msg); 560147883Sscottl 561155521Smjacob if (handled == 0 && mpt->mpt_pers_mask == 0) { 562156301Smjacob mpt_lprt(mpt, MPT_PRT_INFO, 563155521Smjacob "No Handlers For Any Event Notify Frames. " 564155521Smjacob "Event %#x (ACK %sequired).\n", 565155521Smjacob msg->Event, msg->AckRequired? "r" : "not r"); 566155521Smjacob } else if (handled == 0) { 567173303Sscottl mpt_lprt(mpt, 568173303Sscottl msg->AckRequired? MPT_PRT_WARN : MPT_PRT_INFO, 569155521Smjacob "Unhandled Event Notify Frame. Event %#x " 570155521Smjacob "(ACK %sequired).\n", 571155521Smjacob msg->Event, msg->AckRequired? "r" : "not r"); 572155521Smjacob } 573147883Sscottl 574147883Sscottl if (msg->AckRequired) { 575147883Sscottl request_t *ack_req; 576147883Sscottl uint32_t context; 577147883Sscottl 578164315Sjb context = req->index | MPT_REPLY_HANDLER_EVENTS; 579157354Smjacob ack_req = mpt_get_request(mpt, FALSE); 580147883Sscottl if (ack_req == NULL) { 581147883Sscottl struct mpt_evtf_record *evtf; 582147883Sscottl 583147883Sscottl evtf = (struct mpt_evtf_record *)reply_frame; 584147883Sscottl evtf->context = context; 585147883Sscottl LIST_INSERT_HEAD(&mpt->ack_frames, evtf, links); 586147883Sscottl free_reply = FALSE; 587147883Sscottl break; 588147883Sscottl } 589147883Sscottl mpt_send_event_ack(mpt, ack_req, msg, context); 590157354Smjacob /* 591157354Smjacob * Don't check for CONTINUATION_REPLY here 592157354Smjacob */ 593157354Smjacob return (free_reply); 594147883Sscottl } 595147883Sscottl break; 596147883Sscottl } 597147883Sscottl case MPI_FUNCTION_PORT_ENABLE: 598157354Smjacob mpt_lprt(mpt, MPT_PRT_DEBUG , "enable port reply\n"); 599147883Sscottl break; 600147883Sscottl case MPI_FUNCTION_EVENT_ACK: 601147883Sscottl break; 602147883Sscottl default: 603157354Smjacob mpt_prt(mpt, "unknown event function: %x\n", 604147883Sscottl reply_frame->Function); 605147883Sscottl break; 606147883Sscottl } 607147883Sscottl 608157354Smjacob /* 609157354Smjacob * I'm not sure that this continuation stuff works as it should. 610157354Smjacob * 611157354Smjacob * I've had FC async events occur that free the frame up because 612157354Smjacob * the continuation bit isn't set, and then additional async events 613157354Smjacob * then occur using the same context. As you might imagine, this 614157354Smjacob * leads to Very Bad Thing. 615157354Smjacob * 616157354Smjacob * Let's just be safe for now and not free them up until we figure 617157354Smjacob * out what's actually happening here. 618157354Smjacob */ 619157354Smjacob#if 0 620157354Smjacob if ((reply_frame->MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY) == 0) { 621147883Sscottl TAILQ_REMOVE(&mpt->request_pending_list, req, links); 622157354Smjacob mpt_free_request(mpt, req); 623157354Smjacob mpt_prt(mpt, "event_reply %x for req %p:%u NOT a continuation", 624157354Smjacob reply_frame->Function, req, req->serno); 625157354Smjacob if (reply_frame->Function == MPI_FUNCTION_EVENT_NOTIFICATION) { 626157354Smjacob MSG_EVENT_NOTIFY_REPLY *msg = 627157354Smjacob (MSG_EVENT_NOTIFY_REPLY *)reply_frame; 628157354Smjacob mpt_prtc(mpt, " Event=0x%x AckReq=%d", 629157354Smjacob msg->Event, msg->AckRequired); 630157354Smjacob } 631157354Smjacob } else { 632157354Smjacob mpt_prt(mpt, "event_reply %x for %p:%u IS a continuation", 633157354Smjacob reply_frame->Function, req, req->serno); 634157354Smjacob if (reply_frame->Function == MPI_FUNCTION_EVENT_NOTIFICATION) { 635157354Smjacob MSG_EVENT_NOTIFY_REPLY *msg = 636157354Smjacob (MSG_EVENT_NOTIFY_REPLY *)reply_frame; 637157354Smjacob mpt_prtc(mpt, " Event=0x%x AckReq=%d", 638157354Smjacob msg->Event, msg->AckRequired); 639157354Smjacob } 640157354Smjacob mpt_prtc(mpt, "\n"); 641147883Sscottl } 642157354Smjacob#endif 643147883Sscottl return (free_reply); 644147883Sscottl} 645147883Sscottl 646147883Sscottl/* 647147883Sscottl * Process an asynchronous event from the IOC. 648147883Sscottl */ 649147883Sscottlstatic int 650147883Sscottlmpt_core_event(struct mpt_softc *mpt, request_t *req, 651147883Sscottl MSG_EVENT_NOTIFY_REPLY *msg) 652147883Sscottl{ 653155521Smjacob mpt_lprt(mpt, MPT_PRT_DEBUG, "mpt_core_event: 0x%x\n", 654155521Smjacob msg->Event & 0xFF); 655147883Sscottl switch(msg->Event & 0xFF) { 656147883Sscottl case MPI_EVENT_NONE: 657147883Sscottl break; 658147883Sscottl case MPI_EVENT_LOG_DATA: 659147883Sscottl { 660147883Sscottl int i; 661147883Sscottl 662147883Sscottl /* Some error occured that LSI wants logged */ 663147883Sscottl mpt_prt(mpt, "EvtLogData: IOCLogInfo: 0x%08x\n", 664147883Sscottl msg->IOCLogInfo); 665147883Sscottl mpt_prt(mpt, "\tEvtLogData: Event Data:"); 666147883Sscottl for (i = 0; i < msg->EventDataLength; i++) 667147883Sscottl mpt_prtc(mpt, " %08x", msg->Data[i]); 668147883Sscottl mpt_prtc(mpt, "\n"); 669147883Sscottl break; 670147883Sscottl } 671147883Sscottl case MPI_EVENT_EVENT_CHANGE: 672147883Sscottl /* 673147883Sscottl * This is just an acknowledgement 674147883Sscottl * of our mpt_send_event_request. 675147883Sscottl */ 676147883Sscottl break; 677155521Smjacob case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE: 678155521Smjacob break; 679147883Sscottl default: 680157354Smjacob return (0); 681147883Sscottl break; 682147883Sscottl } 683157354Smjacob return (1); 684147883Sscottl} 685147883Sscottl 686147883Sscottlstatic void 687147883Sscottlmpt_send_event_ack(struct mpt_softc *mpt, request_t *ack_req, 688147883Sscottl MSG_EVENT_NOTIFY_REPLY *msg, uint32_t context) 689147883Sscottl{ 690147883Sscottl MSG_EVENT_ACK *ackp; 691147883Sscottl 692147883Sscottl ackp = (MSG_EVENT_ACK *)ack_req->req_vbuf; 693157354Smjacob memset(ackp, 0, sizeof (*ackp)); 694147883Sscottl ackp->Function = MPI_FUNCTION_EVENT_ACK; 695164315Sjb ackp->Event = htole32(msg->Event); 696164315Sjb ackp->EventContext = htole32(msg->EventContext); 697164315Sjb ackp->MsgContext = htole32(context); 698147883Sscottl mpt_check_doorbell(mpt); 699147883Sscottl mpt_send_cmd(mpt, ack_req); 700147883Sscottl} 701147883Sscottl 702147883Sscottl/***************************** Interrupt Handling *****************************/ 703147883Sscottlvoid 704147883Sscottlmpt_intr(void *arg) 705147883Sscottl{ 706147883Sscottl struct mpt_softc *mpt; 707157117Smjacob uint32_t reply_desc; 708157117Smjacob int ntrips = 0; 709147883Sscottl 710147883Sscottl mpt = (struct mpt_softc *)arg; 711157662Smjacob mpt_lprt(mpt, MPT_PRT_DEBUG2, "enter mpt_intr\n"); 712169293Smjacob MPT_LOCK_ASSERT(mpt); 713169293Smjacob 714147883Sscottl while ((reply_desc = mpt_pop_reply_queue(mpt)) != MPT_REPLY_EMPTY) { 715147883Sscottl request_t *req; 716147883Sscottl MSG_DEFAULT_REPLY *reply_frame; 717147883Sscottl uint32_t reply_baddr; 718157117Smjacob uint32_t ctxt_idx; 719147883Sscottl u_int cb_index; 720147883Sscottl u_int req_index; 721147883Sscottl int free_rf; 722147883Sscottl 723147883Sscottl req = NULL; 724147883Sscottl reply_frame = NULL; 725147883Sscottl reply_baddr = 0; 726147883Sscottl if ((reply_desc & MPI_ADDRESS_REPLY_A_BIT) != 0) { 727147883Sscottl u_int offset; 728147883Sscottl /* 729147883Sscottl * Insure that the reply frame is coherent. 730147883Sscottl */ 731157354Smjacob reply_baddr = MPT_REPLY_BADDR(reply_desc); 732147883Sscottl offset = reply_baddr - (mpt->reply_phys & 0xFFFFFFFF); 733157117Smjacob bus_dmamap_sync_range(mpt->reply_dmat, 734157117Smjacob mpt->reply_dmap, offset, MPT_REPLY_SIZE, 735157117Smjacob BUS_DMASYNC_POSTREAD); 736147883Sscottl reply_frame = MPT_REPLY_OTOV(mpt, offset); 737157117Smjacob ctxt_idx = le32toh(reply_frame->MsgContext); 738157117Smjacob } else { 739157117Smjacob uint32_t type; 740157117Smjacob 741157117Smjacob type = MPI_GET_CONTEXT_REPLY_TYPE(reply_desc); 742157117Smjacob ctxt_idx = reply_desc; 743157117Smjacob mpt_lprt(mpt, MPT_PRT_DEBUG1, "Context Reply: 0x%08x\n", 744157117Smjacob reply_desc); 745157117Smjacob 746157117Smjacob switch (type) { 747157117Smjacob case MPI_CONTEXT_REPLY_TYPE_SCSI_INIT: 748157117Smjacob ctxt_idx &= MPI_CONTEXT_REPLY_CONTEXT_MASK; 749157117Smjacob break; 750157117Smjacob case MPI_CONTEXT_REPLY_TYPE_SCSI_TARGET: 751157117Smjacob ctxt_idx = GET_IO_INDEX(reply_desc); 752157117Smjacob if (mpt->tgt_cmd_ptrs == NULL) { 753157117Smjacob mpt_prt(mpt, 754157117Smjacob "mpt_intr: no target cmd ptrs\n"); 755157117Smjacob reply_desc = MPT_REPLY_EMPTY; 756157117Smjacob break; 757157117Smjacob } 758157117Smjacob if (ctxt_idx >= mpt->tgt_cmds_allocated) { 759157117Smjacob mpt_prt(mpt, 760157117Smjacob "mpt_intr: bad tgt cmd ctxt %u\n", 761157117Smjacob ctxt_idx); 762157117Smjacob reply_desc = MPT_REPLY_EMPTY; 763157117Smjacob ntrips = 1000; 764157117Smjacob break; 765157117Smjacob } 766157117Smjacob req = mpt->tgt_cmd_ptrs[ctxt_idx]; 767157117Smjacob if (req == NULL) { 768157117Smjacob mpt_prt(mpt, "no request backpointer " 769157117Smjacob "at index %u", ctxt_idx); 770157117Smjacob reply_desc = MPT_REPLY_EMPTY; 771157117Smjacob ntrips = 1000; 772157117Smjacob break; 773157117Smjacob } 774157117Smjacob /* 775157117Smjacob * Reformulate ctxt_idx to be just as if 776157117Smjacob * it were another type of context reply 777157117Smjacob * so the code below will find the request 778157117Smjacob * via indexing into the pool. 779157117Smjacob */ 780157117Smjacob ctxt_idx = 781157117Smjacob req->index | mpt->scsi_tgt_handler_id; 782157117Smjacob req = NULL; 783157117Smjacob break; 784157117Smjacob case MPI_CONTEXT_REPLY_TYPE_LAN: 785157117Smjacob mpt_prt(mpt, "LAN CONTEXT REPLY: 0x%08x\n", 786157117Smjacob reply_desc); 787157117Smjacob reply_desc = MPT_REPLY_EMPTY; 788157117Smjacob break; 789157117Smjacob default: 790157117Smjacob mpt_prt(mpt, "Context Reply 0x%08x?\n", type); 791157117Smjacob reply_desc = MPT_REPLY_EMPTY; 792157117Smjacob break; 793157117Smjacob } 794157117Smjacob if (reply_desc == MPT_REPLY_EMPTY) { 795157117Smjacob if (ntrips++ > 1000) { 796157117Smjacob break; 797157117Smjacob } 798157117Smjacob continue; 799157117Smjacob } 800147883Sscottl } 801157117Smjacob 802157117Smjacob cb_index = MPT_CONTEXT_TO_CBI(ctxt_idx); 803157117Smjacob req_index = MPT_CONTEXT_TO_REQI(ctxt_idx); 804157117Smjacob if (req_index < MPT_MAX_REQUESTS(mpt)) { 805147883Sscottl req = &mpt->request_pool[req_index]; 806157354Smjacob } else { 807157354Smjacob mpt_prt(mpt, "WARN: mpt_intr index == %d (reply_desc ==" 808157354Smjacob " 0x%x)\n", req_index, reply_desc); 809157117Smjacob } 810147883Sscottl 811157117Smjacob free_rf = mpt_reply_handlers[cb_index](mpt, req, 812157117Smjacob reply_desc, reply_frame); 813147883Sscottl 814157354Smjacob if (reply_frame != NULL && free_rf) { 815147883Sscottl mpt_free_reply(mpt, reply_baddr); 816157354Smjacob } 817157117Smjacob 818157117Smjacob /* 819157117Smjacob * If we got ourselves disabled, don't get stuck in a loop 820157117Smjacob */ 821157117Smjacob if (mpt->disabled) { 822157117Smjacob mpt_disable_ints(mpt); 823157117Smjacob break; 824157117Smjacob } 825157117Smjacob if (ntrips++ > 1000) { 826157117Smjacob break; 827157117Smjacob } 828147883Sscottl } 829157662Smjacob mpt_lprt(mpt, MPT_PRT_DEBUG2, "exit mpt_intr\n"); 830147883Sscottl} 831147883Sscottl 832147883Sscottl/******************************* Error Recovery *******************************/ 833147883Sscottlvoid 834147883Sscottlmpt_complete_request_chain(struct mpt_softc *mpt, struct req_queue *chain, 835147883Sscottl u_int iocstatus) 836147883Sscottl{ 837147883Sscottl MSG_DEFAULT_REPLY ioc_status_frame; 838147883Sscottl request_t *req; 839147883Sscottl 840157354Smjacob memset(&ioc_status_frame, 0, sizeof(ioc_status_frame)); 841147883Sscottl ioc_status_frame.MsgLength = roundup2(sizeof(ioc_status_frame), 4); 842156104Smjacob ioc_status_frame.IOCStatus = iocstatus; 843147883Sscottl while((req = TAILQ_FIRST(chain)) != NULL) { 844147883Sscottl MSG_REQUEST_HEADER *msg_hdr; 845147883Sscottl u_int cb_index; 846157354Smjacob 847147883Sscottl msg_hdr = (MSG_REQUEST_HEADER *)req->req_vbuf; 848156104Smjacob ioc_status_frame.Function = msg_hdr->Function; 849156104Smjacob ioc_status_frame.MsgContext = msg_hdr->MsgContext; 850147883Sscottl cb_index = MPT_CONTEXT_TO_CBI(le32toh(msg_hdr->MsgContext)); 851157117Smjacob mpt_reply_handlers[cb_index](mpt, req, msg_hdr->MsgContext, 852157117Smjacob &ioc_status_frame); 853213105Smarius if (mpt_req_on_pending_list(mpt, req) != 0) 854213105Smarius TAILQ_REMOVE(chain, req, links); 855147883Sscottl } 856147883Sscottl} 857147883Sscottl 858147883Sscottl/********************************* Diagnostics ********************************/ 859147883Sscottl/* 860147883Sscottl * Perform a diagnostic dump of a reply frame. 861147883Sscottl */ 862147883Sscottlvoid 863147883Sscottlmpt_dump_reply_frame(struct mpt_softc *mpt, MSG_DEFAULT_REPLY *reply_frame) 864147883Sscottl{ 865147883Sscottl mpt_prt(mpt, "Address Reply:\n"); 866147883Sscottl mpt_print_reply(reply_frame); 867147883Sscottl} 868147883Sscottl 869147883Sscottl/******************************* Doorbell Access ******************************/ 870147883Sscottlstatic __inline uint32_t mpt_rd_db(struct mpt_softc *mpt); 871147883Sscottlstatic __inline uint32_t mpt_rd_intr(struct mpt_softc *mpt); 872147883Sscottl 873147883Sscottlstatic __inline uint32_t 874147883Sscottlmpt_rd_db(struct mpt_softc *mpt) 875147883Sscottl{ 876101704Smjacob return mpt_read(mpt, MPT_OFFSET_DOORBELL); 877101704Smjacob} 878101704Smjacob 879147883Sscottlstatic __inline uint32_t 880147883Sscottlmpt_rd_intr(struct mpt_softc *mpt) 881101704Smjacob{ 882101704Smjacob return mpt_read(mpt, MPT_OFFSET_INTR_STATUS); 883101704Smjacob} 884101704Smjacob 885101704Smjacob/* Busy wait for a door bell to be read by IOC */ 886101704Smjacobstatic int 887147883Sscottlmpt_wait_db_ack(struct mpt_softc *mpt) 888101704Smjacob{ 889101704Smjacob int i; 890101704Smjacob for (i=0; i < MPT_MAX_WAIT; i++) { 891101704Smjacob if (!MPT_DB_IS_BUSY(mpt_rd_intr(mpt))) { 892101704Smjacob maxwait_ack = i > maxwait_ack ? i : maxwait_ack; 893157117Smjacob return (MPT_OK); 894101704Smjacob } 895157117Smjacob DELAY(200); 896101704Smjacob } 897157117Smjacob return (MPT_FAIL); 898101704Smjacob} 899101704Smjacob 900101704Smjacob/* Busy wait for a door bell interrupt */ 901101704Smjacobstatic int 902147883Sscottlmpt_wait_db_int(struct mpt_softc *mpt) 903101704Smjacob{ 904101704Smjacob int i; 905164837Smjacob for (i = 0; i < MPT_MAX_WAIT; i++) { 906101704Smjacob if (MPT_DB_INTR(mpt_rd_intr(mpt))) { 907101704Smjacob maxwait_int = i > maxwait_int ? i : maxwait_int; 908101704Smjacob return MPT_OK; 909101704Smjacob } 910101704Smjacob DELAY(100); 911101704Smjacob } 912157117Smjacob return (MPT_FAIL); 913101704Smjacob} 914101704Smjacob 915101704Smjacob/* Wait for IOC to transition to a give state */ 916101704Smjacobvoid 917147883Sscottlmpt_check_doorbell(struct mpt_softc *mpt) 918101704Smjacob{ 919147883Sscottl uint32_t db = mpt_rd_db(mpt); 920101704Smjacob if (MPT_STATE(db) != MPT_DB_STATE_RUNNING) { 921147883Sscottl mpt_prt(mpt, "Device not running\n"); 922101704Smjacob mpt_print_db(db); 923101704Smjacob } 924101704Smjacob} 925101704Smjacob 926101704Smjacob/* Wait for IOC to transition to a give state */ 927101704Smjacobstatic int 928147883Sscottlmpt_wait_state(struct mpt_softc *mpt, enum DB_STATE_BITS state) 929101704Smjacob{ 930101704Smjacob int i; 931101704Smjacob 932101704Smjacob for (i = 0; i < MPT_MAX_WAIT; i++) { 933147883Sscottl uint32_t db = mpt_rd_db(mpt); 934101704Smjacob if (MPT_STATE(db) == state) { 935101704Smjacob maxwait_state = i > maxwait_state ? i : maxwait_state; 936101704Smjacob return (MPT_OK); 937101704Smjacob } 938101704Smjacob DELAY(100); 939101704Smjacob } 940101704Smjacob return (MPT_FAIL); 941101704Smjacob} 942101704Smjacob 943101704Smjacob 944147883Sscottl/************************* Intialization/Configuration ************************/ 945147883Sscottlstatic int mpt_download_fw(struct mpt_softc *mpt); 946147883Sscottl 947101704Smjacob/* Issue the reset COMMAND to the IOC */ 948147883Sscottlstatic int 949147883Sscottlmpt_soft_reset(struct mpt_softc *mpt) 950101704Smjacob{ 951147883Sscottl mpt_lprt(mpt, MPT_PRT_DEBUG, "soft reset\n"); 952101704Smjacob 953101704Smjacob /* Have to use hard reset if we are not in Running state */ 954101704Smjacob if (MPT_STATE(mpt_rd_db(mpt)) != MPT_DB_STATE_RUNNING) { 955147883Sscottl mpt_prt(mpt, "soft reset failed: device not running\n"); 956157117Smjacob return (MPT_FAIL); 957101704Smjacob } 958101704Smjacob 959101704Smjacob /* If door bell is in use we don't have a chance of getting 960101704Smjacob * a word in since the IOC probably crashed in message 961101704Smjacob * processing. So don't waste our time. 962101704Smjacob */ 963101704Smjacob if (MPT_DB_IS_IN_USE(mpt_rd_db(mpt))) { 964147883Sscottl mpt_prt(mpt, "soft reset failed: doorbell wedged\n"); 965157117Smjacob return (MPT_FAIL); 966101704Smjacob } 967101704Smjacob 968101704Smjacob /* Send the reset request to the IOC */ 969101704Smjacob mpt_write(mpt, MPT_OFFSET_DOORBELL, 970101704Smjacob MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET << MPI_DOORBELL_FUNCTION_SHIFT); 971101704Smjacob if (mpt_wait_db_ack(mpt) != MPT_OK) { 972147883Sscottl mpt_prt(mpt, "soft reset failed: ack timeout\n"); 973157117Smjacob return (MPT_FAIL); 974101704Smjacob } 975101704Smjacob 976101704Smjacob /* Wait for the IOC to reload and come out of reset state */ 977101704Smjacob if (mpt_wait_state(mpt, MPT_DB_STATE_READY) != MPT_OK) { 978147883Sscottl mpt_prt(mpt, "soft reset failed: device did not restart\n"); 979157117Smjacob return (MPT_FAIL); 980101704Smjacob } 981101704Smjacob 982101704Smjacob return MPT_OK; 983101704Smjacob} 984101704Smjacob 985147883Sscottlstatic int 986147883Sscottlmpt_enable_diag_mode(struct mpt_softc *mpt) 987147883Sscottl{ 988147883Sscottl int try; 989147883Sscottl 990147883Sscottl try = 20; 991147883Sscottl while (--try) { 992147883Sscottl 993147883Sscottl if ((mpt_read(mpt, MPT_OFFSET_DIAGNOSTIC) & MPI_DIAG_DRWE) != 0) 994147883Sscottl break; 995147883Sscottl 996147883Sscottl /* Enable diagnostic registers */ 997147883Sscottl mpt_write(mpt, MPT_OFFSET_SEQUENCE, 0xFF); 998147883Sscottl mpt_write(mpt, MPT_OFFSET_SEQUENCE, MPI_WRSEQ_1ST_KEY_VALUE); 999147883Sscottl mpt_write(mpt, MPT_OFFSET_SEQUENCE, MPI_WRSEQ_2ND_KEY_VALUE); 1000147883Sscottl mpt_write(mpt, MPT_OFFSET_SEQUENCE, MPI_WRSEQ_3RD_KEY_VALUE); 1001147883Sscottl mpt_write(mpt, MPT_OFFSET_SEQUENCE, MPI_WRSEQ_4TH_KEY_VALUE); 1002147883Sscottl mpt_write(mpt, MPT_OFFSET_SEQUENCE, MPI_WRSEQ_5TH_KEY_VALUE); 1003147883Sscottl 1004147883Sscottl DELAY(100000); 1005147883Sscottl } 1006147883Sscottl if (try == 0) 1007147883Sscottl return (EIO); 1008147883Sscottl return (0); 1009147883Sscottl} 1010147883Sscottl 1011147883Sscottlstatic void 1012147883Sscottlmpt_disable_diag_mode(struct mpt_softc *mpt) 1013147883Sscottl{ 1014147883Sscottl mpt_write(mpt, MPT_OFFSET_SEQUENCE, 0xFFFFFFFF); 1015147883Sscottl} 1016147883Sscottl 1017101704Smjacob/* This is a magic diagnostic reset that resets all the ARM 1018156104Smjacob * processors in the chip. 1019101704Smjacob */ 1020147883Sscottlstatic void 1021147883Sscottlmpt_hard_reset(struct mpt_softc *mpt) 1022101704Smjacob{ 1023147883Sscottl int error; 1024147883Sscottl int wait; 1025147883Sscottl uint32_t diagreg; 1026147883Sscottl 1027147883Sscottl mpt_lprt(mpt, MPT_PRT_DEBUG, "hard reset\n"); 1028147883Sscottl 1029147883Sscottl error = mpt_enable_diag_mode(mpt); 1030147883Sscottl if (error) { 1031147883Sscottl mpt_prt(mpt, "WARNING - Could not enter diagnostic mode !\n"); 1032147883Sscottl mpt_prt(mpt, "Trying to reset anyway.\n"); 1033101704Smjacob } 1034101704Smjacob 1035147883Sscottl diagreg = mpt_read(mpt, MPT_OFFSET_DIAGNOSTIC); 1036101704Smjacob 1037147883Sscottl /* 1038147883Sscottl * This appears to be a workaround required for some 1039147883Sscottl * firmware or hardware revs. 1040147883Sscottl */ 1041147883Sscottl mpt_write(mpt, MPT_OFFSET_DIAGNOSTIC, diagreg | MPI_DIAG_DISABLE_ARM); 1042147883Sscottl DELAY(1000); 1043147883Sscottl 1044101704Smjacob /* Diag. port is now active so we can now hit the reset bit */ 1045147883Sscottl mpt_write(mpt, MPT_OFFSET_DIAGNOSTIC, diagreg | MPI_DIAG_RESET_ADAPTER); 1046101704Smjacob 1047147883Sscottl /* 1048147883Sscottl * Ensure that the reset has finished. We delay 1ms 1049147883Sscottl * prior to reading the register to make sure the chip 1050147883Sscottl * has sufficiently completed its reset to handle register 1051147883Sscottl * accesses. 1052147883Sscottl */ 1053147883Sscottl wait = 5000; 1054147883Sscottl do { 1055147883Sscottl DELAY(1000); 1056147883Sscottl diagreg = mpt_read(mpt, MPT_OFFSET_DIAGNOSTIC); 1057147883Sscottl } while (--wait && (diagreg & MPI_DIAG_RESET_ADAPTER) == 0); 1058101704Smjacob 1059147883Sscottl if (wait == 0) { 1060147883Sscottl mpt_prt(mpt, "WARNING - Failed hard reset! " 1061147883Sscottl "Trying to initialize anyway.\n"); 1062147883Sscottl } 1063101704Smjacob 1064147883Sscottl /* 1065147883Sscottl * If we have firmware to download, it must be loaded before 1066147883Sscottl * the controller will become operational. Do so now. 1067147883Sscottl */ 1068147883Sscottl if (mpt->fw_image != NULL) { 1069147883Sscottl 1070147883Sscottl error = mpt_download_fw(mpt); 1071147883Sscottl 1072147883Sscottl if (error) { 1073147883Sscottl mpt_prt(mpt, "WARNING - Firmware Download Failed!\n"); 1074147883Sscottl mpt_prt(mpt, "Trying to initialize anyway.\n"); 1075147883Sscottl } 1076101704Smjacob } 1077101704Smjacob 1078147883Sscottl /* 1079147883Sscottl * Reseting the controller should have disabled write 1080147883Sscottl * access to the diagnostic registers, but disable 1081147883Sscottl * manually to be sure. 1082147883Sscottl */ 1083147883Sscottl mpt_disable_diag_mode(mpt); 1084101704Smjacob} 1085101704Smjacob 1086147883Sscottlstatic void 1087147883Sscottlmpt_core_ioc_reset(struct mpt_softc *mpt, int type) 1088147883Sscottl{ 1089147883Sscottl /* 1090147883Sscottl * Complete all pending requests with a status 1091147883Sscottl * appropriate for an IOC reset. 1092147883Sscottl */ 1093147883Sscottl mpt_complete_request_chain(mpt, &mpt->request_pending_list, 1094147883Sscottl MPI_IOCSTATUS_INVALID_STATE); 1095147883Sscottl} 1096147883Sscottl 1097147883Sscottl 1098101704Smjacob/* 1099101704Smjacob * Reset the IOC when needed. Try software command first then if needed 1100101704Smjacob * poke at the magic diagnostic reset. Note that a hard reset resets 1101101704Smjacob * *both* IOCs on dual function chips (FC929 && LSI1030) as well as 1102101704Smjacob * fouls up the PCI configuration registers. 1103101704Smjacob */ 1104101704Smjacobint 1105147883Sscottlmpt_reset(struct mpt_softc *mpt, int reinit) 1106101704Smjacob{ 1107147883Sscottl struct mpt_personality *pers; 1108147883Sscottl int ret; 1109156104Smjacob int retry_cnt = 0; 1110101704Smjacob 1111156104Smjacob /* 1112156104Smjacob * Try a soft reset. If that fails, get out the big hammer. 1113156104Smjacob */ 1114156104Smjacob again: 1115101704Smjacob if ((ret = mpt_soft_reset(mpt)) != MPT_OK) { 1116156104Smjacob int cnt; 1117156104Smjacob for (cnt = 0; cnt < 5; cnt++) { 1118156104Smjacob /* Failed; do a hard reset */ 1119156104Smjacob mpt_hard_reset(mpt); 1120101704Smjacob 1121156104Smjacob /* 1122156104Smjacob * Wait for the IOC to reload 1123156104Smjacob * and come out of reset state 1124156104Smjacob */ 1125156104Smjacob ret = mpt_wait_state(mpt, MPT_DB_STATE_READY); 1126156104Smjacob if (ret == MPT_OK) { 1127156104Smjacob break; 1128156104Smjacob } 1129156104Smjacob /* 1130156104Smjacob * Okay- try to check again... 1131156104Smjacob */ 1132156104Smjacob ret = mpt_wait_state(mpt, MPT_DB_STATE_READY); 1133156104Smjacob if (ret == MPT_OK) { 1134156104Smjacob break; 1135156104Smjacob } 1136156104Smjacob mpt_prt(mpt, "mpt_reset: failed hard reset (%d:%d)\n", 1137156104Smjacob retry_cnt, cnt); 1138156104Smjacob } 1139101704Smjacob } 1140101704Smjacob 1141156104Smjacob if (retry_cnt == 0) { 1142156104Smjacob /* 1143156104Smjacob * Invoke reset handlers. We bump the reset count so 1144156104Smjacob * that mpt_wait_req() understands that regardless of 1145156104Smjacob * the specified wait condition, it should stop its wait. 1146156104Smjacob */ 1147156104Smjacob mpt->reset_cnt++; 1148156104Smjacob MPT_PERS_FOREACH(mpt, pers) 1149156104Smjacob pers->reset(mpt, ret); 1150156104Smjacob } 1151147883Sscottl 1152157354Smjacob if (reinit) { 1153157117Smjacob ret = mpt_enable_ioc(mpt, 1); 1154156104Smjacob if (ret == MPT_OK) { 1155156104Smjacob mpt_enable_ints(mpt); 1156156104Smjacob } 1157156104Smjacob } 1158156104Smjacob if (ret != MPT_OK && retry_cnt++ < 2) { 1159156104Smjacob goto again; 1160156104Smjacob } 1161101704Smjacob return ret; 1162101704Smjacob} 1163101704Smjacob 1164101704Smjacob/* Return a command buffer to the free queue */ 1165101704Smjacobvoid 1166147883Sscottlmpt_free_request(struct mpt_softc *mpt, request_t *req) 1167101704Smjacob{ 1168155521Smjacob request_t *nxt; 1169147883Sscottl struct mpt_evtf_record *record; 1170147883Sscottl uint32_t reply_baddr; 1171147883Sscottl 1172103871Smjacob if (req == NULL || req != &mpt->request_pool[req->index]) { 1173101704Smjacob panic("mpt_free_request bad req ptr\n"); 1174101704Smjacob return; 1175101704Smjacob } 1176155521Smjacob if ((nxt = req->chain) != NULL) { 1177155521Smjacob req->chain = NULL; 1178155521Smjacob mpt_free_request(mpt, nxt); /* NB: recursion */ 1179155521Smjacob } 1180157354Smjacob KASSERT(req->state != REQ_STATE_FREE, ("freeing free request")); 1181157354Smjacob KASSERT(!(req->state & REQ_STATE_LOCKED), ("freeing locked request")); 1182169293Smjacob MPT_LOCK_ASSERT(mpt); 1183157662Smjacob KASSERT(mpt_req_on_free_list(mpt, req) == 0, 1184157662Smjacob ("mpt_free_request: req %p:%u func %x already on freelist", 1185157662Smjacob req, req->serno, ((MSG_REQUEST_HEADER *)req->req_vbuf)->Function)); 1186157662Smjacob KASSERT(mpt_req_on_pending_list(mpt, req) == 0, 1187157662Smjacob ("mpt_free_request: req %p:%u func %x on pending list", 1188157662Smjacob req, req->serno, ((MSG_REQUEST_HEADER *)req->req_vbuf)->Function)); 1189157662Smjacob#ifdef INVARIANTS 1190157662Smjacob mpt_req_not_spcl(mpt, req, "mpt_free_request", __LINE__); 1191157662Smjacob#endif 1192157354Smjacob 1193101704Smjacob req->ccb = NULL; 1194147883Sscottl if (LIST_EMPTY(&mpt->ack_frames)) { 1195157117Smjacob /* 1196157117Smjacob * Insert free ones at the tail 1197157117Smjacob */ 1198157354Smjacob req->serno = 0; 1199157354Smjacob req->state = REQ_STATE_FREE; 1200157662Smjacob#ifdef INVARIANTS 1201157662Smjacob memset(req->req_vbuf, 0xff, sizeof (MSG_REQUEST_HEADER)); 1202157662Smjacob#endif 1203157117Smjacob TAILQ_INSERT_TAIL(&mpt->request_free_list, req, links); 1204147883Sscottl if (mpt->getreqwaiter != 0) { 1205147883Sscottl mpt->getreqwaiter = 0; 1206147883Sscottl wakeup(&mpt->request_free_list); 1207147883Sscottl } 1208147883Sscottl return; 1209147883Sscottl } 1210147883Sscottl 1211147883Sscottl /* 1212147883Sscottl * Process an ack frame deferred due to resource shortage. 1213147883Sscottl */ 1214147883Sscottl record = LIST_FIRST(&mpt->ack_frames); 1215147883Sscottl LIST_REMOVE(record, links); 1216157354Smjacob req->state = REQ_STATE_ALLOCATED; 1217157662Smjacob mpt_assign_serno(mpt, req); 1218147883Sscottl mpt_send_event_ack(mpt, req, &record->reply, record->context); 1219147883Sscottl reply_baddr = (uint32_t)((uint8_t *)record - mpt->reply) 1220147883Sscottl + (mpt->reply_phys & 0xFFFFFFFF); 1221147883Sscottl mpt_free_reply(mpt, reply_baddr); 1222101704Smjacob} 1223101704Smjacob 1224101704Smjacob/* Get a command buffer from the free queue */ 1225101704Smjacobrequest_t * 1226147883Sscottlmpt_get_request(struct mpt_softc *mpt, int sleep_ok) 1227101704Smjacob{ 1228101704Smjacob request_t *req; 1229147883Sscottl 1230147883Sscottlretry: 1231169293Smjacob MPT_LOCK_ASSERT(mpt); 1232147883Sscottl req = TAILQ_FIRST(&mpt->request_free_list); 1233101704Smjacob if (req != NULL) { 1234147883Sscottl KASSERT(req == &mpt->request_pool[req->index], 1235147883Sscottl ("mpt_get_request: corrupted request free list\n")); 1236157354Smjacob KASSERT(req->state == REQ_STATE_FREE, 1237157662Smjacob ("req %p:%u not free on free list %x index %d function %x", 1238157662Smjacob req, req->serno, req->state, req->index, 1239157662Smjacob ((MSG_REQUEST_HEADER *)req->req_vbuf)->Function)); 1240147883Sscottl TAILQ_REMOVE(&mpt->request_free_list, req, links); 1241147883Sscottl req->state = REQ_STATE_ALLOCATED; 1242155521Smjacob req->chain = NULL; 1243157662Smjacob mpt_assign_serno(mpt, req); 1244147883Sscottl } else if (sleep_ok != 0) { 1245147883Sscottl mpt->getreqwaiter = 1; 1246147883Sscottl mpt_sleep(mpt, &mpt->request_free_list, PUSER, "mptgreq", 0); 1247147883Sscottl goto retry; 1248101704Smjacob } 1249157354Smjacob return (req); 1250101704Smjacob} 1251101704Smjacob 1252101704Smjacob/* Pass the command to the IOC */ 1253101704Smjacobvoid 1254147883Sscottlmpt_send_cmd(struct mpt_softc *mpt, request_t *req) 1255101704Smjacob{ 1256158982Smjacob if (mpt->verbose > MPT_PRT_DEBUG2) { 1257158932Smjacob mpt_dump_request(mpt, req); 1258155521Smjacob } 1259101704Smjacob bus_dmamap_sync(mpt->request_dmat, mpt->request_dmap, 1260103914Smjacob BUS_DMASYNC_PREWRITE); 1261147883Sscottl req->state |= REQ_STATE_QUEUED; 1262157662Smjacob KASSERT(mpt_req_on_free_list(mpt, req) == 0, 1263157662Smjacob ("req %p:%u func %x on freelist list in mpt_send_cmd", 1264157662Smjacob req, req->serno, ((MSG_REQUEST_HEADER *)req->req_vbuf)->Function)); 1265157662Smjacob KASSERT(mpt_req_on_pending_list(mpt, req) == 0, 1266157662Smjacob ("req %p:%u func %x already on pending list in mpt_send_cmd", 1267157662Smjacob req, req->serno, ((MSG_REQUEST_HEADER *)req->req_vbuf)->Function)); 1268147883Sscottl TAILQ_INSERT_HEAD(&mpt->request_pending_list, req, links); 1269147883Sscottl mpt_write(mpt, MPT_OFFSET_REQUEST_Q, (uint32_t) req->req_pbuf); 1270101704Smjacob} 1271101704Smjacob 1272101704Smjacob/* 1273147883Sscottl * Wait for a request to complete. 1274147883Sscottl * 1275147883Sscottl * Inputs: 1276147883Sscottl * mpt softc of controller executing request 1277147883Sscottl * req request to wait for 1278147883Sscottl * sleep_ok nonzero implies may sleep in this context 1279147883Sscottl * time_ms timeout in ms. 0 implies no timeout. 1280147883Sscottl * 1281147883Sscottl * Return Values: 1282147883Sscottl * 0 Request completed 1283147883Sscottl * non-0 Timeout fired before request completion. 1284101704Smjacob */ 1285147883Sscottlint 1286147883Sscottlmpt_wait_req(struct mpt_softc *mpt, request_t *req, 1287147883Sscottl mpt_req_state_t state, mpt_req_state_t mask, 1288147883Sscottl int sleep_ok, int time_ms) 1289101704Smjacob{ 1290147883Sscottl int error; 1291147883Sscottl int timeout; 1292147883Sscottl u_int saved_cnt; 1293101704Smjacob 1294147883Sscottl /* 1295147883Sscottl * timeout is in ms. 0 indicates infinite wait. 1296147883Sscottl * Convert to ticks or 500us units depending on 1297147883Sscottl * our sleep mode. 1298147883Sscottl */ 1299157117Smjacob if (sleep_ok != 0) { 1300147883Sscottl timeout = (time_ms * hz) / 1000; 1301157117Smjacob } else { 1302147883Sscottl timeout = time_ms * 2; 1303157117Smjacob } 1304147883Sscottl req->state |= REQ_STATE_NEED_WAKEUP; 1305147883Sscottl mask &= ~REQ_STATE_NEED_WAKEUP; 1306155521Smjacob saved_cnt = mpt->reset_cnt; 1307157117Smjacob while ((req->state & mask) != state && mpt->reset_cnt == saved_cnt) { 1308147883Sscottl if (sleep_ok != 0) { 1309147883Sscottl error = mpt_sleep(mpt, req, PUSER, "mptreq", timeout); 1310147883Sscottl if (error == EWOULDBLOCK) { 1311147883Sscottl timeout = 0; 1312147883Sscottl break; 1313147883Sscottl } 1314147883Sscottl } else { 1315147883Sscottl if (time_ms != 0 && --timeout == 0) { 1316147883Sscottl break; 1317147883Sscottl } 1318147883Sscottl DELAY(500); 1319147883Sscottl mpt_intr(mpt); 1320147883Sscottl } 1321147883Sscottl } 1322147883Sscottl req->state &= ~REQ_STATE_NEED_WAKEUP; 1323157117Smjacob if (mpt->reset_cnt != saved_cnt) { 1324147883Sscottl return (EIO); 1325157117Smjacob } 1326157117Smjacob if (time_ms && timeout <= 0) { 1327157117Smjacob MSG_REQUEST_HEADER *msg_hdr = req->req_vbuf; 1328160396Smjacob req->state |= REQ_STATE_TIMEDOUT; 1329157117Smjacob mpt_prt(mpt, "mpt_wait_req(%x) timed out\n", msg_hdr->Function); 1330147883Sscottl return (ETIMEDOUT); 1331157117Smjacob } 1332147883Sscottl return (0); 1333101704Smjacob} 1334101704Smjacob 1335101704Smjacob/* 1336101704Smjacob * Send a command to the IOC via the handshake register. 1337101704Smjacob * 1338101704Smjacob * Only done at initialization time and for certain unusual 1339101704Smjacob * commands such as device/bus reset as specified by LSI. 1340101704Smjacob */ 1341101704Smjacobint 1342147883Sscottlmpt_send_handshake_cmd(struct mpt_softc *mpt, size_t len, void *cmd) 1343101704Smjacob{ 1344101704Smjacob int i; 1345147883Sscottl uint32_t data, *data32; 1346101704Smjacob 1347101704Smjacob /* Check condition of the IOC */ 1348101704Smjacob data = mpt_rd_db(mpt); 1349147883Sscottl if ((MPT_STATE(data) != MPT_DB_STATE_READY 1350147883Sscottl && MPT_STATE(data) != MPT_DB_STATE_RUNNING 1351147883Sscottl && MPT_STATE(data) != MPT_DB_STATE_FAULT) 1352147883Sscottl || MPT_DB_IS_IN_USE(data)) { 1353147883Sscottl mpt_prt(mpt, "handshake aborted - invalid doorbell state\n"); 1354101704Smjacob mpt_print_db(data); 1355147883Sscottl return (EBUSY); 1356101704Smjacob } 1357101704Smjacob 1358101704Smjacob /* We move things in 32 bit chunks */ 1359101704Smjacob len = (len + 3) >> 2; 1360101704Smjacob data32 = cmd; 1361101704Smjacob 1362172568Skevlo /* Clear any left over pending doorbell interrupts */ 1363101704Smjacob if (MPT_DB_INTR(mpt_rd_intr(mpt))) 1364101704Smjacob mpt_write(mpt, MPT_OFFSET_INTR_STATUS, 0); 1365101704Smjacob 1366101704Smjacob /* 1367101704Smjacob * Tell the handshake reg. we are going to send a command 1368101704Smjacob * and how long it is going to be. 1369101704Smjacob */ 1370101704Smjacob data = (MPI_FUNCTION_HANDSHAKE << MPI_DOORBELL_FUNCTION_SHIFT) | 1371101704Smjacob (len << MPI_DOORBELL_ADD_DWORDS_SHIFT); 1372101704Smjacob mpt_write(mpt, MPT_OFFSET_DOORBELL, data); 1373101704Smjacob 1374101704Smjacob /* Wait for the chip to notice */ 1375101704Smjacob if (mpt_wait_db_int(mpt) != MPT_OK) { 1376164837Smjacob mpt_prt(mpt, "mpt_send_handshake_cmd: db ignored\n"); 1377147883Sscottl return (ETIMEDOUT); 1378101704Smjacob } 1379101704Smjacob 1380101704Smjacob /* Clear the interrupt */ 1381101704Smjacob mpt_write(mpt, MPT_OFFSET_INTR_STATUS, 0); 1382101704Smjacob 1383101704Smjacob if (mpt_wait_db_ack(mpt) != MPT_OK) { 1384164837Smjacob mpt_prt(mpt, "mpt_send_handshake_cmd: db ack timed out\n"); 1385147883Sscottl return (ETIMEDOUT); 1386101704Smjacob } 1387101704Smjacob 1388101704Smjacob /* Send the command */ 1389101704Smjacob for (i = 0; i < len; i++) { 1390164315Sjb mpt_write(mpt, MPT_OFFSET_DOORBELL, htole32(*data32++)); 1391101704Smjacob if (mpt_wait_db_ack(mpt) != MPT_OK) { 1392156104Smjacob mpt_prt(mpt, 1393164837Smjacob "mpt_send_handshake_cmd: timeout @ index %d\n", i); 1394147883Sscottl return (ETIMEDOUT); 1395101704Smjacob } 1396101704Smjacob } 1397101704Smjacob return MPT_OK; 1398101704Smjacob} 1399101704Smjacob 1400101704Smjacob/* Get the response from the handshake register */ 1401101704Smjacobint 1402147883Sscottlmpt_recv_handshake_reply(struct mpt_softc *mpt, size_t reply_len, void *reply) 1403101704Smjacob{ 1404101704Smjacob int left, reply_left; 1405101704Smjacob u_int16_t *data16; 1406164315Sjb uint32_t data; 1407101704Smjacob MSG_DEFAULT_REPLY *hdr; 1408101704Smjacob 1409101704Smjacob /* We move things out in 16 bit chunks */ 1410101704Smjacob reply_len >>= 1; 1411101704Smjacob data16 = (u_int16_t *)reply; 1412101704Smjacob 1413101704Smjacob hdr = (MSG_DEFAULT_REPLY *)reply; 1414101704Smjacob 1415101704Smjacob /* Get first word */ 1416101704Smjacob if (mpt_wait_db_int(mpt) != MPT_OK) { 1417147883Sscottl mpt_prt(mpt, "mpt_recv_handshake_cmd timeout1\n"); 1418101704Smjacob return ETIMEDOUT; 1419101704Smjacob } 1420164315Sjb data = mpt_read(mpt, MPT_OFFSET_DOORBELL); 1421164315Sjb *data16++ = le16toh(data & MPT_DB_DATA_MASK); 1422101704Smjacob mpt_write(mpt, MPT_OFFSET_INTR_STATUS, 0); 1423101704Smjacob 1424101704Smjacob /* Get Second Word */ 1425101704Smjacob if (mpt_wait_db_int(mpt) != MPT_OK) { 1426147883Sscottl mpt_prt(mpt, "mpt_recv_handshake_cmd timeout2\n"); 1427101704Smjacob return ETIMEDOUT; 1428101704Smjacob } 1429164315Sjb data = mpt_read(mpt, MPT_OFFSET_DOORBELL); 1430164315Sjb *data16++ = le16toh(data & MPT_DB_DATA_MASK); 1431101704Smjacob mpt_write(mpt, MPT_OFFSET_INTR_STATUS, 0); 1432101704Smjacob 1433157354Smjacob /* 1434157354Smjacob * With the second word, we can now look at the length. 1435157354Smjacob * Warn about a reply that's too short (except for IOC FACTS REPLY) 1436157354Smjacob */ 1437157354Smjacob if ((reply_len >> 1) != hdr->MsgLength && 1438157354Smjacob (hdr->Function != MPI_FUNCTION_IOC_FACTS)){ 1439157354Smjacob#if __FreeBSD_version >= 500000 1440103914Smjacob mpt_prt(mpt, "reply length does not match message length: " 1441157382Smjacob "got %x; expected %zx for function %x\n", 1442157354Smjacob hdr->MsgLength << 2, reply_len << 1, hdr->Function); 1443157354Smjacob#else 1444157354Smjacob mpt_prt(mpt, "reply length does not match message length: " 1445157382Smjacob "got %x; expected %x for function %x\n", 1446157354Smjacob hdr->MsgLength << 2, reply_len << 1, hdr->Function); 1447157354Smjacob#endif 1448101704Smjacob } 1449101704Smjacob 1450101704Smjacob /* Get rest of the reply; but don't overflow the provided buffer */ 1451101704Smjacob left = (hdr->MsgLength << 1) - 2; 1452101704Smjacob reply_left = reply_len - 2; 1453101704Smjacob while (left--) { 1454101704Smjacob u_int16_t datum; 1455101704Smjacob 1456101704Smjacob if (mpt_wait_db_int(mpt) != MPT_OK) { 1457147883Sscottl mpt_prt(mpt, "mpt_recv_handshake_cmd timeout3\n"); 1458101704Smjacob return ETIMEDOUT; 1459101704Smjacob } 1460164315Sjb data = mpt_read(mpt, MPT_OFFSET_DOORBELL); 1461164315Sjb datum = le16toh(data & MPT_DB_DATA_MASK); 1462101704Smjacob 1463101704Smjacob if (reply_left-- > 0) 1464164315Sjb *data16++ = datum; 1465101704Smjacob 1466101704Smjacob mpt_write(mpt, MPT_OFFSET_INTR_STATUS, 0); 1467101704Smjacob } 1468101704Smjacob 1469101704Smjacob /* One more wait & clear at the end */ 1470101704Smjacob if (mpt_wait_db_int(mpt) != MPT_OK) { 1471147883Sscottl mpt_prt(mpt, "mpt_recv_handshake_cmd timeout4\n"); 1472101704Smjacob return ETIMEDOUT; 1473101704Smjacob } 1474101704Smjacob mpt_write(mpt, MPT_OFFSET_INTR_STATUS, 0); 1475101704Smjacob 1476101704Smjacob if ((hdr->IOCStatus & MPI_IOCSTATUS_MASK) != MPI_IOCSTATUS_SUCCESS) { 1477147883Sscottl if (mpt->verbose >= MPT_PRT_TRACE) 1478101704Smjacob mpt_print_reply(hdr); 1479101704Smjacob return (MPT_FAIL | hdr->IOCStatus); 1480101704Smjacob } 1481101704Smjacob 1482101704Smjacob return (0); 1483101704Smjacob} 1484101704Smjacob 1485101704Smjacobstatic int 1486147883Sscottlmpt_get_iocfacts(struct mpt_softc *mpt, MSG_IOC_FACTS_REPLY *freplp) 1487101704Smjacob{ 1488101704Smjacob MSG_IOC_FACTS f_req; 1489101704Smjacob int error; 1490101704Smjacob 1491157354Smjacob memset(&f_req, 0, sizeof f_req); 1492101704Smjacob f_req.Function = MPI_FUNCTION_IOC_FACTS; 1493147883Sscottl f_req.MsgContext = htole32(MPT_REPLY_HANDLER_HANDSHAKE); 1494101704Smjacob error = mpt_send_handshake_cmd(mpt, sizeof f_req, &f_req); 1495164990Smjacob if (error) { 1496101704Smjacob return(error); 1497164990Smjacob } 1498101704Smjacob error = mpt_recv_handshake_reply(mpt, sizeof (*freplp), freplp); 1499101704Smjacob return (error); 1500101704Smjacob} 1501101704Smjacob 1502102199Smjacobstatic int 1503164990Smjacobmpt_get_portfacts(struct mpt_softc *mpt, U8 port, MSG_PORT_FACTS_REPLY *freplp) 1504102199Smjacob{ 1505102199Smjacob MSG_PORT_FACTS f_req; 1506102199Smjacob int error; 1507102199Smjacob 1508147883Sscottl memset(&f_req, 0, sizeof f_req); 1509102199Smjacob f_req.Function = MPI_FUNCTION_PORT_FACTS; 1510164990Smjacob f_req.PortNumber = port; 1511147883Sscottl f_req.MsgContext = htole32(MPT_REPLY_HANDLER_HANDSHAKE); 1512102199Smjacob error = mpt_send_handshake_cmd(mpt, sizeof f_req, &f_req); 1513164990Smjacob if (error) { 1514102199Smjacob return(error); 1515164990Smjacob } 1516102199Smjacob error = mpt_recv_handshake_reply(mpt, sizeof (*freplp), freplp); 1517102199Smjacob return (error); 1518102199Smjacob} 1519102199Smjacob 1520101704Smjacob/* 1521101704Smjacob * Send the initialization request. This is where we specify how many 1522101704Smjacob * SCSI busses and how many devices per bus we wish to emulate. 1523101704Smjacob * This is also the command that specifies the max size of the reply 1524101704Smjacob * frames from the IOC that we will be allocating. 1525101704Smjacob */ 1526101704Smjacobstatic int 1527147883Sscottlmpt_send_ioc_init(struct mpt_softc *mpt, uint32_t who) 1528101704Smjacob{ 1529101704Smjacob int error = 0; 1530101704Smjacob MSG_IOC_INIT init; 1531101704Smjacob MSG_IOC_INIT_REPLY reply; 1532101704Smjacob 1533157354Smjacob memset(&init, 0, sizeof init); 1534101704Smjacob init.WhoInit = who; 1535101704Smjacob init.Function = MPI_FUNCTION_IOC_INIT; 1536164990Smjacob init.MaxDevices = 0; /* at least 256 devices per bus */ 1537164990Smjacob init.MaxBuses = 16; /* at least 16 busses */ 1538155521Smjacob 1539155521Smjacob init.MsgVersion = htole16(MPI_VERSION); 1540155521Smjacob init.HeaderVersion = htole16(MPI_HEADER_VERSION); 1541155521Smjacob init.ReplyFrameSize = htole16(MPT_REPLY_SIZE); 1542147883Sscottl init.MsgContext = htole32(MPT_REPLY_HANDLER_HANDSHAKE); 1543101704Smjacob 1544101704Smjacob if ((error = mpt_send_handshake_cmd(mpt, sizeof init, &init)) != 0) { 1545101704Smjacob return(error); 1546101704Smjacob } 1547101704Smjacob 1548101704Smjacob error = mpt_recv_handshake_reply(mpt, sizeof reply, &reply); 1549101704Smjacob return (error); 1550101704Smjacob} 1551101704Smjacob 1552102199Smjacob 1553102199Smjacob/* 1554102199Smjacob * Utiltity routine to read configuration headers and pages 1555102199Smjacob */ 1556147883Sscottlint 1557170252Sscottlmpt_issue_cfg_req(struct mpt_softc *mpt, request_t *req, cfgparms_t *params, 1558170252Sscottl bus_addr_t addr, bus_size_t len, int sleep_ok, int timeout_ms) 1559101704Smjacob{ 1560102199Smjacob MSG_CONFIG *cfgp; 1561147883Sscottl SGE_SIMPLE32 *se; 1562102199Smjacob 1563102199Smjacob cfgp = req->req_vbuf; 1564147883Sscottl memset(cfgp, 0, sizeof *cfgp); 1565170252Sscottl cfgp->Action = params->Action; 1566102199Smjacob cfgp->Function = MPI_FUNCTION_CONFIG; 1567170252Sscottl cfgp->Header.PageVersion = params->PageVersion; 1568170252Sscottl cfgp->Header.PageNumber = params->PageNumber; 1569170252Sscottl cfgp->PageAddress = htole32(params->PageAddress); 1570170252Sscottl if ((params->PageType & MPI_CONFIG_PAGETYPE_MASK) == 1571170252Sscottl MPI_CONFIG_PAGETYPE_EXTENDED) { 1572170252Sscottl cfgp->Header.PageType = MPI_CONFIG_PAGETYPE_EXTENDED; 1573170252Sscottl cfgp->Header.PageLength = 0; 1574170252Sscottl cfgp->ExtPageLength = htole16(params->ExtPageLength); 1575170252Sscottl cfgp->ExtPageType = params->ExtPageType; 1576170252Sscottl } else { 1577170252Sscottl cfgp->Header.PageType = params->PageType; 1578170252Sscottl cfgp->Header.PageLength = params->PageLength; 1579170252Sscottl } 1580147883Sscottl se = (SGE_SIMPLE32 *)&cfgp->PageBufferSGE; 1581164315Sjb se->Address = htole32(addr); 1582147883Sscottl MPI_pSGE_SET_LENGTH(se, len); 1583147883Sscottl MPI_pSGE_SET_FLAGS(se, (MPI_SGE_FLAGS_SIMPLE_ELEMENT | 1584147883Sscottl MPI_SGE_FLAGS_LAST_ELEMENT | MPI_SGE_FLAGS_END_OF_BUFFER | 1585147883Sscottl MPI_SGE_FLAGS_END_OF_LIST | 1586170252Sscottl ((params->Action == MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT 1587170252Sscottl || params->Action == MPI_CONFIG_ACTION_PAGE_WRITE_NVRAM) 1588147883Sscottl ? MPI_SGE_FLAGS_HOST_TO_IOC : MPI_SGE_FLAGS_IOC_TO_HOST))); 1589164315Sjb se->FlagsLength = htole32(se->FlagsLength); 1590147883Sscottl cfgp->MsgContext = htole32(req->index | MPT_REPLY_HANDLER_CONFIG); 1591102199Smjacob 1592102199Smjacob mpt_check_doorbell(mpt); 1593102199Smjacob mpt_send_cmd(mpt, req); 1594147883Sscottl return (mpt_wait_req(mpt, req, REQ_STATE_DONE, REQ_STATE_DONE, 1595147883Sscottl sleep_ok, timeout_ms)); 1596147883Sscottl} 1597102199Smjacob 1598170252Sscottlint 1599170252Sscottlmpt_read_extcfg_header(struct mpt_softc *mpt, int PageVersion, int PageNumber, 1600170252Sscottl uint32_t PageAddress, int ExtPageType, 1601170252Sscottl CONFIG_EXTENDED_PAGE_HEADER *rslt, 1602170252Sscottl int sleep_ok, int timeout_ms) 1603170252Sscottl{ 1604170252Sscottl request_t *req; 1605170252Sscottl cfgparms_t params; 1606170252Sscottl MSG_CONFIG_REPLY *cfgp; 1607170252Sscottl int error; 1608147883Sscottl 1609170252Sscottl req = mpt_get_request(mpt, sleep_ok); 1610170252Sscottl if (req == NULL) { 1611170252Sscottl mpt_prt(mpt, "mpt_extread_cfg_header: Get request failed!\n"); 1612170252Sscottl return (ENOMEM); 1613170252Sscottl } 1614170252Sscottl 1615170252Sscottl params.Action = MPI_CONFIG_ACTION_PAGE_HEADER; 1616170252Sscottl params.PageVersion = PageVersion; 1617170252Sscottl params.PageLength = 0; 1618170252Sscottl params.PageNumber = PageNumber; 1619170252Sscottl params.PageType = MPI_CONFIG_PAGETYPE_EXTENDED; 1620170252Sscottl params.PageAddress = PageAddress; 1621170252Sscottl params.ExtPageType = ExtPageType; 1622170252Sscottl params.ExtPageLength = 0; 1623170252Sscottl error = mpt_issue_cfg_req(mpt, req, ¶ms, /*addr*/0, /*len*/0, 1624170252Sscottl sleep_ok, timeout_ms); 1625170252Sscottl if (error != 0) { 1626170252Sscottl /* 1627170252Sscottl * Leave the request. Without resetting the chip, it's 1628170252Sscottl * still owned by it and we'll just get into trouble 1629170252Sscottl * freeing it now. Mark it as abandoned so that if it 1630170252Sscottl * shows up later it can be freed. 1631170252Sscottl */ 1632170252Sscottl mpt_prt(mpt, "read_extcfg_header timed out\n"); 1633170252Sscottl return (ETIMEDOUT); 1634170252Sscottl } 1635170252Sscottl 1636170252Sscottl switch (req->IOCStatus & MPI_IOCSTATUS_MASK) { 1637170252Sscottl case MPI_IOCSTATUS_SUCCESS: 1638170252Sscottl cfgp = req->req_vbuf; 1639170252Sscottl rslt->PageVersion = cfgp->Header.PageVersion; 1640170252Sscottl rslt->PageNumber = cfgp->Header.PageNumber; 1641170252Sscottl rslt->PageType = cfgp->Header.PageType; 1642186878Smarius rslt->ExtPageLength = le16toh(cfgp->ExtPageLength); 1643170252Sscottl rslt->ExtPageType = cfgp->ExtPageType; 1644170252Sscottl error = 0; 1645170252Sscottl break; 1646170252Sscottl case MPI_IOCSTATUS_CONFIG_INVALID_PAGE: 1647170252Sscottl mpt_lprt(mpt, MPT_PRT_DEBUG, 1648170252Sscottl "Invalid Page Type %d Number %d Addr 0x%0x\n", 1649170252Sscottl MPI_CONFIG_PAGETYPE_EXTENDED, PageNumber, PageAddress); 1650170252Sscottl error = EINVAL; 1651170252Sscottl break; 1652170252Sscottl default: 1653170252Sscottl mpt_prt(mpt, "mpt_read_extcfg_header: Config Info Status %x\n", 1654170252Sscottl req->IOCStatus); 1655170252Sscottl error = EIO; 1656170252Sscottl break; 1657170252Sscottl } 1658170252Sscottl mpt_free_request(mpt, req); 1659170252Sscottl return (error); 1660170252Sscottl} 1661170252Sscottl 1662147883Sscottlint 1663170252Sscottlmpt_read_extcfg_page(struct mpt_softc *mpt, int Action, uint32_t PageAddress, 1664170252Sscottl CONFIG_EXTENDED_PAGE_HEADER *hdr, void *buf, size_t len, 1665170252Sscottl int sleep_ok, int timeout_ms) 1666170252Sscottl{ 1667170252Sscottl request_t *req; 1668170252Sscottl cfgparms_t params; 1669170252Sscottl int error; 1670170252Sscottl 1671170252Sscottl req = mpt_get_request(mpt, sleep_ok); 1672170252Sscottl if (req == NULL) { 1673186878Smarius mpt_prt(mpt, "mpt_read_extcfg_page: Get request failed!\n"); 1674170252Sscottl return (-1); 1675170252Sscottl } 1676170252Sscottl 1677170252Sscottl params.Action = Action; 1678170252Sscottl params.PageVersion = hdr->PageVersion; 1679170252Sscottl params.PageLength = 0; 1680170252Sscottl params.PageNumber = hdr->PageNumber; 1681170252Sscottl params.PageType = MPI_CONFIG_PAGETYPE_EXTENDED; 1682170252Sscottl params.PageAddress = PageAddress; 1683170252Sscottl params.ExtPageType = hdr->ExtPageType; 1684170252Sscottl params.ExtPageLength = hdr->ExtPageLength; 1685170252Sscottl error = mpt_issue_cfg_req(mpt, req, ¶ms, 1686170252Sscottl req->req_pbuf + MPT_RQSL(mpt), 1687170252Sscottl len, sleep_ok, timeout_ms); 1688170252Sscottl if (error != 0) { 1689170252Sscottl mpt_prt(mpt, "read_extcfg_page(%d) timed out\n", Action); 1690170252Sscottl return (-1); 1691170252Sscottl } 1692170252Sscottl 1693170252Sscottl if ((req->IOCStatus & MPI_IOCSTATUS_MASK) != MPI_IOCSTATUS_SUCCESS) { 1694170252Sscottl mpt_prt(mpt, "mpt_read_extcfg_page: Config Info Status %x\n", 1695170252Sscottl req->IOCStatus); 1696170252Sscottl mpt_free_request(mpt, req); 1697170252Sscottl return (-1); 1698170252Sscottl } 1699170252Sscottl bus_dmamap_sync(mpt->request_dmat, mpt->request_dmap, 1700170252Sscottl BUS_DMASYNC_POSTREAD); 1701170252Sscottl memcpy(buf, ((uint8_t *)req->req_vbuf)+MPT_RQSL(mpt), len); 1702170252Sscottl mpt_free_request(mpt, req); 1703170252Sscottl return (0); 1704170252Sscottl} 1705170252Sscottl 1706170252Sscottlint 1707147883Sscottlmpt_read_cfg_header(struct mpt_softc *mpt, int PageType, int PageNumber, 1708147883Sscottl uint32_t PageAddress, CONFIG_PAGE_HEADER *rslt, 1709147883Sscottl int sleep_ok, int timeout_ms) 1710147883Sscottl{ 1711147883Sscottl request_t *req; 1712170252Sscottl cfgparms_t params; 1713156104Smjacob MSG_CONFIG *cfgp; 1714147883Sscottl int error; 1715147883Sscottl 1716147883Sscottl req = mpt_get_request(mpt, sleep_ok); 1717147883Sscottl if (req == NULL) { 1718147883Sscottl mpt_prt(mpt, "mpt_read_cfg_header: Get request failed!\n"); 1719156104Smjacob return (ENOMEM); 1720102199Smjacob } 1721147883Sscottl 1722170252Sscottl params.Action = MPI_CONFIG_ACTION_PAGE_HEADER; 1723170252Sscottl params.PageVersion = 0; 1724170252Sscottl params.PageLength = 0; 1725170252Sscottl params.PageNumber = PageNumber; 1726170252Sscottl params.PageType = PageType; 1727170252Sscottl params.PageAddress = PageAddress; 1728170252Sscottl error = mpt_issue_cfg_req(mpt, req, ¶ms, /*addr*/0, /*len*/0, 1729147883Sscottl sleep_ok, timeout_ms); 1730147883Sscottl if (error != 0) { 1731160396Smjacob /* 1732160396Smjacob * Leave the request. Without resetting the chip, it's 1733160396Smjacob * still owned by it and we'll just get into trouble 1734160396Smjacob * freeing it now. Mark it as abandoned so that if it 1735160396Smjacob * shows up later it can be freed. 1736160396Smjacob */ 1737147883Sscottl mpt_prt(mpt, "read_cfg_header timed out\n"); 1738156104Smjacob return (ETIMEDOUT); 1739147883Sscottl } 1740147883Sscottl 1741156104Smjacob switch (req->IOCStatus & MPI_IOCSTATUS_MASK) { 1742156104Smjacob case MPI_IOCSTATUS_SUCCESS: 1743147883Sscottl cfgp = req->req_vbuf; 1744147883Sscottl bcopy(&cfgp->Header, rslt, sizeof(*rslt)); 1745147883Sscottl error = 0; 1746156104Smjacob break; 1747156104Smjacob case MPI_IOCSTATUS_CONFIG_INVALID_PAGE: 1748156104Smjacob mpt_lprt(mpt, MPT_PRT_DEBUG, 1749156104Smjacob "Invalid Page Type %d Number %d Addr 0x%0x\n", 1750156104Smjacob PageType, PageNumber, PageAddress); 1751156104Smjacob error = EINVAL; 1752156104Smjacob break; 1753156104Smjacob default: 1754156104Smjacob mpt_prt(mpt, "mpt_read_cfg_header: Config Info Status %x\n", 1755156104Smjacob req->IOCStatus); 1756156104Smjacob error = EIO; 1757156104Smjacob break; 1758147883Sscottl } 1759102199Smjacob mpt_free_request(mpt, req); 1760147883Sscottl return (error); 1761102199Smjacob} 1762102199Smjacob 1763102822Smjacobint 1764147883Sscottlmpt_read_cfg_page(struct mpt_softc *mpt, int Action, uint32_t PageAddress, 1765147883Sscottl CONFIG_PAGE_HEADER *hdr, size_t len, int sleep_ok, 1766147883Sscottl int timeout_ms) 1767102199Smjacob{ 1768147883Sscottl request_t *req; 1769170252Sscottl cfgparms_t params; 1770147883Sscottl int error; 1771102199Smjacob 1772147883Sscottl req = mpt_get_request(mpt, sleep_ok); 1773147883Sscottl if (req == NULL) { 1774147883Sscottl mpt_prt(mpt, "mpt_read_cfg_page: Get request failed!\n"); 1775147883Sscottl return (-1); 1776147883Sscottl } 1777102199Smjacob 1778170252Sscottl params.Action = Action; 1779170252Sscottl params.PageVersion = hdr->PageVersion; 1780170252Sscottl params.PageLength = hdr->PageLength; 1781170252Sscottl params.PageNumber = hdr->PageNumber; 1782170252Sscottl params.PageType = hdr->PageType & MPI_CONFIG_PAGETYPE_MASK; 1783170252Sscottl params.PageAddress = PageAddress; 1784170252Sscottl error = mpt_issue_cfg_req(mpt, req, ¶ms, 1785170252Sscottl req->req_pbuf + MPT_RQSL(mpt), 1786147883Sscottl len, sleep_ok, timeout_ms); 1787147883Sscottl if (error != 0) { 1788147883Sscottl mpt_prt(mpt, "read_cfg_page(%d) timed out\n", Action); 1789147883Sscottl return (-1); 1790147883Sscottl } 1791102199Smjacob 1792147883Sscottl if ((req->IOCStatus & MPI_IOCSTATUS_MASK) != MPI_IOCSTATUS_SUCCESS) { 1793147883Sscottl mpt_prt(mpt, "mpt_read_cfg_page: Config Info Status %x\n", 1794147883Sscottl req->IOCStatus); 1795147883Sscottl mpt_free_request(mpt, req); 1796102199Smjacob return (-1); 1797102199Smjacob } 1798102199Smjacob bus_dmamap_sync(mpt->request_dmat, mpt->request_dmap, 1799102199Smjacob BUS_DMASYNC_POSTREAD); 1800157117Smjacob memcpy(hdr, ((uint8_t *)req->req_vbuf)+MPT_RQSL(mpt), len); 1801102199Smjacob mpt_free_request(mpt, req); 1802102199Smjacob return (0); 1803102199Smjacob} 1804102199Smjacob 1805102822Smjacobint 1806147883Sscottlmpt_write_cfg_page(struct mpt_softc *mpt, int Action, uint32_t PageAddress, 1807147883Sscottl CONFIG_PAGE_HEADER *hdr, size_t len, int sleep_ok, 1808147883Sscottl int timeout_ms) 1809102199Smjacob{ 1810147883Sscottl request_t *req; 1811170252Sscottl cfgparms_t params; 1812147883Sscottl u_int hdr_attr; 1813147883Sscottl int error; 1814102199Smjacob 1815102199Smjacob hdr_attr = hdr->PageType & MPI_CONFIG_PAGEATTR_MASK; 1816102199Smjacob if (hdr_attr != MPI_CONFIG_PAGEATTR_CHANGEABLE && 1817102199Smjacob hdr_attr != MPI_CONFIG_PAGEATTR_PERSISTENT) { 1818147883Sscottl mpt_prt(mpt, "page type 0x%x not changeable\n", 1819147883Sscottl hdr->PageType & MPI_CONFIG_PAGETYPE_MASK); 1820102199Smjacob return (-1); 1821102199Smjacob } 1822102199Smjacob 1823160290Smjacob#if 0 1824160290Smjacob /* 1825160290Smjacob * We shouldn't mask off other bits here. 1826160290Smjacob */ 1827160290Smjacob hdr->PageType &= MPI_CONFIG_PAGETYPE_MASK; 1828160290Smjacob#endif 1829160290Smjacob 1830147883Sscottl req = mpt_get_request(mpt, sleep_ok); 1831147883Sscottl if (req == NULL) 1832147883Sscottl return (-1); 1833102199Smjacob 1834160290Smjacob memcpy(((caddr_t)req->req_vbuf) + MPT_RQSL(mpt), hdr, len); 1835160290Smjacob 1836160290Smjacob /* 1837160290Smjacob * There isn't any point in restoring stripped out attributes 1838160290Smjacob * if you then mask them going down to issue the request. 1839160290Smjacob */ 1840160290Smjacob 1841170252Sscottl params.Action = Action; 1842170252Sscottl params.PageVersion = hdr->PageVersion; 1843170252Sscottl params.PageLength = hdr->PageLength; 1844170252Sscottl params.PageNumber = hdr->PageNumber; 1845170252Sscottl params.PageAddress = PageAddress; 1846160290Smjacob#if 0 1847147883Sscottl /* Restore stripped out attributes */ 1848147883Sscottl hdr->PageType |= hdr_attr; 1849170252Sscottl params.PageType = hdr->PageType & MPI_CONFIG_PAGETYPE_MASK; 1850160290Smjacob#else 1851170252Sscottl params.PageType = hdr->PageType; 1852170252Sscottl#endif 1853170252Sscottl error = mpt_issue_cfg_req(mpt, req, ¶ms, 1854160290Smjacob req->req_pbuf + MPT_RQSL(mpt), 1855160290Smjacob len, sleep_ok, timeout_ms); 1856147883Sscottl if (error != 0) { 1857147883Sscottl mpt_prt(mpt, "mpt_write_cfg_page timed out\n"); 1858147883Sscottl return (-1); 1859147883Sscottl } 1860102199Smjacob 1861147883Sscottl if ((req->IOCStatus & MPI_IOCSTATUS_MASK) != MPI_IOCSTATUS_SUCCESS) { 1862147883Sscottl mpt_prt(mpt, "mpt_write_cfg_page: Config Info Status %x\n", 1863147883Sscottl req->IOCStatus); 1864147883Sscottl mpt_free_request(mpt, req); 1865147883Sscottl return (-1); 1866102199Smjacob } 1867147883Sscottl mpt_free_request(mpt, req); 1868147883Sscottl return (0); 1869147883Sscottl} 1870102199Smjacob 1871147883Sscottl/* 1872147883Sscottl * Read IOC configuration information 1873147883Sscottl */ 1874147883Sscottlstatic int 1875147883Sscottlmpt_read_config_info_ioc(struct mpt_softc *mpt) 1876147883Sscottl{ 1877147883Sscottl CONFIG_PAGE_HEADER hdr; 1878147883Sscottl struct mpt_raid_volume *mpt_raid; 1879147883Sscottl int rv; 1880147883Sscottl int i; 1881147883Sscottl size_t len; 1882147883Sscottl 1883147883Sscottl rv = mpt_read_cfg_header(mpt, MPI_CONFIG_PAGETYPE_IOC, 1884158982Smjacob 2, 0, &hdr, FALSE, 5000); 1885156104Smjacob /* 1886156104Smjacob * If it's an invalid page, so what? Not a supported function.... 1887156104Smjacob */ 1888158982Smjacob if (rv == EINVAL) { 1889156104Smjacob return (0); 1890158982Smjacob } 1891158982Smjacob if (rv) { 1892156104Smjacob return (rv); 1893158982Smjacob } 1894147883Sscottl 1895164990Smjacob mpt_lprt(mpt, MPT_PRT_DEBUG, 1896164990Smjacob "IOC Page 2 Header: Version %x len %x PageNumber %x PageType %x\n", 1897164990Smjacob hdr.PageVersion, hdr.PageLength << 2, 1898164990Smjacob hdr.PageNumber, hdr.PageType); 1899147883Sscottl 1900147883Sscottl len = hdr.PageLength * sizeof(uint32_t); 1901151075Sscottl mpt->ioc_page2 = malloc(len, M_DEVBUF, M_NOWAIT | M_ZERO); 1902158982Smjacob if (mpt->ioc_page2 == NULL) { 1903158982Smjacob mpt_prt(mpt, "unable to allocate memory for IOC page 2\n"); 1904158982Smjacob mpt_raid_free_mem(mpt); 1905147883Sscottl return (ENOMEM); 1906158982Smjacob } 1907147883Sscottl memcpy(&mpt->ioc_page2->Header, &hdr, sizeof(hdr)); 1908158982Smjacob rv = mpt_read_cur_cfg_page(mpt, 0, 1909158982Smjacob &mpt->ioc_page2->Header, len, FALSE, 5000); 1910147883Sscottl if (rv) { 1911147883Sscottl mpt_prt(mpt, "failed to read IOC Page 2\n"); 1912158982Smjacob mpt_raid_free_mem(mpt); 1913158982Smjacob return (EIO); 1914158982Smjacob } 1915164990Smjacob mpt2host_config_page_ioc2(mpt->ioc_page2); 1916158982Smjacob 1917158982Smjacob if (mpt->ioc_page2->CapabilitiesFlags != 0) { 1918147883Sscottl uint32_t mask; 1919147883Sscottl 1920147883Sscottl mpt_prt(mpt, "Capabilities: ("); 1921147883Sscottl for (mask = 1; mask != 0; mask <<= 1) { 1922158982Smjacob if ((mpt->ioc_page2->CapabilitiesFlags & mask) == 0) { 1923147883Sscottl continue; 1924158982Smjacob } 1925147883Sscottl switch (mask) { 1926147883Sscottl case MPI_IOCPAGE2_CAP_FLAGS_IS_SUPPORT: 1927147883Sscottl mpt_prtc(mpt, " RAID-0"); 1928147883Sscottl break; 1929147883Sscottl case MPI_IOCPAGE2_CAP_FLAGS_IME_SUPPORT: 1930147883Sscottl mpt_prtc(mpt, " RAID-1E"); 1931147883Sscottl break; 1932147883Sscottl case MPI_IOCPAGE2_CAP_FLAGS_IM_SUPPORT: 1933147883Sscottl mpt_prtc(mpt, " RAID-1"); 1934147883Sscottl break; 1935147883Sscottl case MPI_IOCPAGE2_CAP_FLAGS_SES_SUPPORT: 1936147883Sscottl mpt_prtc(mpt, " SES"); 1937147883Sscottl break; 1938147883Sscottl case MPI_IOCPAGE2_CAP_FLAGS_SAFTE_SUPPORT: 1939147883Sscottl mpt_prtc(mpt, " SAFTE"); 1940147883Sscottl break; 1941147883Sscottl case MPI_IOCPAGE2_CAP_FLAGS_CROSS_CHANNEL_SUPPORT: 1942147883Sscottl mpt_prtc(mpt, " Multi-Channel-Arrays"); 1943147883Sscottl default: 1944147883Sscottl break; 1945147883Sscottl } 1946102199Smjacob } 1947147883Sscottl mpt_prtc(mpt, " )\n"); 1948147883Sscottl if ((mpt->ioc_page2->CapabilitiesFlags 1949147883Sscottl & (MPI_IOCPAGE2_CAP_FLAGS_IS_SUPPORT 1950147883Sscottl | MPI_IOCPAGE2_CAP_FLAGS_IME_SUPPORT 1951147883Sscottl | MPI_IOCPAGE2_CAP_FLAGS_IM_SUPPORT)) != 0) { 1952147883Sscottl mpt_prt(mpt, "%d Active Volume%s(%d Max)\n", 1953147883Sscottl mpt->ioc_page2->NumActiveVolumes, 1954147883Sscottl mpt->ioc_page2->NumActiveVolumes != 1 1955147883Sscottl ? "s " : " ", 1956147883Sscottl mpt->ioc_page2->MaxVolumes); 1957147883Sscottl mpt_prt(mpt, "%d Hidden Drive Member%s(%d Max)\n", 1958147883Sscottl mpt->ioc_page2->NumActivePhysDisks, 1959147883Sscottl mpt->ioc_page2->NumActivePhysDisks != 1 1960147883Sscottl ? "s " : " ", 1961147883Sscottl mpt->ioc_page2->MaxPhysDisks); 1962147883Sscottl } 1963147883Sscottl } 1964102199Smjacob 1965147883Sscottl len = mpt->ioc_page2->MaxVolumes * sizeof(struct mpt_raid_volume); 1966158982Smjacob mpt->raid_volumes = malloc(len, M_DEVBUF, M_NOWAIT | M_ZERO); 1967147883Sscottl if (mpt->raid_volumes == NULL) { 1968147883Sscottl mpt_prt(mpt, "Could not allocate RAID volume data\n"); 1969158982Smjacob mpt_raid_free_mem(mpt); 1970158982Smjacob return (ENOMEM); 1971147883Sscottl } 1972147883Sscottl 1973147883Sscottl /* 1974147883Sscottl * Copy critical data out of ioc_page2 so that we can 1975147883Sscottl * safely refresh the page without windows of unreliable 1976147883Sscottl * data. 1977147883Sscottl */ 1978147883Sscottl mpt->raid_max_volumes = mpt->ioc_page2->MaxVolumes; 1979147883Sscottl 1980158982Smjacob len = sizeof(*mpt->raid_volumes->config_page) + 1981158982Smjacob (sizeof (RAID_VOL0_PHYS_DISK) * (mpt->ioc_page2->MaxPhysDisks - 1)); 1982147883Sscottl for (i = 0; i < mpt->ioc_page2->MaxVolumes; i++) { 1983147883Sscottl mpt_raid = &mpt->raid_volumes[i]; 1984158982Smjacob mpt_raid->config_page = 1985158982Smjacob malloc(len, M_DEVBUF, M_NOWAIT | M_ZERO); 1986147883Sscottl if (mpt_raid->config_page == NULL) { 1987147883Sscottl mpt_prt(mpt, "Could not allocate RAID page data\n"); 1988158982Smjacob mpt_raid_free_mem(mpt); 1989158982Smjacob return (ENOMEM); 1990147883Sscottl } 1991147883Sscottl } 1992147883Sscottl mpt->raid_page0_len = len; 1993147883Sscottl 1994147883Sscottl len = mpt->ioc_page2->MaxPhysDisks * sizeof(struct mpt_raid_disk); 1995158982Smjacob mpt->raid_disks = malloc(len, M_DEVBUF, M_NOWAIT | M_ZERO); 1996147883Sscottl if (mpt->raid_disks == NULL) { 1997147883Sscottl mpt_prt(mpt, "Could not allocate RAID disk data\n"); 1998158982Smjacob mpt_raid_free_mem(mpt); 1999158982Smjacob return (ENOMEM); 2000147883Sscottl } 2001147883Sscottl mpt->raid_max_disks = mpt->ioc_page2->MaxPhysDisks; 2002147883Sscottl 2003158982Smjacob /* 2004158982Smjacob * Load page 3. 2005158982Smjacob */ 2006147883Sscottl rv = mpt_read_cfg_header(mpt, MPI_CONFIG_PAGETYPE_IOC, 2007158982Smjacob 3, 0, &hdr, FALSE, 5000); 2008158982Smjacob if (rv) { 2009158982Smjacob mpt_raid_free_mem(mpt); 2010147883Sscottl return (EIO); 2011158982Smjacob } 2012147883Sscottl 2013147883Sscottl mpt_lprt(mpt, MPT_PRT_DEBUG, "IOC Page 3 Header: %x %x %x %x\n", 2014158982Smjacob hdr.PageVersion, hdr.PageLength, hdr.PageNumber, hdr.PageType); 2015147883Sscottl 2016147883Sscottl len = hdr.PageLength * sizeof(uint32_t); 2017151075Sscottl mpt->ioc_page3 = malloc(len, M_DEVBUF, M_NOWAIT | M_ZERO); 2018158982Smjacob if (mpt->ioc_page3 == NULL) { 2019158982Smjacob mpt_prt(mpt, "unable to allocate memory for IOC page 3\n"); 2020158982Smjacob mpt_raid_free_mem(mpt); 2021158982Smjacob return (ENOMEM); 2022158982Smjacob } 2023147883Sscottl memcpy(&mpt->ioc_page3->Header, &hdr, sizeof(hdr)); 2024158982Smjacob rv = mpt_read_cur_cfg_page(mpt, 0, 2025158982Smjacob &mpt->ioc_page3->Header, len, FALSE, 5000); 2026147883Sscottl if (rv) { 2027158982Smjacob mpt_raid_free_mem(mpt); 2028158982Smjacob return (EIO); 2029102199Smjacob } 2030186878Smarius mpt2host_config_page_ioc3(mpt->ioc_page3); 2031147883Sscottl mpt_raid_wakeup(mpt); 2032102199Smjacob return (0); 2033102199Smjacob} 2034102199Smjacob 2035102199Smjacob/* 2036102199Smjacob * Enable IOC port 2037102199Smjacob */ 2038102199Smjacobstatic int 2039147883Sscottlmpt_send_port_enable(struct mpt_softc *mpt, int port) 2040102199Smjacob{ 2041147883Sscottl request_t *req; 2042101704Smjacob MSG_PORT_ENABLE *enable_req; 2043147883Sscottl int error; 2044101704Smjacob 2045147883Sscottl req = mpt_get_request(mpt, /*sleep_ok*/FALSE); 2046147883Sscottl if (req == NULL) 2047147883Sscottl return (-1); 2048101704Smjacob 2049101704Smjacob enable_req = req->req_vbuf; 2050157354Smjacob memset(enable_req, 0, MPT_RQSL(mpt)); 2051101704Smjacob 2052101704Smjacob enable_req->Function = MPI_FUNCTION_PORT_ENABLE; 2053147883Sscottl enable_req->MsgContext = htole32(req->index | MPT_REPLY_HANDLER_CONFIG); 2054101704Smjacob enable_req->PortNumber = port; 2055101704Smjacob 2056101704Smjacob mpt_check_doorbell(mpt); 2057147883Sscottl mpt_lprt(mpt, MPT_PRT_DEBUG, "enabling port %d\n", port); 2058147883Sscottl 2059147883Sscottl mpt_send_cmd(mpt, req); 2060147883Sscottl error = mpt_wait_req(mpt, req, REQ_STATE_DONE, REQ_STATE_DONE, 2061157662Smjacob FALSE, (mpt->is_sas || mpt->is_fc)? 30000 : 3000); 2062147883Sscottl if (error != 0) { 2063157117Smjacob mpt_prt(mpt, "port %d enable timed out\n", port); 2064147883Sscottl return (-1); 2065101704Smjacob } 2066101704Smjacob mpt_free_request(mpt, req); 2067157117Smjacob mpt_lprt(mpt, MPT_PRT_DEBUG, "enabled port %d\n", port); 2068101704Smjacob return (0); 2069101704Smjacob} 2070101704Smjacob 2071101704Smjacob/* 2072101704Smjacob * Enable/Disable asynchronous event reporting. 2073101704Smjacob */ 2074101704Smjacobstatic int 2075147883Sscottlmpt_send_event_request(struct mpt_softc *mpt, int onoff) 2076101704Smjacob{ 2077101704Smjacob request_t *req; 2078101704Smjacob MSG_EVENT_NOTIFY *enable_req; 2079101704Smjacob 2080157354Smjacob req = mpt_get_request(mpt, FALSE); 2081157354Smjacob if (req == NULL) { 2082157354Smjacob return (ENOMEM); 2083157354Smjacob } 2084101704Smjacob enable_req = req->req_vbuf; 2085157354Smjacob memset(enable_req, 0, sizeof *enable_req); 2086101704Smjacob 2087101704Smjacob enable_req->Function = MPI_FUNCTION_EVENT_NOTIFICATION; 2088147883Sscottl enable_req->MsgContext = htole32(req->index | MPT_REPLY_HANDLER_EVENTS); 2089101704Smjacob enable_req->Switch = onoff; 2090101704Smjacob 2091101704Smjacob mpt_check_doorbell(mpt); 2092157354Smjacob mpt_lprt(mpt, MPT_PRT_DEBUG, "%sabling async events\n", 2093157354Smjacob onoff ? "en" : "dis"); 2094157354Smjacob /* 2095157354Smjacob * Send the command off, but don't wait for it. 2096157354Smjacob */ 2097101704Smjacob mpt_send_cmd(mpt, req); 2098101704Smjacob return (0); 2099101704Smjacob} 2100101704Smjacob 2101101704Smjacob/* 2102172568Skevlo * Un-mask the interrupts on the chip. 2103101704Smjacob */ 2104101704Smjacobvoid 2105147883Sscottlmpt_enable_ints(struct mpt_softc *mpt) 2106101704Smjacob{ 2107101704Smjacob /* Unmask every thing except door bell int */ 2108101704Smjacob mpt_write(mpt, MPT_OFFSET_INTR_MASK, MPT_INTR_DB_MASK); 2109101704Smjacob} 2110101704Smjacob 2111101704Smjacob/* 2112172568Skevlo * Mask the interrupts on the chip. 2113101704Smjacob */ 2114101704Smjacobvoid 2115147883Sscottlmpt_disable_ints(struct mpt_softc *mpt) 2116101704Smjacob{ 2117101704Smjacob /* Mask all interrupts */ 2118156104Smjacob mpt_write(mpt, MPT_OFFSET_INTR_MASK, 2119101704Smjacob MPT_INTR_REPLY_MASK | MPT_INTR_DB_MASK); 2120101704Smjacob} 2121101704Smjacob 2122147883Sscottlstatic void 2123147883Sscottlmpt_sysctl_attach(struct mpt_softc *mpt) 2124147883Sscottl{ 2125157117Smjacob#if __FreeBSD_version >= 500000 2126147883Sscottl struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(mpt->dev); 2127147883Sscottl struct sysctl_oid *tree = device_get_sysctl_tree(mpt->dev); 2128147883Sscottl 2129156104Smjacob SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, 2130147883Sscottl "debug", CTLFLAG_RW, &mpt->verbose, 0, 2131147883Sscottl "Debugging/Verbose level"); 2132160290Smjacob SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, 2133160290Smjacob "role", CTLFLAG_RD, &mpt->role, 0, 2134160290Smjacob "HBA role"); 2135165814Smjacob#ifdef MPT_TEST_MULTIPATH 2136165814Smjacob SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, 2137165814Smjacob "failure_id", CTLFLAG_RW, &mpt->failure_id, -1, 2138165814Smjacob "Next Target to Fail"); 2139157117Smjacob#endif 2140165814Smjacob#endif 2141147883Sscottl} 2142147883Sscottl 2143101704Smjacobint 2144147883Sscottlmpt_attach(struct mpt_softc *mpt) 2145101704Smjacob{ 2146157117Smjacob struct mpt_personality *pers; 2147147883Sscottl int i; 2148157117Smjacob int error; 2149147883Sscottl 2150177808Sscottl mpt_core_attach(mpt); 2151177808Sscottl mpt_core_enable(mpt); 2152177808Sscottl 2153162133Smjacob TAILQ_INSERT_TAIL(&mpt_tailq, mpt, links); 2154147883Sscottl for (i = 0; i < MPT_MAX_PERSONALITIES; i++) { 2155147883Sscottl pers = mpt_personalities[i]; 2156157117Smjacob if (pers == NULL) { 2157147883Sscottl continue; 2158157117Smjacob } 2159147883Sscottl if (pers->probe(mpt) == 0) { 2160147883Sscottl error = pers->attach(mpt); 2161147883Sscottl if (error != 0) { 2162147883Sscottl mpt_detach(mpt); 2163147883Sscottl return (error); 2164147883Sscottl } 2165147883Sscottl mpt->mpt_pers_mask |= (0x1 << pers->id); 2166147883Sscottl pers->use_count++; 2167147883Sscottl } 2168147883Sscottl } 2169155521Smjacob 2170157117Smjacob /* 2171157117Smjacob * Now that we've attached everything, do the enable function 2172157117Smjacob * for all of the personalities. This allows the personalities 2173157117Smjacob * to do setups that are appropriate for them prior to enabling 2174157117Smjacob * any ports. 2175157117Smjacob */ 2176157117Smjacob for (i = 0; i < MPT_MAX_PERSONALITIES; i++) { 2177157117Smjacob pers = mpt_personalities[i]; 2178157117Smjacob if (pers != NULL && MPT_PERS_ATTACHED(pers, mpt) != 0) { 2179157117Smjacob error = pers->enable(mpt); 2180157117Smjacob if (error != 0) { 2181157117Smjacob mpt_prt(mpt, "personality %s attached but would" 2182157117Smjacob " not enable (%d)\n", pers->name, error); 2183157117Smjacob mpt_detach(mpt); 2184157117Smjacob return (error); 2185157117Smjacob } 2186157117Smjacob } 2187157117Smjacob } 2188147883Sscottl return (0); 2189147883Sscottl} 2190147883Sscottl 2191147883Sscottlint 2192147883Sscottlmpt_shutdown(struct mpt_softc *mpt) 2193147883Sscottl{ 2194147883Sscottl struct mpt_personality *pers; 2195147883Sscottl 2196157117Smjacob MPT_PERS_FOREACH_REVERSE(mpt, pers) { 2197147883Sscottl pers->shutdown(mpt); 2198157117Smjacob } 2199147883Sscottl return (0); 2200147883Sscottl} 2201147883Sscottl 2202147883Sscottlint 2203147883Sscottlmpt_detach(struct mpt_softc *mpt) 2204147883Sscottl{ 2205147883Sscottl struct mpt_personality *pers; 2206147883Sscottl 2207147883Sscottl MPT_PERS_FOREACH_REVERSE(mpt, pers) { 2208147883Sscottl pers->detach(mpt); 2209147883Sscottl mpt->mpt_pers_mask &= ~(0x1 << pers->id); 2210147883Sscottl pers->use_count--; 2211147883Sscottl } 2212162133Smjacob TAILQ_REMOVE(&mpt_tailq, mpt, links); 2213147883Sscottl return (0); 2214147883Sscottl} 2215147883Sscottl 2216147883Sscottlint 2217147883Sscottlmpt_core_load(struct mpt_personality *pers) 2218147883Sscottl{ 2219147883Sscottl int i; 2220147883Sscottl 2221147883Sscottl /* 2222147883Sscottl * Setup core handlers and insert the default handler 2223147883Sscottl * into all "empty slots". 2224147883Sscottl */ 2225157117Smjacob for (i = 0; i < MPT_NUM_REPLY_HANDLERS; i++) { 2226147883Sscottl mpt_reply_handlers[i] = mpt_default_reply_handler; 2227157117Smjacob } 2228147883Sscottl 2229147883Sscottl mpt_reply_handlers[MPT_CBI(MPT_REPLY_HANDLER_EVENTS)] = 2230147883Sscottl mpt_event_reply_handler; 2231147883Sscottl mpt_reply_handlers[MPT_CBI(MPT_REPLY_HANDLER_CONFIG)] = 2232147883Sscottl mpt_config_reply_handler; 2233147883Sscottl mpt_reply_handlers[MPT_CBI(MPT_REPLY_HANDLER_HANDSHAKE)] = 2234147883Sscottl mpt_handshake_reply_handler; 2235147883Sscottl return (0); 2236147883Sscottl} 2237147883Sscottl 2238147883Sscottl/* 2239147883Sscottl * Initialize per-instance driver data and perform 2240147883Sscottl * initial controller configuration. 2241147883Sscottl */ 2242147883Sscottlint 2243147883Sscottlmpt_core_attach(struct mpt_softc *mpt) 2244147883Sscottl{ 2245169293Smjacob int val, error; 2246101704Smjacob 2247147883Sscottl LIST_INIT(&mpt->ack_frames); 2248147883Sscottl /* Put all request buffers on the free list */ 2249147883Sscottl TAILQ_INIT(&mpt->request_pending_list); 2250147883Sscottl TAILQ_INIT(&mpt->request_free_list); 2251157354Smjacob TAILQ_INIT(&mpt->request_timeout_list); 2252157117Smjacob for (val = 0; val < MPT_MAX_LUNS; val++) { 2253157117Smjacob STAILQ_INIT(&mpt->trt[val].atios); 2254157117Smjacob STAILQ_INIT(&mpt->trt[val].inots); 2255157117Smjacob } 2256157117Smjacob STAILQ_INIT(&mpt->trt_wildcard.atios); 2257157117Smjacob STAILQ_INIT(&mpt->trt_wildcard.inots); 2258165814Smjacob#ifdef MPT_TEST_MULTIPATH 2259165814Smjacob mpt->failure_id = -1; 2260165814Smjacob#endif 2261157117Smjacob mpt->scsi_tgt_handler_id = MPT_HANDLER_ID_NONE; 2262147883Sscottl mpt_sysctl_attach(mpt); 2263147883Sscottl mpt_lprt(mpt, MPT_PRT_DEBUG, "doorbell req = %s\n", 2264157117Smjacob mpt_ioc_diag(mpt_read(mpt, MPT_OFFSET_DOORBELL))); 2265169293Smjacob 2266169293Smjacob MPT_LOCK(mpt); 2267177881Sscottl error = mpt_configure_ioc(mpt, 0, 0); 2268169293Smjacob MPT_UNLOCK(mpt); 2269169293Smjacob 2270169293Smjacob return (error); 2271147883Sscottl} 2272147883Sscottl 2273157117Smjacobint 2274157117Smjacobmpt_core_enable(struct mpt_softc *mpt) 2275157117Smjacob{ 2276157117Smjacob /* 2277157117Smjacob * We enter with the IOC enabled, but async events 2278157117Smjacob * not enabled, ports not enabled and interrupts 2279157117Smjacob * not enabled. 2280157117Smjacob */ 2281169293Smjacob MPT_LOCK(mpt); 2282157117Smjacob 2283157117Smjacob /* 2284157117Smjacob * Enable asynchronous event reporting- all personalities 2285157117Smjacob * have attached so that they should be able to now field 2286157117Smjacob * async events. 2287157117Smjacob */ 2288157117Smjacob mpt_send_event_request(mpt, 1); 2289157117Smjacob 2290157117Smjacob /* 2291157117Smjacob * Catch any pending interrupts 2292157117Smjacob * 2293157117Smjacob * This seems to be crucial- otherwise 2294157117Smjacob * the portenable below times out. 2295157117Smjacob */ 2296157117Smjacob mpt_intr(mpt); 2297157117Smjacob 2298157117Smjacob /* 2299157117Smjacob * Enable Interrupts 2300157117Smjacob */ 2301157117Smjacob mpt_enable_ints(mpt); 2302157117Smjacob 2303157117Smjacob /* 2304157117Smjacob * Catch any pending interrupts 2305157117Smjacob * 2306157117Smjacob * This seems to be crucial- otherwise 2307157117Smjacob * the portenable below times out. 2308157117Smjacob */ 2309157117Smjacob mpt_intr(mpt); 2310157117Smjacob 2311157117Smjacob /* 2312157662Smjacob * Enable the port. 2313157117Smjacob */ 2314157117Smjacob if (mpt_send_port_enable(mpt, 0) != MPT_OK) { 2315157117Smjacob mpt_prt(mpt, "failed to enable port 0\n"); 2316169293Smjacob MPT_UNLOCK(mpt); 2317157117Smjacob return (ENXIO); 2318157117Smjacob } 2319169293Smjacob MPT_UNLOCK(mpt); 2320157117Smjacob return (0); 2321157117Smjacob} 2322157117Smjacob 2323147883Sscottlvoid 2324147883Sscottlmpt_core_shutdown(struct mpt_softc *mpt) 2325147883Sscottl{ 2326157117Smjacob mpt_disable_ints(mpt); 2327147883Sscottl} 2328147883Sscottl 2329147883Sscottlvoid 2330147883Sscottlmpt_core_detach(struct mpt_softc *mpt) 2331147883Sscottl{ 2332198262Skan int val; 2333198262Skan 2334164990Smjacob /* 2335164990Smjacob * XXX: FREE MEMORY 2336164990Smjacob */ 2337157117Smjacob mpt_disable_ints(mpt); 2338198262Skan 2339198262Skan /* Make sure no request has pending timeouts. */ 2340198262Skan for (val = 0; val < MPT_MAX_REQUESTS(mpt); val++) { 2341198262Skan request_t *req = &mpt->request_pool[val]; 2342198262Skan mpt_callout_drain(mpt, &req->callout); 2343198262Skan } 2344209599Sken 2345209599Sken mpt_dma_buf_free(mpt); 2346147883Sscottl} 2347147883Sscottl 2348147883Sscottlint 2349147883Sscottlmpt_core_unload(struct mpt_personality *pers) 2350147883Sscottl{ 2351147883Sscottl /* Unload is always successfull. */ 2352147883Sscottl return (0); 2353147883Sscottl} 2354147883Sscottl 2355147883Sscottl#define FW_UPLOAD_REQ_SIZE \ 2356147883Sscottl (sizeof(MSG_FW_UPLOAD) - sizeof(SGE_MPI_UNION) \ 2357147883Sscottl + sizeof(FW_UPLOAD_TCSGE) + sizeof(SGE_SIMPLE32)) 2358147883Sscottl 2359147883Sscottlstatic int 2360147883Sscottlmpt_upload_fw(struct mpt_softc *mpt) 2361147883Sscottl{ 2362147883Sscottl uint8_t fw_req_buf[FW_UPLOAD_REQ_SIZE]; 2363147883Sscottl MSG_FW_UPLOAD_REPLY fw_reply; 2364147883Sscottl MSG_FW_UPLOAD *fw_req; 2365147883Sscottl FW_UPLOAD_TCSGE *tsge; 2366147883Sscottl SGE_SIMPLE32 *sge; 2367147883Sscottl uint32_t flags; 2368147883Sscottl int error; 2369147883Sscottl 2370147883Sscottl memset(&fw_req_buf, 0, sizeof(fw_req_buf)); 2371147883Sscottl fw_req = (MSG_FW_UPLOAD *)fw_req_buf; 2372147883Sscottl fw_req->ImageType = MPI_FW_UPLOAD_ITYPE_FW_IOC_MEM; 2373147883Sscottl fw_req->Function = MPI_FUNCTION_FW_UPLOAD; 2374147883Sscottl fw_req->MsgContext = htole32(MPT_REPLY_HANDLER_HANDSHAKE); 2375147883Sscottl tsge = (FW_UPLOAD_TCSGE *)&fw_req->SGL; 2376147883Sscottl tsge->DetailsLength = 12; 2377147883Sscottl tsge->Flags = MPI_SGE_FLAGS_TRANSACTION_ELEMENT; 2378147883Sscottl tsge->ImageSize = htole32(mpt->fw_image_size); 2379147883Sscottl sge = (SGE_SIMPLE32 *)(tsge + 1); 2380147883Sscottl flags = (MPI_SGE_FLAGS_LAST_ELEMENT | MPI_SGE_FLAGS_END_OF_BUFFER 2381147883Sscottl | MPI_SGE_FLAGS_END_OF_LIST | MPI_SGE_FLAGS_SIMPLE_ELEMENT 2382147883Sscottl | MPI_SGE_FLAGS_32_BIT_ADDRESSING | MPI_SGE_FLAGS_IOC_TO_HOST); 2383147883Sscottl flags <<= MPI_SGE_FLAGS_SHIFT; 2384147883Sscottl sge->FlagsLength = htole32(flags | mpt->fw_image_size); 2385147883Sscottl sge->Address = htole32(mpt->fw_phys); 2386147883Sscottl error = mpt_send_handshake_cmd(mpt, sizeof(fw_req_buf), &fw_req_buf); 2387147883Sscottl if (error) 2388147883Sscottl return(error); 2389147883Sscottl error = mpt_recv_handshake_reply(mpt, sizeof(fw_reply), &fw_reply); 2390147883Sscottl return (error); 2391147883Sscottl} 2392147883Sscottl 2393147883Sscottlstatic void 2394147883Sscottlmpt_diag_outsl(struct mpt_softc *mpt, uint32_t addr, 2395147883Sscottl uint32_t *data, bus_size_t len) 2396147883Sscottl{ 2397147883Sscottl uint32_t *data_end; 2398147883Sscottl 2399147883Sscottl data_end = data + (roundup2(len, sizeof(uint32_t)) / 4); 2400159919Smjacob if (mpt->is_sas) { 2401159919Smjacob pci_enable_io(mpt->dev, SYS_RES_IOPORT); 2402159919Smjacob } 2403147883Sscottl mpt_pio_write(mpt, MPT_OFFSET_DIAG_ADDR, addr); 2404147883Sscottl while (data != data_end) { 2405147883Sscottl mpt_pio_write(mpt, MPT_OFFSET_DIAG_DATA, *data); 2406147883Sscottl data++; 2407101704Smjacob } 2408159919Smjacob if (mpt->is_sas) { 2409159919Smjacob pci_disable_io(mpt->dev, SYS_RES_IOPORT); 2410159919Smjacob } 2411147883Sscottl} 2412101704Smjacob 2413147883Sscottlstatic int 2414147883Sscottlmpt_download_fw(struct mpt_softc *mpt) 2415147883Sscottl{ 2416147883Sscottl MpiFwHeader_t *fw_hdr; 2417147883Sscottl int error; 2418147883Sscottl uint32_t ext_offset; 2419147883Sscottl uint32_t data; 2420147883Sscottl 2421147883Sscottl mpt_prt(mpt, "Downloading Firmware - Image Size %d\n", 2422147883Sscottl mpt->fw_image_size); 2423147883Sscottl 2424147883Sscottl error = mpt_enable_diag_mode(mpt); 2425147883Sscottl if (error != 0) { 2426147883Sscottl mpt_prt(mpt, "Could not enter diagnostic mode!\n"); 2427147883Sscottl return (EIO); 2428101704Smjacob } 2429101704Smjacob 2430147883Sscottl mpt_write(mpt, MPT_OFFSET_DIAGNOSTIC, 2431147883Sscottl MPI_DIAG_RW_ENABLE|MPI_DIAG_DISABLE_ARM); 2432147883Sscottl 2433147883Sscottl fw_hdr = (MpiFwHeader_t *)mpt->fw_image; 2434147883Sscottl mpt_diag_outsl(mpt, fw_hdr->LoadStartAddress, (uint32_t*)fw_hdr, 2435147883Sscottl fw_hdr->ImageSize); 2436147883Sscottl 2437147883Sscottl ext_offset = fw_hdr->NextImageHeaderOffset; 2438147883Sscottl while (ext_offset != 0) { 2439147883Sscottl MpiExtImageHeader_t *ext; 2440147883Sscottl 2441147883Sscottl ext = (MpiExtImageHeader_t *)((uintptr_t)fw_hdr + ext_offset); 2442147883Sscottl ext_offset = ext->NextImageHeaderOffset; 2443147883Sscottl 2444147883Sscottl mpt_diag_outsl(mpt, ext->LoadStartAddress, (uint32_t*)ext, 2445147883Sscottl ext->ImageSize); 2446147883Sscottl } 2447147883Sscottl 2448159919Smjacob if (mpt->is_sas) { 2449159919Smjacob pci_enable_io(mpt->dev, SYS_RES_IOPORT); 2450159919Smjacob } 2451147883Sscottl /* Setup the address to jump to on reset. */ 2452147883Sscottl mpt_pio_write(mpt, MPT_OFFSET_DIAG_ADDR, fw_hdr->IopResetRegAddr); 2453147883Sscottl mpt_pio_write(mpt, MPT_OFFSET_DIAG_DATA, fw_hdr->IopResetVectorValue); 2454147883Sscottl 2455101704Smjacob /* 2456147883Sscottl * The controller sets the "flash bad" status after attempting 2457147883Sscottl * to auto-boot from flash. Clear the status so that the controller 2458147883Sscottl * will continue the boot process with our newly installed firmware. 2459101704Smjacob */ 2460147883Sscottl mpt_pio_write(mpt, MPT_OFFSET_DIAG_ADDR, MPT_DIAG_MEM_CFG_BASE); 2461147883Sscottl data = mpt_pio_read(mpt, MPT_OFFSET_DIAG_DATA) | MPT_DIAG_MEM_CFG_BADFL; 2462147883Sscottl mpt_pio_write(mpt, MPT_OFFSET_DIAG_ADDR, MPT_DIAG_MEM_CFG_BASE); 2463147883Sscottl mpt_pio_write(mpt, MPT_OFFSET_DIAG_DATA, data); 2464147883Sscottl 2465159919Smjacob if (mpt->is_sas) { 2466159919Smjacob pci_disable_io(mpt->dev, SYS_RES_IOPORT); 2467159919Smjacob } 2468155521Smjacob 2469147883Sscottl /* 2470147883Sscottl * Re-enable the processor and clear the boot halt flag. 2471147883Sscottl */ 2472147883Sscottl data = mpt_read(mpt, MPT_OFFSET_DIAGNOSTIC); 2473147883Sscottl data &= ~(MPI_DIAG_PREVENT_IOC_BOOT|MPI_DIAG_DISABLE_ARM); 2474147883Sscottl mpt_write(mpt, MPT_OFFSET_DIAGNOSTIC, data); 2475147883Sscottl 2476147883Sscottl mpt_disable_diag_mode(mpt); 2477147883Sscottl return (0); 2478147883Sscottl} 2479147883Sscottl 2480209960Smariusstatic int 2481209599Skenmpt_dma_buf_alloc(struct mpt_softc *mpt) 2482209599Sken{ 2483209599Sken struct mpt_map_info mi; 2484209599Sken uint8_t *vptr; 2485209599Sken uint32_t pptr, end; 2486209599Sken int i, error; 2487209599Sken 2488209599Sken /* Create a child tag for data buffers */ 2489209599Sken if (mpt_dma_tag_create(mpt, mpt->parent_dmat, 1, 2490209599Sken 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, 2491209960Smarius NULL, NULL, (mpt->max_cam_seg_cnt - 1) * PAGE_SIZE, 2492209960Smarius mpt->max_cam_seg_cnt, BUS_SPACE_MAXSIZE_32BIT, 0, 2493209960Smarius &mpt->buffer_dmat) != 0) { 2494209599Sken mpt_prt(mpt, "cannot create a dma tag for data buffers\n"); 2495209599Sken return (1); 2496209599Sken } 2497209599Sken 2498209599Sken /* Create a child tag for request buffers */ 2499209599Sken if (mpt_dma_tag_create(mpt, mpt->parent_dmat, PAGE_SIZE, 0, 2500209599Sken BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, 2501209599Sken NULL, NULL, MPT_REQ_MEM_SIZE(mpt), 1, BUS_SPACE_MAXSIZE_32BIT, 0, 2502209599Sken &mpt->request_dmat) != 0) { 2503209599Sken mpt_prt(mpt, "cannot create a dma tag for requests\n"); 2504209599Sken return (1); 2505209599Sken } 2506209599Sken 2507209599Sken /* Allocate some DMA accessable memory for requests */ 2508209599Sken if (bus_dmamem_alloc(mpt->request_dmat, (void **)&mpt->request, 2509209599Sken BUS_DMA_NOWAIT, &mpt->request_dmap) != 0) { 2510209599Sken mpt_prt(mpt, "cannot allocate %d bytes of request memory\n", 2511209599Sken MPT_REQ_MEM_SIZE(mpt)); 2512209599Sken return (1); 2513209599Sken } 2514209599Sken 2515209599Sken mi.mpt = mpt; 2516209599Sken mi.error = 0; 2517209599Sken 2518209599Sken /* Load and lock it into "bus space" */ 2519209599Sken bus_dmamap_load(mpt->request_dmat, mpt->request_dmap, mpt->request, 2520209599Sken MPT_REQ_MEM_SIZE(mpt), mpt_map_rquest, &mi, 0); 2521209599Sken 2522209599Sken if (mi.error) { 2523209599Sken mpt_prt(mpt, "error %d loading dma map for DMA request queue\n", 2524209599Sken mi.error); 2525209599Sken return (1); 2526209599Sken } 2527209599Sken mpt->request_phys = mi.phys; 2528209599Sken 2529209599Sken /* 2530209599Sken * Now create per-request dma maps 2531209599Sken */ 2532209599Sken i = 0; 2533209599Sken pptr = mpt->request_phys; 2534209599Sken vptr = mpt->request; 2535209599Sken end = pptr + MPT_REQ_MEM_SIZE(mpt); 2536209599Sken while(pptr < end) { 2537209599Sken request_t *req = &mpt->request_pool[i]; 2538209599Sken req->index = i++; 2539209599Sken 2540209599Sken /* Store location of Request Data */ 2541209599Sken req->req_pbuf = pptr; 2542209599Sken req->req_vbuf = vptr; 2543209599Sken 2544209599Sken pptr += MPT_REQUEST_AREA; 2545209599Sken vptr += MPT_REQUEST_AREA; 2546209599Sken 2547209599Sken req->sense_pbuf = (pptr - MPT_SENSE_SIZE); 2548209599Sken req->sense_vbuf = (vptr - MPT_SENSE_SIZE); 2549209599Sken 2550209599Sken error = bus_dmamap_create(mpt->buffer_dmat, 0, &req->dmap); 2551209599Sken if (error) { 2552209599Sken mpt_prt(mpt, "error %d creating per-cmd DMA maps\n", 2553209599Sken error); 2554209599Sken return (1); 2555209599Sken } 2556209599Sken } 2557209599Sken 2558209599Sken return (0); 2559209599Sken} 2560209599Sken 2561209599Skenstatic void 2562209599Skenmpt_dma_buf_free(struct mpt_softc *mpt) 2563209599Sken{ 2564209599Sken int i; 2565209599Sken if (mpt->request_dmat == 0) { 2566209599Sken mpt_lprt(mpt, MPT_PRT_DEBUG, "already released dma memory\n"); 2567209599Sken return; 2568209599Sken } 2569209599Sken for (i = 0; i < MPT_MAX_REQUESTS(mpt); i++) { 2570209599Sken bus_dmamap_destroy(mpt->buffer_dmat, mpt->request_pool[i].dmap); 2571209599Sken } 2572209599Sken bus_dmamap_unload(mpt->request_dmat, mpt->request_dmap); 2573209599Sken bus_dmamem_free(mpt->request_dmat, mpt->request, mpt->request_dmap); 2574209599Sken bus_dma_tag_destroy(mpt->request_dmat); 2575209599Sken mpt->request_dmat = 0; 2576209599Sken bus_dma_tag_destroy(mpt->buffer_dmat); 2577209599Sken} 2578209599Sken 2579147883Sscottl/* 2580147883Sscottl * Allocate/Initialize data structures for the controller. Called 2581147883Sscottl * once at instance startup. 2582147883Sscottl */ 2583147883Sscottlstatic int 2584164990Smjacobmpt_configure_ioc(struct mpt_softc *mpt, int tn, int needreset) 2585147883Sscottl{ 2586164990Smjacob PTR_MSG_PORT_FACTS_REPLY pfp; 2587209599Sken int error, port, val; 2588164990Smjacob size_t len; 2589147883Sscottl 2590164990Smjacob if (tn == MPT_MAX_TRYS) { 2591164990Smjacob return (-1); 2592164990Smjacob } 2593147883Sscottl 2594164990Smjacob /* 2595164990Smjacob * No need to reset if the IOC is already in the READY state. 2596164990Smjacob * 2597164990Smjacob * Force reset if initialization failed previously. 2598164990Smjacob * Note that a hard_reset of the second channel of a '929 2599164990Smjacob * will stop operation of the first channel. Hopefully, if the 2600164990Smjacob * first channel is ok, the second will not require a hard 2601164990Smjacob * reset. 2602164990Smjacob */ 2603164990Smjacob if (needreset || MPT_STATE(mpt_rd_db(mpt)) != MPT_DB_STATE_READY) { 2604164990Smjacob if (mpt_reset(mpt, FALSE) != MPT_OK) { 2605164990Smjacob return (mpt_configure_ioc(mpt, tn++, 1)); 2606101704Smjacob } 2607147883Sscottl needreset = 0; 2608164990Smjacob } 2609101704Smjacob 2610164990Smjacob if (mpt_get_iocfacts(mpt, &mpt->ioc_facts) != MPT_OK) { 2611164990Smjacob mpt_prt(mpt, "mpt_get_iocfacts failed\n"); 2612164990Smjacob return (mpt_configure_ioc(mpt, tn++, 1)); 2613164990Smjacob } 2614164990Smjacob mpt2host_iocfacts_reply(&mpt->ioc_facts); 2615102199Smjacob 2616164990Smjacob mpt_prt(mpt, "MPI Version=%d.%d.%d.%d\n", 2617164990Smjacob mpt->ioc_facts.MsgVersion >> 8, 2618164990Smjacob mpt->ioc_facts.MsgVersion & 0xFF, 2619164990Smjacob mpt->ioc_facts.HeaderVersion >> 8, 2620164990Smjacob mpt->ioc_facts.HeaderVersion & 0xFF); 2621155521Smjacob 2622164990Smjacob /* 2623164990Smjacob * Now that we know request frame size, we can calculate 2624164990Smjacob * the actual (reasonable) segment limit for read/write I/O. 2625164990Smjacob * 2626164990Smjacob * This limit is constrained by: 2627164990Smjacob * 2628164990Smjacob * + The size of each area we allocate per command (and how 2629164990Smjacob * many chain segments we can fit into it). 2630164990Smjacob * + The total number of areas we've set up. 2631164990Smjacob * + The actual chain depth the card will allow. 2632164990Smjacob * 2633164990Smjacob * The first area's segment count is limited by the I/O request 2634164990Smjacob * at the head of it. We cannot allocate realistically more 2635164990Smjacob * than MPT_MAX_REQUESTS areas. Therefore, to account for both 2636164990Smjacob * conditions, we'll just start out with MPT_MAX_REQUESTS-2. 2637164990Smjacob * 2638164990Smjacob */ 2639164990Smjacob /* total number of request areas we (can) allocate */ 2640164990Smjacob mpt->max_seg_cnt = MPT_MAX_REQUESTS(mpt) - 2; 2641155521Smjacob 2642164990Smjacob /* converted to the number of chain areas possible */ 2643164990Smjacob mpt->max_seg_cnt *= MPT_NRFM(mpt); 2644155521Smjacob 2645164990Smjacob /* limited by the number of chain areas the card will support */ 2646164990Smjacob if (mpt->max_seg_cnt > mpt->ioc_facts.MaxChainDepth) { 2647209599Sken mpt_lprt(mpt, MPT_PRT_INFO, 2648164990Smjacob "chain depth limited to %u (from %u)\n", 2649164990Smjacob mpt->ioc_facts.MaxChainDepth, mpt->max_seg_cnt); 2650164990Smjacob mpt->max_seg_cnt = mpt->ioc_facts.MaxChainDepth; 2651164990Smjacob } 2652155521Smjacob 2653164990Smjacob /* converted to the number of simple sges in chain segments. */ 2654164990Smjacob mpt->max_seg_cnt *= (MPT_NSGL(mpt) - 1); 2655155521Smjacob 2656209599Sken /* 2657209599Sken * Use this as the basis for reporting the maximum I/O size to CAM. 2658209599Sken */ 2659209599Sken mpt->max_cam_seg_cnt = min(mpt->max_seg_cnt, (MAXPHYS / PAGE_SIZE) + 1); 2660209599Sken 2661209599Sken error = mpt_dma_buf_alloc(mpt); 2662209599Sken if (error != 0) { 2663209599Sken mpt_prt(mpt, "mpt_dma_buf_alloc() failed!\n"); 2664209599Sken return (EIO); 2665209599Sken } 2666209599Sken 2667209599Sken for (val = 0; val < MPT_MAX_REQUESTS(mpt); val++) { 2668209599Sken request_t *req = &mpt->request_pool[val]; 2669209599Sken req->state = REQ_STATE_ALLOCATED; 2670209599Sken mpt_callout_init(mpt, &req->callout); 2671209599Sken mpt_free_request(mpt, req); 2672209599Sken } 2673209599Sken 2674209599Sken mpt_lprt(mpt, MPT_PRT_INFO, "Maximum Segment Count: %u, Maximum " 2675209599Sken "CAM Segment Count: %u\n", mpt->max_seg_cnt, 2676209599Sken mpt->max_cam_seg_cnt); 2677209599Sken 2678209599Sken mpt_lprt(mpt, MPT_PRT_INFO, "MsgLength=%u IOCNumber = %d\n", 2679164990Smjacob mpt->ioc_facts.MsgLength, mpt->ioc_facts.IOCNumber); 2680209599Sken mpt_lprt(mpt, MPT_PRT_INFO, 2681164990Smjacob "IOCFACTS: GlobalCredits=%d BlockSize=%u bytes " 2682164990Smjacob "Request Frame Size %u bytes Max Chain Depth %u\n", 2683164990Smjacob mpt->ioc_facts.GlobalCredits, mpt->ioc_facts.BlockSize, 2684164990Smjacob mpt->ioc_facts.RequestFrameSize << 2, 2685164990Smjacob mpt->ioc_facts.MaxChainDepth); 2686209599Sken mpt_lprt(mpt, MPT_PRT_INFO, "IOCFACTS: Num Ports %d, FWImageSize %d, " 2687164990Smjacob "Flags=%#x\n", mpt->ioc_facts.NumberOfPorts, 2688164990Smjacob mpt->ioc_facts.FWImageSize, mpt->ioc_facts.Flags); 2689155521Smjacob 2690164990Smjacob len = mpt->ioc_facts.NumberOfPorts * sizeof (MSG_PORT_FACTS_REPLY); 2691164990Smjacob mpt->port_facts = malloc(len, M_DEVBUF, M_NOWAIT | M_ZERO); 2692164990Smjacob if (mpt->port_facts == NULL) { 2693164990Smjacob mpt_prt(mpt, "unable to allocate memory for port facts\n"); 2694164990Smjacob return (ENOMEM); 2695164990Smjacob } 2696147883Sscottl 2697155521Smjacob 2698164990Smjacob if ((mpt->ioc_facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT) && 2699164990Smjacob (mpt->fw_uploaded == 0)) { 2700164990Smjacob struct mpt_map_info mi; 2701147883Sscottl 2702164990Smjacob /* 2703164990Smjacob * In some configurations, the IOC's firmware is 2704164990Smjacob * stored in a shared piece of system NVRAM that 2705164990Smjacob * is only accessable via the BIOS. In this 2706164990Smjacob * case, the firmware keeps a copy of firmware in 2707164990Smjacob * RAM until the OS driver retrieves it. Once 2708164990Smjacob * retrieved, we are responsible for re-downloading 2709164990Smjacob * the firmware after any hard-reset. 2710164990Smjacob */ 2711164990Smjacob mpt->fw_image_size = mpt->ioc_facts.FWImageSize; 2712164990Smjacob error = mpt_dma_tag_create(mpt, mpt->parent_dmat, 1, 0, 2713164990Smjacob BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL, 2714164990Smjacob mpt->fw_image_size, 1, mpt->fw_image_size, 0, 2715164990Smjacob &mpt->fw_dmat); 2716164990Smjacob if (error != 0) { 2717164990Smjacob mpt_prt(mpt, "cannot create firmwarew dma tag\n"); 2718164990Smjacob return (ENOMEM); 2719101704Smjacob } 2720164990Smjacob error = bus_dmamem_alloc(mpt->fw_dmat, 2721164990Smjacob (void **)&mpt->fw_image, BUS_DMA_NOWAIT, &mpt->fw_dmap); 2722164990Smjacob if (error != 0) { 2723164990Smjacob mpt_prt(mpt, "cannot allocate firmware memory\n"); 2724164990Smjacob bus_dma_tag_destroy(mpt->fw_dmat); 2725164990Smjacob return (ENOMEM); 2726164990Smjacob } 2727164990Smjacob mi.mpt = mpt; 2728164990Smjacob mi.error = 0; 2729164990Smjacob bus_dmamap_load(mpt->fw_dmat, mpt->fw_dmap, 2730164990Smjacob mpt->fw_image, mpt->fw_image_size, mpt_map_rquest, &mi, 0); 2731164990Smjacob mpt->fw_phys = mi.phys; 2732101704Smjacob 2733164990Smjacob error = mpt_upload_fw(mpt); 2734164990Smjacob if (error != 0) { 2735164990Smjacob mpt_prt(mpt, "firmware upload failed.\n"); 2736164990Smjacob bus_dmamap_unload(mpt->fw_dmat, mpt->fw_dmap); 2737164990Smjacob bus_dmamem_free(mpt->fw_dmat, mpt->fw_image, 2738164990Smjacob mpt->fw_dmap); 2739164990Smjacob bus_dma_tag_destroy(mpt->fw_dmat); 2740164990Smjacob mpt->fw_image = NULL; 2741164990Smjacob return (EIO); 2742102199Smjacob } 2743164990Smjacob mpt->fw_uploaded = 1; 2744164990Smjacob } 2745102199Smjacob 2746164990Smjacob for (port = 0; port < mpt->ioc_facts.NumberOfPorts; port++) { 2747164990Smjacob pfp = &mpt->port_facts[port]; 2748164990Smjacob error = mpt_get_portfacts(mpt, 0, pfp); 2749164990Smjacob if (error != MPT_OK) { 2750164990Smjacob mpt_prt(mpt, 2751164990Smjacob "mpt_get_portfacts on port %d failed\n", port); 2752164990Smjacob free(mpt->port_facts, M_DEVBUF); 2753164990Smjacob mpt->port_facts = NULL; 2754164990Smjacob return (mpt_configure_ioc(mpt, tn++, 1)); 2755102199Smjacob } 2756164990Smjacob mpt2host_portfacts_reply(pfp); 2757157117Smjacob 2758164990Smjacob if (port > 0) { 2759164990Smjacob error = MPT_PRT_INFO; 2760102199Smjacob } else { 2761164990Smjacob error = MPT_PRT_DEBUG; 2762102199Smjacob } 2763164990Smjacob mpt_lprt(mpt, error, 2764164990Smjacob "PORTFACTS[%d]: Type %x PFlags %x IID %d MaxDev %d\n", 2765164990Smjacob port, pfp->PortType, pfp->ProtocolFlags, pfp->PortSCSIID, 2766164990Smjacob pfp->MaxDevices); 2767102199Smjacob 2768164990Smjacob } 2769157117Smjacob 2770164990Smjacob /* 2771164990Smjacob * XXX: Not yet supporting more than port 0 2772164990Smjacob */ 2773164990Smjacob pfp = &mpt->port_facts[0]; 2774164990Smjacob if (pfp->PortType == MPI_PORTFACTS_PORTTYPE_FC) { 2775164990Smjacob mpt->is_fc = 1; 2776164990Smjacob mpt->is_sas = 0; 2777164990Smjacob mpt->is_spi = 0; 2778164990Smjacob } else if (pfp->PortType == MPI_PORTFACTS_PORTTYPE_SAS) { 2779164990Smjacob mpt->is_fc = 0; 2780164990Smjacob mpt->is_sas = 1; 2781164990Smjacob mpt->is_spi = 0; 2782164990Smjacob } else if (pfp->PortType == MPI_PORTFACTS_PORTTYPE_SCSI) { 2783164990Smjacob mpt->is_fc = 0; 2784164990Smjacob mpt->is_sas = 0; 2785164990Smjacob mpt->is_spi = 1; 2786207287Smarius if (mpt->mpt_ini_id == MPT_INI_ID_NONE) 2787207287Smarius mpt->mpt_ini_id = pfp->PortSCSIID; 2788164990Smjacob } else if (pfp->PortType == MPI_PORTFACTS_PORTTYPE_ISCSI) { 2789164990Smjacob mpt_prt(mpt, "iSCSI not supported yet\n"); 2790164990Smjacob return (ENXIO); 2791164990Smjacob } else if (pfp->PortType == MPI_PORTFACTS_PORTTYPE_INACTIVE) { 2792164990Smjacob mpt_prt(mpt, "Inactive Port\n"); 2793164990Smjacob return (ENXIO); 2794164990Smjacob } else { 2795164990Smjacob mpt_prt(mpt, "unknown Port Type %#x\n", pfp->PortType); 2796164990Smjacob return (ENXIO); 2797164990Smjacob } 2798101704Smjacob 2799164990Smjacob /* 2800164990Smjacob * Set our role with what this port supports. 2801164990Smjacob * 2802164990Smjacob * Note this might be changed later in different modules 2803164990Smjacob * if this is different from what is wanted. 2804164990Smjacob */ 2805164990Smjacob mpt->role = MPT_ROLE_NONE; 2806164990Smjacob if (pfp->ProtocolFlags & MPI_PORTFACTS_PROTOCOL_INITIATOR) { 2807164990Smjacob mpt->role |= MPT_ROLE_INITIATOR; 2808101704Smjacob } 2809164990Smjacob if (pfp->ProtocolFlags & MPI_PORTFACTS_PROTOCOL_TARGET) { 2810164990Smjacob mpt->role |= MPT_ROLE_TARGET; 2811164990Smjacob } 2812101704Smjacob 2813164990Smjacob /* 2814164990Smjacob * Enable the IOC 2815164990Smjacob */ 2816177808Sscottl if (mpt_enable_ioc(mpt, 1) != MPT_OK) { 2817164990Smjacob mpt_prt(mpt, "unable to initialize IOC\n"); 2818164990Smjacob return (ENXIO); 2819101704Smjacob } 2820101704Smjacob 2821164990Smjacob /* 2822164990Smjacob * Read IOC configuration information. 2823164990Smjacob * 2824164990Smjacob * We need this to determine whether or not we have certain 2825164990Smjacob * settings for Integrated Mirroring (e.g.). 2826164990Smjacob */ 2827164990Smjacob mpt_read_config_info_ioc(mpt); 2828164990Smjacob 2829101704Smjacob return (0); 2830101704Smjacob} 2831147883Sscottl 2832147883Sscottlstatic int 2833157117Smjacobmpt_enable_ioc(struct mpt_softc *mpt, int portenable) 2834147883Sscottl{ 2835147883Sscottl uint32_t pptr; 2836147883Sscottl int val; 2837147883Sscottl 2838155521Smjacob if (mpt_send_ioc_init(mpt, MPI_WHOINIT_HOST_DRIVER) != MPT_OK) { 2839147883Sscottl mpt_prt(mpt, "mpt_send_ioc_init failed\n"); 2840147883Sscottl return (EIO); 2841147883Sscottl } 2842147883Sscottl 2843147883Sscottl mpt_lprt(mpt, MPT_PRT_DEBUG, "mpt_send_ioc_init ok\n"); 2844147883Sscottl 2845147883Sscottl if (mpt_wait_state(mpt, MPT_DB_STATE_RUNNING) != MPT_OK) { 2846147883Sscottl mpt_prt(mpt, "IOC failed to go to run state\n"); 2847147883Sscottl return (ENXIO); 2848147883Sscottl } 2849155521Smjacob mpt_lprt(mpt, MPT_PRT_DEBUG, "IOC now at RUNSTATE\n"); 2850147883Sscottl 2851147883Sscottl /* 2852147883Sscottl * Give it reply buffers 2853147883Sscottl * 2854147883Sscottl * Do *not* exceed global credits. 2855147883Sscottl */ 2856156104Smjacob for (val = 0, pptr = mpt->reply_phys; 2857156104Smjacob (pptr + MPT_REPLY_SIZE) < (mpt->reply_phys + PAGE_SIZE); 2858147883Sscottl pptr += MPT_REPLY_SIZE) { 2859147883Sscottl mpt_free_reply(mpt, pptr); 2860164990Smjacob if (++val == mpt->ioc_facts.GlobalCredits - 1) 2861147883Sscottl break; 2862147883Sscottl } 2863147883Sscottl 2864157117Smjacob 2865147883Sscottl /* 2866157354Smjacob * Enable the port if asked. This is only done if we're resetting 2867157354Smjacob * the IOC after initial startup. 2868147883Sscottl */ 2869157117Smjacob if (portenable) { 2870157117Smjacob /* 2871157117Smjacob * Enable asynchronous event reporting 2872157117Smjacob */ 2873157117Smjacob mpt_send_event_request(mpt, 1); 2874147883Sscottl 2875157117Smjacob if (mpt_send_port_enable(mpt, 0) != MPT_OK) { 2876209599Sken mpt_prt(mpt, "%s: failed to enable port 0\n", __func__); 2877157117Smjacob return (ENXIO); 2878157117Smjacob } 2879147883Sscottl } 2880156104Smjacob return (MPT_OK); 2881147883Sscottl} 2882164990Smjacob 2883164990Smjacob/* 2884164990Smjacob * Endian Conversion Functions- only used on Big Endian machines 2885164990Smjacob */ 2886164990Smjacob#if _BYTE_ORDER == _BIG_ENDIAN 2887164990Smjacobvoid 2888164990Smjacobmpt2host_sge_simple_union(SGE_SIMPLE_UNION *sge) 2889164990Smjacob{ 2890186878Smarius 2891164990Smjacob MPT_2_HOST32(sge, FlagsLength); 2892164998Smjacob MPT_2_HOST32(sge, u.Address64.Low); 2893164998Smjacob MPT_2_HOST32(sge, u.Address64.High); 2894164998Smjacob} 2895164990Smjacob 2896164990Smjacobvoid 2897164990Smjacobmpt2host_iocfacts_reply(MSG_IOC_FACTS_REPLY *rp) 2898164990Smjacob{ 2899186878Smarius 2900164990Smjacob MPT_2_HOST16(rp, MsgVersion); 2901164990Smjacob MPT_2_HOST16(rp, HeaderVersion); 2902164990Smjacob MPT_2_HOST32(rp, MsgContext); 2903164990Smjacob MPT_2_HOST16(rp, IOCExceptions); 2904164990Smjacob MPT_2_HOST16(rp, IOCStatus); 2905164990Smjacob MPT_2_HOST32(rp, IOCLogInfo); 2906164990Smjacob MPT_2_HOST16(rp, ReplyQueueDepth); 2907164990Smjacob MPT_2_HOST16(rp, RequestFrameSize); 2908164990Smjacob MPT_2_HOST16(rp, Reserved_0101_FWVersion); 2909164990Smjacob MPT_2_HOST16(rp, ProductID); 2910164990Smjacob MPT_2_HOST32(rp, CurrentHostMfaHighAddr); 2911164990Smjacob MPT_2_HOST16(rp, GlobalCredits); 2912164990Smjacob MPT_2_HOST32(rp, CurrentSenseBufferHighAddr); 2913164990Smjacob MPT_2_HOST16(rp, CurReplyFrameSize); 2914164990Smjacob MPT_2_HOST32(rp, FWImageSize); 2915164990Smjacob MPT_2_HOST32(rp, IOCCapabilities); 2916164990Smjacob MPT_2_HOST32(rp, FWVersion.Word); 2917164990Smjacob MPT_2_HOST16(rp, HighPriorityQueueDepth); 2918164990Smjacob MPT_2_HOST16(rp, Reserved2); 2919164990Smjacob mpt2host_sge_simple_union(&rp->HostPageBufferSGE); 2920164990Smjacob MPT_2_HOST32(rp, ReplyFifoHostSignalingAddr); 2921164990Smjacob} 2922164990Smjacob 2923164990Smjacobvoid 2924164990Smjacobmpt2host_portfacts_reply(MSG_PORT_FACTS_REPLY *pfp) 2925164990Smjacob{ 2926186878Smarius 2927164990Smjacob MPT_2_HOST16(pfp, Reserved); 2928164990Smjacob MPT_2_HOST16(pfp, Reserved1); 2929164990Smjacob MPT_2_HOST32(pfp, MsgContext); 2930164990Smjacob MPT_2_HOST16(pfp, Reserved2); 2931164990Smjacob MPT_2_HOST16(pfp, IOCStatus); 2932164990Smjacob MPT_2_HOST32(pfp, IOCLogInfo); 2933164990Smjacob MPT_2_HOST16(pfp, MaxDevices); 2934164990Smjacob MPT_2_HOST16(pfp, PortSCSIID); 2935164990Smjacob MPT_2_HOST16(pfp, ProtocolFlags); 2936164990Smjacob MPT_2_HOST16(pfp, MaxPostedCmdBuffers); 2937164990Smjacob MPT_2_HOST16(pfp, MaxPersistentIDs); 2938164990Smjacob MPT_2_HOST16(pfp, MaxLanBuckets); 2939164990Smjacob MPT_2_HOST16(pfp, Reserved4); 2940164990Smjacob MPT_2_HOST32(pfp, Reserved5); 2941164990Smjacob} 2942186878Smarius 2943164990Smjacobvoid 2944164990Smjacobmpt2host_config_page_ioc2(CONFIG_PAGE_IOC_2 *ioc2) 2945164990Smjacob{ 2946164990Smjacob int i; 2947186878Smarius 2948186878Smarius MPT_2_HOST32(ioc2, CapabilitiesFlags); 2949164990Smjacob for (i = 0; i < MPI_IOC_PAGE_2_RAID_VOLUME_MAX; i++) { 2950164998Smjacob MPT_2_HOST16(ioc2, RaidVolume[i].Reserved3); 2951164990Smjacob } 2952164990Smjacob} 2953164990Smjacob 2954164990Smjacobvoid 2955186878Smariusmpt2host_config_page_ioc3(CONFIG_PAGE_IOC_3 *ioc3) 2956186878Smarius{ 2957186878Smarius 2958186878Smarius MPT_2_HOST16(ioc3, Reserved2); 2959186878Smarius} 2960186878Smarius 2961186878Smariusvoid 2962186878Smariusmpt2host_config_page_scsi_port_0(CONFIG_PAGE_SCSI_PORT_0 *sp0) 2963186878Smarius{ 2964186878Smarius 2965186878Smarius MPT_2_HOST32(sp0, Capabilities); 2966186878Smarius MPT_2_HOST32(sp0, PhysicalInterface); 2967186878Smarius} 2968186878Smarius 2969186878Smariusvoid 2970186878Smariusmpt2host_config_page_scsi_port_1(CONFIG_PAGE_SCSI_PORT_1 *sp1) 2971186878Smarius{ 2972186878Smarius 2973186878Smarius MPT_2_HOST32(sp1, Configuration); 2974186878Smarius MPT_2_HOST32(sp1, OnBusTimerValue); 2975186878Smarius MPT_2_HOST16(sp1, IDConfig); 2976186878Smarius} 2977186878Smarius 2978186878Smariusvoid 2979186878Smariushost2mpt_config_page_scsi_port_1(CONFIG_PAGE_SCSI_PORT_1 *sp1) 2980186878Smarius{ 2981186878Smarius 2982186878Smarius HOST_2_MPT32(sp1, Configuration); 2983186878Smarius HOST_2_MPT32(sp1, OnBusTimerValue); 2984186878Smarius HOST_2_MPT16(sp1, IDConfig); 2985186878Smarius} 2986186878Smarius 2987186878Smariusvoid 2988186878Smariusmpt2host_config_page_scsi_port_2(CONFIG_PAGE_SCSI_PORT_2 *sp2) 2989186878Smarius{ 2990186878Smarius int i; 2991186878Smarius 2992186878Smarius MPT_2_HOST32(sp2, PortFlags); 2993186878Smarius MPT_2_HOST32(sp2, PortSettings); 2994186878Smarius for (i = 0; i < sizeof(sp2->DeviceSettings) / 2995186878Smarius sizeof(*sp2->DeviceSettings); i++) { 2996186878Smarius MPT_2_HOST16(sp2, DeviceSettings[i].DeviceFlags); 2997186878Smarius } 2998186878Smarius} 2999186878Smarius 3000186878Smariusvoid 3001186878Smariusmpt2host_config_page_scsi_device_0(CONFIG_PAGE_SCSI_DEVICE_0 *sd0) 3002186878Smarius{ 3003186878Smarius 3004186878Smarius MPT_2_HOST32(sd0, NegotiatedParameters); 3005186878Smarius MPT_2_HOST32(sd0, Information); 3006186878Smarius} 3007186878Smarius 3008186878Smariusvoid 3009186878Smariusmpt2host_config_page_scsi_device_1(CONFIG_PAGE_SCSI_DEVICE_1 *sd1) 3010186878Smarius{ 3011186878Smarius 3012186878Smarius MPT_2_HOST32(sd1, RequestedParameters); 3013186878Smarius MPT_2_HOST32(sd1, Reserved); 3014186878Smarius MPT_2_HOST32(sd1, Configuration); 3015186878Smarius} 3016186878Smarius 3017186878Smariusvoid 3018186878Smariushost2mpt_config_page_scsi_device_1(CONFIG_PAGE_SCSI_DEVICE_1 *sd1) 3019186878Smarius{ 3020186878Smarius 3021186878Smarius HOST_2_MPT32(sd1, RequestedParameters); 3022186878Smarius HOST_2_MPT32(sd1, Reserved); 3023186878Smarius HOST_2_MPT32(sd1, Configuration); 3024186878Smarius} 3025186878Smarius 3026186878Smariusvoid 3027186878Smariusmpt2host_config_page_fc_port_0(CONFIG_PAGE_FC_PORT_0 *fp0) 3028186878Smarius{ 3029186878Smarius 3030186878Smarius MPT_2_HOST32(fp0, Flags); 3031186878Smarius MPT_2_HOST32(fp0, PortIdentifier); 3032186878Smarius MPT_2_HOST32(fp0, WWNN.Low); 3033186878Smarius MPT_2_HOST32(fp0, WWNN.High); 3034186878Smarius MPT_2_HOST32(fp0, WWPN.Low); 3035186878Smarius MPT_2_HOST32(fp0, WWPN.High); 3036186878Smarius MPT_2_HOST32(fp0, SupportedServiceClass); 3037186878Smarius MPT_2_HOST32(fp0, SupportedSpeeds); 3038186878Smarius MPT_2_HOST32(fp0, CurrentSpeed); 3039186878Smarius MPT_2_HOST32(fp0, MaxFrameSize); 3040186878Smarius MPT_2_HOST32(fp0, FabricWWNN.Low); 3041186878Smarius MPT_2_HOST32(fp0, FabricWWNN.High); 3042186878Smarius MPT_2_HOST32(fp0, FabricWWPN.Low); 3043186878Smarius MPT_2_HOST32(fp0, FabricWWPN.High); 3044186878Smarius MPT_2_HOST32(fp0, DiscoveredPortsCount); 3045186878Smarius MPT_2_HOST32(fp0, MaxInitiators); 3046186878Smarius} 3047186878Smarius 3048186878Smariusvoid 3049186878Smariusmpt2host_config_page_fc_port_1(CONFIG_PAGE_FC_PORT_1 *fp1) 3050186878Smarius{ 3051186878Smarius 3052186878Smarius MPT_2_HOST32(fp1, Flags); 3053186878Smarius MPT_2_HOST32(fp1, NoSEEPROMWWNN.Low); 3054186878Smarius MPT_2_HOST32(fp1, NoSEEPROMWWNN.High); 3055186878Smarius MPT_2_HOST32(fp1, NoSEEPROMWWPN.Low); 3056186878Smarius MPT_2_HOST32(fp1, NoSEEPROMWWPN.High); 3057186878Smarius} 3058186878Smarius 3059186878Smariusvoid 3060186878Smariushost2mpt_config_page_fc_port_1(CONFIG_PAGE_FC_PORT_1 *fp1) 3061186878Smarius{ 3062186878Smarius 3063186878Smarius HOST_2_MPT32(fp1, Flags); 3064186878Smarius HOST_2_MPT32(fp1, NoSEEPROMWWNN.Low); 3065186878Smarius HOST_2_MPT32(fp1, NoSEEPROMWWNN.High); 3066186878Smarius HOST_2_MPT32(fp1, NoSEEPROMWWPN.Low); 3067186878Smarius HOST_2_MPT32(fp1, NoSEEPROMWWPN.High); 3068186878Smarius} 3069186878Smarius 3070186878Smariusvoid 3071164990Smjacobmpt2host_config_page_raid_vol_0(CONFIG_PAGE_RAID_VOL_0 *volp) 3072164990Smjacob{ 3073164990Smjacob int i; 3074186878Smarius 3075164990Smjacob MPT_2_HOST16(volp, VolumeStatus.Reserved); 3076164990Smjacob MPT_2_HOST16(volp, VolumeSettings.Settings); 3077164990Smjacob MPT_2_HOST32(volp, MaxLBA); 3078170276Sscottl MPT_2_HOST32(volp, MaxLBAHigh); 3079164990Smjacob MPT_2_HOST32(volp, StripeSize); 3080164990Smjacob MPT_2_HOST32(volp, Reserved2); 3081164990Smjacob MPT_2_HOST32(volp, Reserved3); 3082164990Smjacob for (i = 0; i < MPI_RAID_VOL_PAGE_0_PHYSDISK_MAX; i++) { 3083164998Smjacob MPT_2_HOST16(volp, PhysDisk[i].Reserved); 3084164990Smjacob } 3085164990Smjacob} 3086164990Smjacob 3087164990Smjacobvoid 3088186878Smariusmpt2host_config_page_raid_phys_disk_0(CONFIG_PAGE_RAID_PHYS_DISK_0 *rpd0) 3089186878Smarius{ 3090186878Smarius 3091186878Smarius MPT_2_HOST32(rpd0, Reserved1); 3092186878Smarius MPT_2_HOST16(rpd0, PhysDiskStatus.Reserved); 3093186878Smarius MPT_2_HOST32(rpd0, MaxLBA); 3094186878Smarius MPT_2_HOST16(rpd0, ErrorData.Reserved); 3095186878Smarius MPT_2_HOST16(rpd0, ErrorData.ErrorCount); 3096186878Smarius MPT_2_HOST16(rpd0, ErrorData.SmartCount); 3097186878Smarius} 3098186878Smarius 3099186878Smariusvoid 3100164990Smjacobmpt2host_mpi_raid_vol_indicator(MPI_RAID_VOL_INDICATOR *vi) 3101164990Smjacob{ 3102186878Smarius 3103164998Smjacob MPT_2_HOST16(vi, TotalBlocks.High); 3104164998Smjacob MPT_2_HOST16(vi, TotalBlocks.Low); 3105164998Smjacob MPT_2_HOST16(vi, BlocksRemaining.High); 3106164998Smjacob MPT_2_HOST16(vi, BlocksRemaining.Low); 3107164990Smjacob} 3108164990Smjacob#endif 3109