mpt.c revision 220945
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 220945 2011-04-22 09:59:16Z 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{ 307220945Smarius /* Load is always successful. */ 308147883Sscottl return (0); 309147883Sscottl} 310147883Sscottl 311147883Sscottlint 312147883Sscottlmpt_stdprobe(struct mpt_softc *mpt) 313147883Sscottl{ 314220945Smarius /* Probe is always successful. */ 315147883Sscottl return (0); 316147883Sscottl} 317147883Sscottl 318147883Sscottlint 319147883Sscottlmpt_stdattach(struct mpt_softc *mpt) 320147883Sscottl{ 321220945Smarius /* Attach is always successful. */ 322147883Sscottl return (0); 323147883Sscottl} 324147883Sscottl 325147883Sscottlint 326157117Smjacobmpt_stdenable(struct mpt_softc *mpt) 327157117Smjacob{ 328220945Smarius /* Enable is always successful. */ 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{ 364220945Smarius /* Unload is always successful. */ 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 662220945Smarius /* Some error occurred 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; 721219335Smarius u_int offset; 722147883Sscottl int free_rf; 723147883Sscottl 724147883Sscottl req = NULL; 725147883Sscottl reply_frame = NULL; 726147883Sscottl reply_baddr = 0; 727219335Smarius offset = 0; 728147883Sscottl if ((reply_desc & MPI_ADDRESS_REPLY_A_BIT) != 0) { 729147883Sscottl /* 730219335Smarius * Ensure that the reply frame is coherent. 731147883Sscottl */ 732157354Smjacob reply_baddr = MPT_REPLY_BADDR(reply_desc); 733147883Sscottl offset = reply_baddr - (mpt->reply_phys & 0xFFFFFFFF); 734157117Smjacob bus_dmamap_sync_range(mpt->reply_dmat, 735157117Smjacob mpt->reply_dmap, offset, MPT_REPLY_SIZE, 736157117Smjacob BUS_DMASYNC_POSTREAD); 737147883Sscottl reply_frame = MPT_REPLY_OTOV(mpt, offset); 738157117Smjacob ctxt_idx = le32toh(reply_frame->MsgContext); 739157117Smjacob } else { 740157117Smjacob uint32_t type; 741157117Smjacob 742157117Smjacob type = MPI_GET_CONTEXT_REPLY_TYPE(reply_desc); 743157117Smjacob ctxt_idx = reply_desc; 744157117Smjacob mpt_lprt(mpt, MPT_PRT_DEBUG1, "Context Reply: 0x%08x\n", 745157117Smjacob reply_desc); 746157117Smjacob 747157117Smjacob switch (type) { 748157117Smjacob case MPI_CONTEXT_REPLY_TYPE_SCSI_INIT: 749157117Smjacob ctxt_idx &= MPI_CONTEXT_REPLY_CONTEXT_MASK; 750157117Smjacob break; 751157117Smjacob case MPI_CONTEXT_REPLY_TYPE_SCSI_TARGET: 752157117Smjacob ctxt_idx = GET_IO_INDEX(reply_desc); 753157117Smjacob if (mpt->tgt_cmd_ptrs == NULL) { 754157117Smjacob mpt_prt(mpt, 755157117Smjacob "mpt_intr: no target cmd ptrs\n"); 756157117Smjacob reply_desc = MPT_REPLY_EMPTY; 757157117Smjacob break; 758157117Smjacob } 759157117Smjacob if (ctxt_idx >= mpt->tgt_cmds_allocated) { 760157117Smjacob mpt_prt(mpt, 761157117Smjacob "mpt_intr: bad tgt cmd ctxt %u\n", 762157117Smjacob ctxt_idx); 763157117Smjacob reply_desc = MPT_REPLY_EMPTY; 764157117Smjacob ntrips = 1000; 765157117Smjacob break; 766157117Smjacob } 767157117Smjacob req = mpt->tgt_cmd_ptrs[ctxt_idx]; 768157117Smjacob if (req == NULL) { 769157117Smjacob mpt_prt(mpt, "no request backpointer " 770157117Smjacob "at index %u", ctxt_idx); 771157117Smjacob reply_desc = MPT_REPLY_EMPTY; 772157117Smjacob ntrips = 1000; 773157117Smjacob break; 774157117Smjacob } 775157117Smjacob /* 776157117Smjacob * Reformulate ctxt_idx to be just as if 777157117Smjacob * it were another type of context reply 778157117Smjacob * so the code below will find the request 779157117Smjacob * via indexing into the pool. 780157117Smjacob */ 781157117Smjacob ctxt_idx = 782157117Smjacob req->index | mpt->scsi_tgt_handler_id; 783157117Smjacob req = NULL; 784157117Smjacob break; 785157117Smjacob case MPI_CONTEXT_REPLY_TYPE_LAN: 786157117Smjacob mpt_prt(mpt, "LAN CONTEXT REPLY: 0x%08x\n", 787157117Smjacob reply_desc); 788157117Smjacob reply_desc = MPT_REPLY_EMPTY; 789157117Smjacob break; 790157117Smjacob default: 791157117Smjacob mpt_prt(mpt, "Context Reply 0x%08x?\n", type); 792157117Smjacob reply_desc = MPT_REPLY_EMPTY; 793157117Smjacob break; 794157117Smjacob } 795157117Smjacob if (reply_desc == MPT_REPLY_EMPTY) { 796157117Smjacob if (ntrips++ > 1000) { 797157117Smjacob break; 798157117Smjacob } 799157117Smjacob continue; 800157117Smjacob } 801147883Sscottl } 802157117Smjacob 803157117Smjacob cb_index = MPT_CONTEXT_TO_CBI(ctxt_idx); 804157117Smjacob req_index = MPT_CONTEXT_TO_REQI(ctxt_idx); 805157117Smjacob if (req_index < MPT_MAX_REQUESTS(mpt)) { 806147883Sscottl req = &mpt->request_pool[req_index]; 807157354Smjacob } else { 808157354Smjacob mpt_prt(mpt, "WARN: mpt_intr index == %d (reply_desc ==" 809157354Smjacob " 0x%x)\n", req_index, reply_desc); 810157117Smjacob } 811147883Sscottl 812219335Smarius bus_dmamap_sync(mpt->request_dmat, mpt->request_dmap, 813219335Smarius BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); 814157117Smjacob free_rf = mpt_reply_handlers[cb_index](mpt, req, 815157117Smjacob reply_desc, reply_frame); 816147883Sscottl 817157354Smjacob if (reply_frame != NULL && free_rf) { 818219335Smarius bus_dmamap_sync_range(mpt->reply_dmat, 819219335Smarius mpt->reply_dmap, offset, MPT_REPLY_SIZE, 820219335Smarius BUS_DMASYNC_PREREAD); 821147883Sscottl mpt_free_reply(mpt, reply_baddr); 822157354Smjacob } 823157117Smjacob 824157117Smjacob /* 825157117Smjacob * If we got ourselves disabled, don't get stuck in a loop 826157117Smjacob */ 827157117Smjacob if (mpt->disabled) { 828157117Smjacob mpt_disable_ints(mpt); 829157117Smjacob break; 830157117Smjacob } 831157117Smjacob if (ntrips++ > 1000) { 832157117Smjacob break; 833157117Smjacob } 834147883Sscottl } 835157662Smjacob mpt_lprt(mpt, MPT_PRT_DEBUG2, "exit mpt_intr\n"); 836147883Sscottl} 837147883Sscottl 838147883Sscottl/******************************* Error Recovery *******************************/ 839147883Sscottlvoid 840147883Sscottlmpt_complete_request_chain(struct mpt_softc *mpt, struct req_queue *chain, 841147883Sscottl u_int iocstatus) 842147883Sscottl{ 843147883Sscottl MSG_DEFAULT_REPLY ioc_status_frame; 844147883Sscottl request_t *req; 845147883Sscottl 846157354Smjacob memset(&ioc_status_frame, 0, sizeof(ioc_status_frame)); 847147883Sscottl ioc_status_frame.MsgLength = roundup2(sizeof(ioc_status_frame), 4); 848156104Smjacob ioc_status_frame.IOCStatus = iocstatus; 849147883Sscottl while((req = TAILQ_FIRST(chain)) != NULL) { 850147883Sscottl MSG_REQUEST_HEADER *msg_hdr; 851147883Sscottl u_int cb_index; 852157354Smjacob 853219335Smarius bus_dmamap_sync(mpt->request_dmat, mpt->request_dmap, 854219335Smarius BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); 855147883Sscottl msg_hdr = (MSG_REQUEST_HEADER *)req->req_vbuf; 856156104Smjacob ioc_status_frame.Function = msg_hdr->Function; 857156104Smjacob ioc_status_frame.MsgContext = msg_hdr->MsgContext; 858147883Sscottl cb_index = MPT_CONTEXT_TO_CBI(le32toh(msg_hdr->MsgContext)); 859157117Smjacob mpt_reply_handlers[cb_index](mpt, req, msg_hdr->MsgContext, 860157117Smjacob &ioc_status_frame); 861213105Smarius if (mpt_req_on_pending_list(mpt, req) != 0) 862213105Smarius TAILQ_REMOVE(chain, req, links); 863147883Sscottl } 864147883Sscottl} 865147883Sscottl 866147883Sscottl/********************************* Diagnostics ********************************/ 867147883Sscottl/* 868147883Sscottl * Perform a diagnostic dump of a reply frame. 869147883Sscottl */ 870147883Sscottlvoid 871147883Sscottlmpt_dump_reply_frame(struct mpt_softc *mpt, MSG_DEFAULT_REPLY *reply_frame) 872147883Sscottl{ 873147883Sscottl mpt_prt(mpt, "Address Reply:\n"); 874147883Sscottl mpt_print_reply(reply_frame); 875147883Sscottl} 876147883Sscottl 877147883Sscottl/******************************* Doorbell Access ******************************/ 878147883Sscottlstatic __inline uint32_t mpt_rd_db(struct mpt_softc *mpt); 879147883Sscottlstatic __inline uint32_t mpt_rd_intr(struct mpt_softc *mpt); 880147883Sscottl 881147883Sscottlstatic __inline uint32_t 882147883Sscottlmpt_rd_db(struct mpt_softc *mpt) 883147883Sscottl{ 884101704Smjacob return mpt_read(mpt, MPT_OFFSET_DOORBELL); 885101704Smjacob} 886101704Smjacob 887147883Sscottlstatic __inline uint32_t 888147883Sscottlmpt_rd_intr(struct mpt_softc *mpt) 889101704Smjacob{ 890101704Smjacob return mpt_read(mpt, MPT_OFFSET_INTR_STATUS); 891101704Smjacob} 892101704Smjacob 893101704Smjacob/* Busy wait for a door bell to be read by IOC */ 894101704Smjacobstatic int 895147883Sscottlmpt_wait_db_ack(struct mpt_softc *mpt) 896101704Smjacob{ 897101704Smjacob int i; 898101704Smjacob for (i=0; i < MPT_MAX_WAIT; i++) { 899101704Smjacob if (!MPT_DB_IS_BUSY(mpt_rd_intr(mpt))) { 900101704Smjacob maxwait_ack = i > maxwait_ack ? i : maxwait_ack; 901157117Smjacob return (MPT_OK); 902101704Smjacob } 903157117Smjacob DELAY(200); 904101704Smjacob } 905157117Smjacob return (MPT_FAIL); 906101704Smjacob} 907101704Smjacob 908101704Smjacob/* Busy wait for a door bell interrupt */ 909101704Smjacobstatic int 910147883Sscottlmpt_wait_db_int(struct mpt_softc *mpt) 911101704Smjacob{ 912101704Smjacob int i; 913164837Smjacob for (i = 0; i < MPT_MAX_WAIT; i++) { 914101704Smjacob if (MPT_DB_INTR(mpt_rd_intr(mpt))) { 915101704Smjacob maxwait_int = i > maxwait_int ? i : maxwait_int; 916101704Smjacob return MPT_OK; 917101704Smjacob } 918101704Smjacob DELAY(100); 919101704Smjacob } 920157117Smjacob return (MPT_FAIL); 921101704Smjacob} 922101704Smjacob 923101704Smjacob/* Wait for IOC to transition to a give state */ 924101704Smjacobvoid 925147883Sscottlmpt_check_doorbell(struct mpt_softc *mpt) 926101704Smjacob{ 927147883Sscottl uint32_t db = mpt_rd_db(mpt); 928101704Smjacob if (MPT_STATE(db) != MPT_DB_STATE_RUNNING) { 929147883Sscottl mpt_prt(mpt, "Device not running\n"); 930101704Smjacob mpt_print_db(db); 931101704Smjacob } 932101704Smjacob} 933101704Smjacob 934101704Smjacob/* Wait for IOC to transition to a give state */ 935101704Smjacobstatic int 936147883Sscottlmpt_wait_state(struct mpt_softc *mpt, enum DB_STATE_BITS state) 937101704Smjacob{ 938101704Smjacob int i; 939101704Smjacob 940101704Smjacob for (i = 0; i < MPT_MAX_WAIT; i++) { 941147883Sscottl uint32_t db = mpt_rd_db(mpt); 942101704Smjacob if (MPT_STATE(db) == state) { 943101704Smjacob maxwait_state = i > maxwait_state ? i : maxwait_state; 944101704Smjacob return (MPT_OK); 945101704Smjacob } 946101704Smjacob DELAY(100); 947101704Smjacob } 948101704Smjacob return (MPT_FAIL); 949101704Smjacob} 950101704Smjacob 951101704Smjacob 952147883Sscottl/************************* Intialization/Configuration ************************/ 953147883Sscottlstatic int mpt_download_fw(struct mpt_softc *mpt); 954147883Sscottl 955101704Smjacob/* Issue the reset COMMAND to the IOC */ 956147883Sscottlstatic int 957147883Sscottlmpt_soft_reset(struct mpt_softc *mpt) 958101704Smjacob{ 959147883Sscottl mpt_lprt(mpt, MPT_PRT_DEBUG, "soft reset\n"); 960101704Smjacob 961101704Smjacob /* Have to use hard reset if we are not in Running state */ 962101704Smjacob if (MPT_STATE(mpt_rd_db(mpt)) != MPT_DB_STATE_RUNNING) { 963147883Sscottl mpt_prt(mpt, "soft reset failed: device not running\n"); 964157117Smjacob return (MPT_FAIL); 965101704Smjacob } 966101704Smjacob 967101704Smjacob /* If door bell is in use we don't have a chance of getting 968101704Smjacob * a word in since the IOC probably crashed in message 969101704Smjacob * processing. So don't waste our time. 970101704Smjacob */ 971101704Smjacob if (MPT_DB_IS_IN_USE(mpt_rd_db(mpt))) { 972147883Sscottl mpt_prt(mpt, "soft reset failed: doorbell wedged\n"); 973157117Smjacob return (MPT_FAIL); 974101704Smjacob } 975101704Smjacob 976101704Smjacob /* Send the reset request to the IOC */ 977101704Smjacob mpt_write(mpt, MPT_OFFSET_DOORBELL, 978101704Smjacob MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET << MPI_DOORBELL_FUNCTION_SHIFT); 979101704Smjacob if (mpt_wait_db_ack(mpt) != MPT_OK) { 980147883Sscottl mpt_prt(mpt, "soft reset failed: ack timeout\n"); 981157117Smjacob return (MPT_FAIL); 982101704Smjacob } 983101704Smjacob 984101704Smjacob /* Wait for the IOC to reload and come out of reset state */ 985101704Smjacob if (mpt_wait_state(mpt, MPT_DB_STATE_READY) != MPT_OK) { 986147883Sscottl mpt_prt(mpt, "soft reset failed: device did not restart\n"); 987157117Smjacob return (MPT_FAIL); 988101704Smjacob } 989101704Smjacob 990101704Smjacob return MPT_OK; 991101704Smjacob} 992101704Smjacob 993147883Sscottlstatic int 994147883Sscottlmpt_enable_diag_mode(struct mpt_softc *mpt) 995147883Sscottl{ 996147883Sscottl int try; 997147883Sscottl 998147883Sscottl try = 20; 999147883Sscottl while (--try) { 1000147883Sscottl 1001147883Sscottl if ((mpt_read(mpt, MPT_OFFSET_DIAGNOSTIC) & MPI_DIAG_DRWE) != 0) 1002147883Sscottl break; 1003147883Sscottl 1004147883Sscottl /* Enable diagnostic registers */ 1005147883Sscottl mpt_write(mpt, MPT_OFFSET_SEQUENCE, 0xFF); 1006147883Sscottl mpt_write(mpt, MPT_OFFSET_SEQUENCE, MPI_WRSEQ_1ST_KEY_VALUE); 1007147883Sscottl mpt_write(mpt, MPT_OFFSET_SEQUENCE, MPI_WRSEQ_2ND_KEY_VALUE); 1008147883Sscottl mpt_write(mpt, MPT_OFFSET_SEQUENCE, MPI_WRSEQ_3RD_KEY_VALUE); 1009147883Sscottl mpt_write(mpt, MPT_OFFSET_SEQUENCE, MPI_WRSEQ_4TH_KEY_VALUE); 1010147883Sscottl mpt_write(mpt, MPT_OFFSET_SEQUENCE, MPI_WRSEQ_5TH_KEY_VALUE); 1011147883Sscottl 1012147883Sscottl DELAY(100000); 1013147883Sscottl } 1014147883Sscottl if (try == 0) 1015147883Sscottl return (EIO); 1016147883Sscottl return (0); 1017147883Sscottl} 1018147883Sscottl 1019147883Sscottlstatic void 1020147883Sscottlmpt_disable_diag_mode(struct mpt_softc *mpt) 1021147883Sscottl{ 1022147883Sscottl mpt_write(mpt, MPT_OFFSET_SEQUENCE, 0xFFFFFFFF); 1023147883Sscottl} 1024147883Sscottl 1025101704Smjacob/* This is a magic diagnostic reset that resets all the ARM 1026156104Smjacob * processors in the chip. 1027101704Smjacob */ 1028147883Sscottlstatic void 1029147883Sscottlmpt_hard_reset(struct mpt_softc *mpt) 1030101704Smjacob{ 1031147883Sscottl int error; 1032147883Sscottl int wait; 1033147883Sscottl uint32_t diagreg; 1034147883Sscottl 1035147883Sscottl mpt_lprt(mpt, MPT_PRT_DEBUG, "hard reset\n"); 1036147883Sscottl 1037147883Sscottl error = mpt_enable_diag_mode(mpt); 1038147883Sscottl if (error) { 1039147883Sscottl mpt_prt(mpt, "WARNING - Could not enter diagnostic mode !\n"); 1040147883Sscottl mpt_prt(mpt, "Trying to reset anyway.\n"); 1041101704Smjacob } 1042101704Smjacob 1043147883Sscottl diagreg = mpt_read(mpt, MPT_OFFSET_DIAGNOSTIC); 1044101704Smjacob 1045147883Sscottl /* 1046147883Sscottl * This appears to be a workaround required for some 1047147883Sscottl * firmware or hardware revs. 1048147883Sscottl */ 1049147883Sscottl mpt_write(mpt, MPT_OFFSET_DIAGNOSTIC, diagreg | MPI_DIAG_DISABLE_ARM); 1050147883Sscottl DELAY(1000); 1051147883Sscottl 1052101704Smjacob /* Diag. port is now active so we can now hit the reset bit */ 1053147883Sscottl mpt_write(mpt, MPT_OFFSET_DIAGNOSTIC, diagreg | MPI_DIAG_RESET_ADAPTER); 1054101704Smjacob 1055147883Sscottl /* 1056147883Sscottl * Ensure that the reset has finished. We delay 1ms 1057147883Sscottl * prior to reading the register to make sure the chip 1058147883Sscottl * has sufficiently completed its reset to handle register 1059147883Sscottl * accesses. 1060147883Sscottl */ 1061147883Sscottl wait = 5000; 1062147883Sscottl do { 1063147883Sscottl DELAY(1000); 1064147883Sscottl diagreg = mpt_read(mpt, MPT_OFFSET_DIAGNOSTIC); 1065147883Sscottl } while (--wait && (diagreg & MPI_DIAG_RESET_ADAPTER) == 0); 1066101704Smjacob 1067147883Sscottl if (wait == 0) { 1068147883Sscottl mpt_prt(mpt, "WARNING - Failed hard reset! " 1069147883Sscottl "Trying to initialize anyway.\n"); 1070147883Sscottl } 1071101704Smjacob 1072147883Sscottl /* 1073147883Sscottl * If we have firmware to download, it must be loaded before 1074147883Sscottl * the controller will become operational. Do so now. 1075147883Sscottl */ 1076147883Sscottl if (mpt->fw_image != NULL) { 1077147883Sscottl 1078147883Sscottl error = mpt_download_fw(mpt); 1079147883Sscottl 1080147883Sscottl if (error) { 1081147883Sscottl mpt_prt(mpt, "WARNING - Firmware Download Failed!\n"); 1082147883Sscottl mpt_prt(mpt, "Trying to initialize anyway.\n"); 1083147883Sscottl } 1084101704Smjacob } 1085101704Smjacob 1086147883Sscottl /* 1087147883Sscottl * Reseting the controller should have disabled write 1088147883Sscottl * access to the diagnostic registers, but disable 1089147883Sscottl * manually to be sure. 1090147883Sscottl */ 1091147883Sscottl mpt_disable_diag_mode(mpt); 1092101704Smjacob} 1093101704Smjacob 1094147883Sscottlstatic void 1095147883Sscottlmpt_core_ioc_reset(struct mpt_softc *mpt, int type) 1096147883Sscottl{ 1097147883Sscottl /* 1098147883Sscottl * Complete all pending requests with a status 1099147883Sscottl * appropriate for an IOC reset. 1100147883Sscottl */ 1101147883Sscottl mpt_complete_request_chain(mpt, &mpt->request_pending_list, 1102147883Sscottl MPI_IOCSTATUS_INVALID_STATE); 1103147883Sscottl} 1104147883Sscottl 1105147883Sscottl 1106101704Smjacob/* 1107101704Smjacob * Reset the IOC when needed. Try software command first then if needed 1108101704Smjacob * poke at the magic diagnostic reset. Note that a hard reset resets 1109101704Smjacob * *both* IOCs on dual function chips (FC929 && LSI1030) as well as 1110101704Smjacob * fouls up the PCI configuration registers. 1111101704Smjacob */ 1112101704Smjacobint 1113147883Sscottlmpt_reset(struct mpt_softc *mpt, int reinit) 1114101704Smjacob{ 1115147883Sscottl struct mpt_personality *pers; 1116147883Sscottl int ret; 1117156104Smjacob int retry_cnt = 0; 1118101704Smjacob 1119156104Smjacob /* 1120156104Smjacob * Try a soft reset. If that fails, get out the big hammer. 1121156104Smjacob */ 1122156104Smjacob again: 1123101704Smjacob if ((ret = mpt_soft_reset(mpt)) != MPT_OK) { 1124156104Smjacob int cnt; 1125156104Smjacob for (cnt = 0; cnt < 5; cnt++) { 1126156104Smjacob /* Failed; do a hard reset */ 1127156104Smjacob mpt_hard_reset(mpt); 1128101704Smjacob 1129156104Smjacob /* 1130156104Smjacob * Wait for the IOC to reload 1131156104Smjacob * and come out of reset state 1132156104Smjacob */ 1133156104Smjacob ret = mpt_wait_state(mpt, MPT_DB_STATE_READY); 1134156104Smjacob if (ret == MPT_OK) { 1135156104Smjacob break; 1136156104Smjacob } 1137156104Smjacob /* 1138156104Smjacob * Okay- try to check again... 1139156104Smjacob */ 1140156104Smjacob ret = mpt_wait_state(mpt, MPT_DB_STATE_READY); 1141156104Smjacob if (ret == MPT_OK) { 1142156104Smjacob break; 1143156104Smjacob } 1144156104Smjacob mpt_prt(mpt, "mpt_reset: failed hard reset (%d:%d)\n", 1145156104Smjacob retry_cnt, cnt); 1146156104Smjacob } 1147101704Smjacob } 1148101704Smjacob 1149156104Smjacob if (retry_cnt == 0) { 1150156104Smjacob /* 1151156104Smjacob * Invoke reset handlers. We bump the reset count so 1152156104Smjacob * that mpt_wait_req() understands that regardless of 1153156104Smjacob * the specified wait condition, it should stop its wait. 1154156104Smjacob */ 1155156104Smjacob mpt->reset_cnt++; 1156156104Smjacob MPT_PERS_FOREACH(mpt, pers) 1157156104Smjacob pers->reset(mpt, ret); 1158156104Smjacob } 1159147883Sscottl 1160157354Smjacob if (reinit) { 1161157117Smjacob ret = mpt_enable_ioc(mpt, 1); 1162156104Smjacob if (ret == MPT_OK) { 1163156104Smjacob mpt_enable_ints(mpt); 1164156104Smjacob } 1165156104Smjacob } 1166156104Smjacob if (ret != MPT_OK && retry_cnt++ < 2) { 1167156104Smjacob goto again; 1168156104Smjacob } 1169101704Smjacob return ret; 1170101704Smjacob} 1171101704Smjacob 1172101704Smjacob/* Return a command buffer to the free queue */ 1173101704Smjacobvoid 1174147883Sscottlmpt_free_request(struct mpt_softc *mpt, request_t *req) 1175101704Smjacob{ 1176155521Smjacob request_t *nxt; 1177147883Sscottl struct mpt_evtf_record *record; 1178219335Smarius uint32_t offset, reply_baddr; 1179147883Sscottl 1180103871Smjacob if (req == NULL || req != &mpt->request_pool[req->index]) { 1181101704Smjacob panic("mpt_free_request bad req ptr\n"); 1182101704Smjacob return; 1183101704Smjacob } 1184155521Smjacob if ((nxt = req->chain) != NULL) { 1185155521Smjacob req->chain = NULL; 1186155521Smjacob mpt_free_request(mpt, nxt); /* NB: recursion */ 1187155521Smjacob } 1188157354Smjacob KASSERT(req->state != REQ_STATE_FREE, ("freeing free request")); 1189157354Smjacob KASSERT(!(req->state & REQ_STATE_LOCKED), ("freeing locked request")); 1190169293Smjacob MPT_LOCK_ASSERT(mpt); 1191157662Smjacob KASSERT(mpt_req_on_free_list(mpt, req) == 0, 1192157662Smjacob ("mpt_free_request: req %p:%u func %x already on freelist", 1193157662Smjacob req, req->serno, ((MSG_REQUEST_HEADER *)req->req_vbuf)->Function)); 1194157662Smjacob KASSERT(mpt_req_on_pending_list(mpt, req) == 0, 1195157662Smjacob ("mpt_free_request: req %p:%u func %x on pending list", 1196157662Smjacob req, req->serno, ((MSG_REQUEST_HEADER *)req->req_vbuf)->Function)); 1197157662Smjacob#ifdef INVARIANTS 1198157662Smjacob mpt_req_not_spcl(mpt, req, "mpt_free_request", __LINE__); 1199157662Smjacob#endif 1200157354Smjacob 1201101704Smjacob req->ccb = NULL; 1202147883Sscottl if (LIST_EMPTY(&mpt->ack_frames)) { 1203157117Smjacob /* 1204157117Smjacob * Insert free ones at the tail 1205157117Smjacob */ 1206157354Smjacob req->serno = 0; 1207157354Smjacob req->state = REQ_STATE_FREE; 1208157662Smjacob#ifdef INVARIANTS 1209157662Smjacob memset(req->req_vbuf, 0xff, sizeof (MSG_REQUEST_HEADER)); 1210157662Smjacob#endif 1211157117Smjacob TAILQ_INSERT_TAIL(&mpt->request_free_list, req, links); 1212147883Sscottl if (mpt->getreqwaiter != 0) { 1213147883Sscottl mpt->getreqwaiter = 0; 1214147883Sscottl wakeup(&mpt->request_free_list); 1215147883Sscottl } 1216147883Sscottl return; 1217147883Sscottl } 1218147883Sscottl 1219147883Sscottl /* 1220147883Sscottl * Process an ack frame deferred due to resource shortage. 1221147883Sscottl */ 1222147883Sscottl record = LIST_FIRST(&mpt->ack_frames); 1223147883Sscottl LIST_REMOVE(record, links); 1224157354Smjacob req->state = REQ_STATE_ALLOCATED; 1225157662Smjacob mpt_assign_serno(mpt, req); 1226147883Sscottl mpt_send_event_ack(mpt, req, &record->reply, record->context); 1227219335Smarius offset = (uint32_t)((uint8_t *)record - mpt->reply); 1228219335Smarius reply_baddr = offset + (mpt->reply_phys & 0xFFFFFFFF); 1229219335Smarius bus_dmamap_sync_range(mpt->reply_dmat, mpt->reply_dmap, offset, 1230219335Smarius MPT_REPLY_SIZE, BUS_DMASYNC_PREREAD); 1231147883Sscottl mpt_free_reply(mpt, reply_baddr); 1232101704Smjacob} 1233101704Smjacob 1234101704Smjacob/* Get a command buffer from the free queue */ 1235101704Smjacobrequest_t * 1236147883Sscottlmpt_get_request(struct mpt_softc *mpt, int sleep_ok) 1237101704Smjacob{ 1238101704Smjacob request_t *req; 1239147883Sscottl 1240147883Sscottlretry: 1241169293Smjacob MPT_LOCK_ASSERT(mpt); 1242147883Sscottl req = TAILQ_FIRST(&mpt->request_free_list); 1243101704Smjacob if (req != NULL) { 1244147883Sscottl KASSERT(req == &mpt->request_pool[req->index], 1245147883Sscottl ("mpt_get_request: corrupted request free list\n")); 1246157354Smjacob KASSERT(req->state == REQ_STATE_FREE, 1247157662Smjacob ("req %p:%u not free on free list %x index %d function %x", 1248157662Smjacob req, req->serno, req->state, req->index, 1249157662Smjacob ((MSG_REQUEST_HEADER *)req->req_vbuf)->Function)); 1250147883Sscottl TAILQ_REMOVE(&mpt->request_free_list, req, links); 1251147883Sscottl req->state = REQ_STATE_ALLOCATED; 1252155521Smjacob req->chain = NULL; 1253157662Smjacob mpt_assign_serno(mpt, req); 1254147883Sscottl } else if (sleep_ok != 0) { 1255147883Sscottl mpt->getreqwaiter = 1; 1256147883Sscottl mpt_sleep(mpt, &mpt->request_free_list, PUSER, "mptgreq", 0); 1257147883Sscottl goto retry; 1258101704Smjacob } 1259157354Smjacob return (req); 1260101704Smjacob} 1261101704Smjacob 1262101704Smjacob/* Pass the command to the IOC */ 1263101704Smjacobvoid 1264147883Sscottlmpt_send_cmd(struct mpt_softc *mpt, request_t *req) 1265101704Smjacob{ 1266158982Smjacob if (mpt->verbose > MPT_PRT_DEBUG2) { 1267158932Smjacob mpt_dump_request(mpt, req); 1268155521Smjacob } 1269101704Smjacob bus_dmamap_sync(mpt->request_dmat, mpt->request_dmap, 1270219335Smarius BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); 1271147883Sscottl req->state |= REQ_STATE_QUEUED; 1272157662Smjacob KASSERT(mpt_req_on_free_list(mpt, req) == 0, 1273157662Smjacob ("req %p:%u func %x on freelist list in mpt_send_cmd", 1274157662Smjacob req, req->serno, ((MSG_REQUEST_HEADER *)req->req_vbuf)->Function)); 1275157662Smjacob KASSERT(mpt_req_on_pending_list(mpt, req) == 0, 1276157662Smjacob ("req %p:%u func %x already on pending list in mpt_send_cmd", 1277157662Smjacob req, req->serno, ((MSG_REQUEST_HEADER *)req->req_vbuf)->Function)); 1278147883Sscottl TAILQ_INSERT_HEAD(&mpt->request_pending_list, req, links); 1279147883Sscottl mpt_write(mpt, MPT_OFFSET_REQUEST_Q, (uint32_t) req->req_pbuf); 1280101704Smjacob} 1281101704Smjacob 1282101704Smjacob/* 1283147883Sscottl * Wait for a request to complete. 1284147883Sscottl * 1285147883Sscottl * Inputs: 1286147883Sscottl * mpt softc of controller executing request 1287147883Sscottl * req request to wait for 1288147883Sscottl * sleep_ok nonzero implies may sleep in this context 1289147883Sscottl * time_ms timeout in ms. 0 implies no timeout. 1290147883Sscottl * 1291147883Sscottl * Return Values: 1292147883Sscottl * 0 Request completed 1293147883Sscottl * non-0 Timeout fired before request completion. 1294101704Smjacob */ 1295147883Sscottlint 1296147883Sscottlmpt_wait_req(struct mpt_softc *mpt, request_t *req, 1297147883Sscottl mpt_req_state_t state, mpt_req_state_t mask, 1298147883Sscottl int sleep_ok, int time_ms) 1299101704Smjacob{ 1300147883Sscottl int error; 1301147883Sscottl int timeout; 1302147883Sscottl u_int saved_cnt; 1303101704Smjacob 1304147883Sscottl /* 1305147883Sscottl * timeout is in ms. 0 indicates infinite wait. 1306147883Sscottl * Convert to ticks or 500us units depending on 1307147883Sscottl * our sleep mode. 1308147883Sscottl */ 1309157117Smjacob if (sleep_ok != 0) { 1310147883Sscottl timeout = (time_ms * hz) / 1000; 1311157117Smjacob } else { 1312147883Sscottl timeout = time_ms * 2; 1313157117Smjacob } 1314147883Sscottl req->state |= REQ_STATE_NEED_WAKEUP; 1315147883Sscottl mask &= ~REQ_STATE_NEED_WAKEUP; 1316155521Smjacob saved_cnt = mpt->reset_cnt; 1317157117Smjacob while ((req->state & mask) != state && mpt->reset_cnt == saved_cnt) { 1318147883Sscottl if (sleep_ok != 0) { 1319147883Sscottl error = mpt_sleep(mpt, req, PUSER, "mptreq", timeout); 1320147883Sscottl if (error == EWOULDBLOCK) { 1321147883Sscottl timeout = 0; 1322147883Sscottl break; 1323147883Sscottl } 1324147883Sscottl } else { 1325147883Sscottl if (time_ms != 0 && --timeout == 0) { 1326147883Sscottl break; 1327147883Sscottl } 1328147883Sscottl DELAY(500); 1329147883Sscottl mpt_intr(mpt); 1330147883Sscottl } 1331147883Sscottl } 1332147883Sscottl req->state &= ~REQ_STATE_NEED_WAKEUP; 1333157117Smjacob if (mpt->reset_cnt != saved_cnt) { 1334147883Sscottl return (EIO); 1335157117Smjacob } 1336157117Smjacob if (time_ms && timeout <= 0) { 1337157117Smjacob MSG_REQUEST_HEADER *msg_hdr = req->req_vbuf; 1338160396Smjacob req->state |= REQ_STATE_TIMEDOUT; 1339157117Smjacob mpt_prt(mpt, "mpt_wait_req(%x) timed out\n", msg_hdr->Function); 1340147883Sscottl return (ETIMEDOUT); 1341157117Smjacob } 1342147883Sscottl return (0); 1343101704Smjacob} 1344101704Smjacob 1345101704Smjacob/* 1346101704Smjacob * Send a command to the IOC via the handshake register. 1347101704Smjacob * 1348101704Smjacob * Only done at initialization time and for certain unusual 1349101704Smjacob * commands such as device/bus reset as specified by LSI. 1350101704Smjacob */ 1351101704Smjacobint 1352147883Sscottlmpt_send_handshake_cmd(struct mpt_softc *mpt, size_t len, void *cmd) 1353101704Smjacob{ 1354101704Smjacob int i; 1355147883Sscottl uint32_t data, *data32; 1356101704Smjacob 1357101704Smjacob /* Check condition of the IOC */ 1358101704Smjacob data = mpt_rd_db(mpt); 1359147883Sscottl if ((MPT_STATE(data) != MPT_DB_STATE_READY 1360147883Sscottl && MPT_STATE(data) != MPT_DB_STATE_RUNNING 1361147883Sscottl && MPT_STATE(data) != MPT_DB_STATE_FAULT) 1362147883Sscottl || MPT_DB_IS_IN_USE(data)) { 1363147883Sscottl mpt_prt(mpt, "handshake aborted - invalid doorbell state\n"); 1364101704Smjacob mpt_print_db(data); 1365147883Sscottl return (EBUSY); 1366101704Smjacob } 1367101704Smjacob 1368101704Smjacob /* We move things in 32 bit chunks */ 1369101704Smjacob len = (len + 3) >> 2; 1370101704Smjacob data32 = cmd; 1371101704Smjacob 1372172568Skevlo /* Clear any left over pending doorbell interrupts */ 1373101704Smjacob if (MPT_DB_INTR(mpt_rd_intr(mpt))) 1374101704Smjacob mpt_write(mpt, MPT_OFFSET_INTR_STATUS, 0); 1375101704Smjacob 1376101704Smjacob /* 1377101704Smjacob * Tell the handshake reg. we are going to send a command 1378101704Smjacob * and how long it is going to be. 1379101704Smjacob */ 1380101704Smjacob data = (MPI_FUNCTION_HANDSHAKE << MPI_DOORBELL_FUNCTION_SHIFT) | 1381101704Smjacob (len << MPI_DOORBELL_ADD_DWORDS_SHIFT); 1382101704Smjacob mpt_write(mpt, MPT_OFFSET_DOORBELL, data); 1383101704Smjacob 1384101704Smjacob /* Wait for the chip to notice */ 1385101704Smjacob if (mpt_wait_db_int(mpt) != MPT_OK) { 1386164837Smjacob mpt_prt(mpt, "mpt_send_handshake_cmd: db ignored\n"); 1387147883Sscottl return (ETIMEDOUT); 1388101704Smjacob } 1389101704Smjacob 1390101704Smjacob /* Clear the interrupt */ 1391101704Smjacob mpt_write(mpt, MPT_OFFSET_INTR_STATUS, 0); 1392101704Smjacob 1393101704Smjacob if (mpt_wait_db_ack(mpt) != MPT_OK) { 1394164837Smjacob mpt_prt(mpt, "mpt_send_handshake_cmd: db ack timed out\n"); 1395147883Sscottl return (ETIMEDOUT); 1396101704Smjacob } 1397101704Smjacob 1398101704Smjacob /* Send the command */ 1399101704Smjacob for (i = 0; i < len; i++) { 1400164315Sjb mpt_write(mpt, MPT_OFFSET_DOORBELL, htole32(*data32++)); 1401101704Smjacob if (mpt_wait_db_ack(mpt) != MPT_OK) { 1402156104Smjacob mpt_prt(mpt, 1403164837Smjacob "mpt_send_handshake_cmd: timeout @ index %d\n", i); 1404147883Sscottl return (ETIMEDOUT); 1405101704Smjacob } 1406101704Smjacob } 1407101704Smjacob return MPT_OK; 1408101704Smjacob} 1409101704Smjacob 1410101704Smjacob/* Get the response from the handshake register */ 1411101704Smjacobint 1412147883Sscottlmpt_recv_handshake_reply(struct mpt_softc *mpt, size_t reply_len, void *reply) 1413101704Smjacob{ 1414101704Smjacob int left, reply_left; 1415101704Smjacob u_int16_t *data16; 1416164315Sjb uint32_t data; 1417101704Smjacob MSG_DEFAULT_REPLY *hdr; 1418101704Smjacob 1419101704Smjacob /* We move things out in 16 bit chunks */ 1420101704Smjacob reply_len >>= 1; 1421101704Smjacob data16 = (u_int16_t *)reply; 1422101704Smjacob 1423101704Smjacob hdr = (MSG_DEFAULT_REPLY *)reply; 1424101704Smjacob 1425101704Smjacob /* Get first word */ 1426101704Smjacob if (mpt_wait_db_int(mpt) != MPT_OK) { 1427147883Sscottl mpt_prt(mpt, "mpt_recv_handshake_cmd timeout1\n"); 1428101704Smjacob return ETIMEDOUT; 1429101704Smjacob } 1430164315Sjb data = mpt_read(mpt, MPT_OFFSET_DOORBELL); 1431164315Sjb *data16++ = le16toh(data & MPT_DB_DATA_MASK); 1432101704Smjacob mpt_write(mpt, MPT_OFFSET_INTR_STATUS, 0); 1433101704Smjacob 1434101704Smjacob /* Get Second Word */ 1435101704Smjacob if (mpt_wait_db_int(mpt) != MPT_OK) { 1436147883Sscottl mpt_prt(mpt, "mpt_recv_handshake_cmd timeout2\n"); 1437101704Smjacob return ETIMEDOUT; 1438101704Smjacob } 1439164315Sjb data = mpt_read(mpt, MPT_OFFSET_DOORBELL); 1440164315Sjb *data16++ = le16toh(data & MPT_DB_DATA_MASK); 1441101704Smjacob mpt_write(mpt, MPT_OFFSET_INTR_STATUS, 0); 1442101704Smjacob 1443157354Smjacob /* 1444157354Smjacob * With the second word, we can now look at the length. 1445157354Smjacob * Warn about a reply that's too short (except for IOC FACTS REPLY) 1446157354Smjacob */ 1447157354Smjacob if ((reply_len >> 1) != hdr->MsgLength && 1448157354Smjacob (hdr->Function != MPI_FUNCTION_IOC_FACTS)){ 1449157354Smjacob#if __FreeBSD_version >= 500000 1450103914Smjacob mpt_prt(mpt, "reply length does not match message length: " 1451157382Smjacob "got %x; expected %zx for function %x\n", 1452157354Smjacob hdr->MsgLength << 2, reply_len << 1, hdr->Function); 1453157354Smjacob#else 1454157354Smjacob mpt_prt(mpt, "reply length does not match message length: " 1455157382Smjacob "got %x; expected %x for function %x\n", 1456157354Smjacob hdr->MsgLength << 2, reply_len << 1, hdr->Function); 1457157354Smjacob#endif 1458101704Smjacob } 1459101704Smjacob 1460101704Smjacob /* Get rest of the reply; but don't overflow the provided buffer */ 1461101704Smjacob left = (hdr->MsgLength << 1) - 2; 1462101704Smjacob reply_left = reply_len - 2; 1463101704Smjacob while (left--) { 1464101704Smjacob u_int16_t datum; 1465101704Smjacob 1466101704Smjacob if (mpt_wait_db_int(mpt) != MPT_OK) { 1467147883Sscottl mpt_prt(mpt, "mpt_recv_handshake_cmd timeout3\n"); 1468101704Smjacob return ETIMEDOUT; 1469101704Smjacob } 1470164315Sjb data = mpt_read(mpt, MPT_OFFSET_DOORBELL); 1471164315Sjb datum = le16toh(data & MPT_DB_DATA_MASK); 1472101704Smjacob 1473101704Smjacob if (reply_left-- > 0) 1474164315Sjb *data16++ = datum; 1475101704Smjacob 1476101704Smjacob mpt_write(mpt, MPT_OFFSET_INTR_STATUS, 0); 1477101704Smjacob } 1478101704Smjacob 1479101704Smjacob /* One more wait & clear at the end */ 1480101704Smjacob if (mpt_wait_db_int(mpt) != MPT_OK) { 1481147883Sscottl mpt_prt(mpt, "mpt_recv_handshake_cmd timeout4\n"); 1482101704Smjacob return ETIMEDOUT; 1483101704Smjacob } 1484101704Smjacob mpt_write(mpt, MPT_OFFSET_INTR_STATUS, 0); 1485101704Smjacob 1486101704Smjacob if ((hdr->IOCStatus & MPI_IOCSTATUS_MASK) != MPI_IOCSTATUS_SUCCESS) { 1487147883Sscottl if (mpt->verbose >= MPT_PRT_TRACE) 1488101704Smjacob mpt_print_reply(hdr); 1489101704Smjacob return (MPT_FAIL | hdr->IOCStatus); 1490101704Smjacob } 1491101704Smjacob 1492101704Smjacob return (0); 1493101704Smjacob} 1494101704Smjacob 1495101704Smjacobstatic int 1496147883Sscottlmpt_get_iocfacts(struct mpt_softc *mpt, MSG_IOC_FACTS_REPLY *freplp) 1497101704Smjacob{ 1498101704Smjacob MSG_IOC_FACTS f_req; 1499101704Smjacob int error; 1500101704Smjacob 1501157354Smjacob memset(&f_req, 0, sizeof f_req); 1502101704Smjacob f_req.Function = MPI_FUNCTION_IOC_FACTS; 1503147883Sscottl f_req.MsgContext = htole32(MPT_REPLY_HANDLER_HANDSHAKE); 1504101704Smjacob error = mpt_send_handshake_cmd(mpt, sizeof f_req, &f_req); 1505164990Smjacob if (error) { 1506101704Smjacob return(error); 1507164990Smjacob } 1508101704Smjacob error = mpt_recv_handshake_reply(mpt, sizeof (*freplp), freplp); 1509101704Smjacob return (error); 1510101704Smjacob} 1511101704Smjacob 1512102199Smjacobstatic int 1513164990Smjacobmpt_get_portfacts(struct mpt_softc *mpt, U8 port, MSG_PORT_FACTS_REPLY *freplp) 1514102199Smjacob{ 1515102199Smjacob MSG_PORT_FACTS f_req; 1516102199Smjacob int error; 1517102199Smjacob 1518147883Sscottl memset(&f_req, 0, sizeof f_req); 1519102199Smjacob f_req.Function = MPI_FUNCTION_PORT_FACTS; 1520164990Smjacob f_req.PortNumber = port; 1521147883Sscottl f_req.MsgContext = htole32(MPT_REPLY_HANDLER_HANDSHAKE); 1522102199Smjacob error = mpt_send_handshake_cmd(mpt, sizeof f_req, &f_req); 1523164990Smjacob if (error) { 1524102199Smjacob return(error); 1525164990Smjacob } 1526102199Smjacob error = mpt_recv_handshake_reply(mpt, sizeof (*freplp), freplp); 1527102199Smjacob return (error); 1528102199Smjacob} 1529102199Smjacob 1530101704Smjacob/* 1531101704Smjacob * Send the initialization request. This is where we specify how many 1532101704Smjacob * SCSI busses and how many devices per bus we wish to emulate. 1533101704Smjacob * This is also the command that specifies the max size of the reply 1534101704Smjacob * frames from the IOC that we will be allocating. 1535101704Smjacob */ 1536101704Smjacobstatic int 1537147883Sscottlmpt_send_ioc_init(struct mpt_softc *mpt, uint32_t who) 1538101704Smjacob{ 1539101704Smjacob int error = 0; 1540101704Smjacob MSG_IOC_INIT init; 1541101704Smjacob MSG_IOC_INIT_REPLY reply; 1542101704Smjacob 1543157354Smjacob memset(&init, 0, sizeof init); 1544101704Smjacob init.WhoInit = who; 1545101704Smjacob init.Function = MPI_FUNCTION_IOC_INIT; 1546164990Smjacob init.MaxDevices = 0; /* at least 256 devices per bus */ 1547164990Smjacob init.MaxBuses = 16; /* at least 16 busses */ 1548155521Smjacob 1549155521Smjacob init.MsgVersion = htole16(MPI_VERSION); 1550155521Smjacob init.HeaderVersion = htole16(MPI_HEADER_VERSION); 1551155521Smjacob init.ReplyFrameSize = htole16(MPT_REPLY_SIZE); 1552147883Sscottl init.MsgContext = htole32(MPT_REPLY_HANDLER_HANDSHAKE); 1553101704Smjacob 1554101704Smjacob if ((error = mpt_send_handshake_cmd(mpt, sizeof init, &init)) != 0) { 1555101704Smjacob return(error); 1556101704Smjacob } 1557101704Smjacob 1558101704Smjacob error = mpt_recv_handshake_reply(mpt, sizeof reply, &reply); 1559101704Smjacob return (error); 1560101704Smjacob} 1561101704Smjacob 1562102199Smjacob 1563102199Smjacob/* 1564102199Smjacob * Utiltity routine to read configuration headers and pages 1565102199Smjacob */ 1566147883Sscottlint 1567170252Sscottlmpt_issue_cfg_req(struct mpt_softc *mpt, request_t *req, cfgparms_t *params, 1568170252Sscottl bus_addr_t addr, bus_size_t len, int sleep_ok, int timeout_ms) 1569101704Smjacob{ 1570102199Smjacob MSG_CONFIG *cfgp; 1571147883Sscottl SGE_SIMPLE32 *se; 1572102199Smjacob 1573102199Smjacob cfgp = req->req_vbuf; 1574147883Sscottl memset(cfgp, 0, sizeof *cfgp); 1575170252Sscottl cfgp->Action = params->Action; 1576102199Smjacob cfgp->Function = MPI_FUNCTION_CONFIG; 1577170252Sscottl cfgp->Header.PageVersion = params->PageVersion; 1578170252Sscottl cfgp->Header.PageNumber = params->PageNumber; 1579170252Sscottl cfgp->PageAddress = htole32(params->PageAddress); 1580170252Sscottl if ((params->PageType & MPI_CONFIG_PAGETYPE_MASK) == 1581170252Sscottl MPI_CONFIG_PAGETYPE_EXTENDED) { 1582170252Sscottl cfgp->Header.PageType = MPI_CONFIG_PAGETYPE_EXTENDED; 1583170252Sscottl cfgp->Header.PageLength = 0; 1584170252Sscottl cfgp->ExtPageLength = htole16(params->ExtPageLength); 1585170252Sscottl cfgp->ExtPageType = params->ExtPageType; 1586170252Sscottl } else { 1587170252Sscottl cfgp->Header.PageType = params->PageType; 1588170252Sscottl cfgp->Header.PageLength = params->PageLength; 1589170252Sscottl } 1590147883Sscottl se = (SGE_SIMPLE32 *)&cfgp->PageBufferSGE; 1591164315Sjb se->Address = htole32(addr); 1592147883Sscottl MPI_pSGE_SET_LENGTH(se, len); 1593147883Sscottl MPI_pSGE_SET_FLAGS(se, (MPI_SGE_FLAGS_SIMPLE_ELEMENT | 1594147883Sscottl MPI_SGE_FLAGS_LAST_ELEMENT | MPI_SGE_FLAGS_END_OF_BUFFER | 1595147883Sscottl MPI_SGE_FLAGS_END_OF_LIST | 1596170252Sscottl ((params->Action == MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT 1597170252Sscottl || params->Action == MPI_CONFIG_ACTION_PAGE_WRITE_NVRAM) 1598147883Sscottl ? MPI_SGE_FLAGS_HOST_TO_IOC : MPI_SGE_FLAGS_IOC_TO_HOST))); 1599164315Sjb se->FlagsLength = htole32(se->FlagsLength); 1600147883Sscottl cfgp->MsgContext = htole32(req->index | MPT_REPLY_HANDLER_CONFIG); 1601102199Smjacob 1602102199Smjacob mpt_check_doorbell(mpt); 1603102199Smjacob mpt_send_cmd(mpt, req); 1604147883Sscottl return (mpt_wait_req(mpt, req, REQ_STATE_DONE, REQ_STATE_DONE, 1605147883Sscottl sleep_ok, timeout_ms)); 1606147883Sscottl} 1607102199Smjacob 1608170252Sscottlint 1609170252Sscottlmpt_read_extcfg_header(struct mpt_softc *mpt, int PageVersion, int PageNumber, 1610170252Sscottl uint32_t PageAddress, int ExtPageType, 1611170252Sscottl CONFIG_EXTENDED_PAGE_HEADER *rslt, 1612170252Sscottl int sleep_ok, int timeout_ms) 1613170252Sscottl{ 1614170252Sscottl request_t *req; 1615170252Sscottl cfgparms_t params; 1616170252Sscottl MSG_CONFIG_REPLY *cfgp; 1617170252Sscottl int error; 1618147883Sscottl 1619170252Sscottl req = mpt_get_request(mpt, sleep_ok); 1620170252Sscottl if (req == NULL) { 1621170252Sscottl mpt_prt(mpt, "mpt_extread_cfg_header: Get request failed!\n"); 1622170252Sscottl return (ENOMEM); 1623170252Sscottl } 1624170252Sscottl 1625170252Sscottl params.Action = MPI_CONFIG_ACTION_PAGE_HEADER; 1626170252Sscottl params.PageVersion = PageVersion; 1627170252Sscottl params.PageLength = 0; 1628170252Sscottl params.PageNumber = PageNumber; 1629170252Sscottl params.PageType = MPI_CONFIG_PAGETYPE_EXTENDED; 1630170252Sscottl params.PageAddress = PageAddress; 1631170252Sscottl params.ExtPageType = ExtPageType; 1632170252Sscottl params.ExtPageLength = 0; 1633170252Sscottl error = mpt_issue_cfg_req(mpt, req, ¶ms, /*addr*/0, /*len*/0, 1634170252Sscottl sleep_ok, timeout_ms); 1635170252Sscottl if (error != 0) { 1636170252Sscottl /* 1637170252Sscottl * Leave the request. Without resetting the chip, it's 1638170252Sscottl * still owned by it and we'll just get into trouble 1639170252Sscottl * freeing it now. Mark it as abandoned so that if it 1640170252Sscottl * shows up later it can be freed. 1641170252Sscottl */ 1642170252Sscottl mpt_prt(mpt, "read_extcfg_header timed out\n"); 1643170252Sscottl return (ETIMEDOUT); 1644170252Sscottl } 1645170252Sscottl 1646170252Sscottl switch (req->IOCStatus & MPI_IOCSTATUS_MASK) { 1647170252Sscottl case MPI_IOCSTATUS_SUCCESS: 1648170252Sscottl cfgp = req->req_vbuf; 1649170252Sscottl rslt->PageVersion = cfgp->Header.PageVersion; 1650170252Sscottl rslt->PageNumber = cfgp->Header.PageNumber; 1651170252Sscottl rslt->PageType = cfgp->Header.PageType; 1652186878Smarius rslt->ExtPageLength = le16toh(cfgp->ExtPageLength); 1653170252Sscottl rslt->ExtPageType = cfgp->ExtPageType; 1654170252Sscottl error = 0; 1655170252Sscottl break; 1656170252Sscottl case MPI_IOCSTATUS_CONFIG_INVALID_PAGE: 1657170252Sscottl mpt_lprt(mpt, MPT_PRT_DEBUG, 1658170252Sscottl "Invalid Page Type %d Number %d Addr 0x%0x\n", 1659170252Sscottl MPI_CONFIG_PAGETYPE_EXTENDED, PageNumber, PageAddress); 1660170252Sscottl error = EINVAL; 1661170252Sscottl break; 1662170252Sscottl default: 1663170252Sscottl mpt_prt(mpt, "mpt_read_extcfg_header: Config Info Status %x\n", 1664170252Sscottl req->IOCStatus); 1665170252Sscottl error = EIO; 1666170252Sscottl break; 1667170252Sscottl } 1668170252Sscottl mpt_free_request(mpt, req); 1669170252Sscottl return (error); 1670170252Sscottl} 1671170252Sscottl 1672147883Sscottlint 1673170252Sscottlmpt_read_extcfg_page(struct mpt_softc *mpt, int Action, uint32_t PageAddress, 1674170252Sscottl CONFIG_EXTENDED_PAGE_HEADER *hdr, void *buf, size_t len, 1675170252Sscottl int sleep_ok, int timeout_ms) 1676170252Sscottl{ 1677170252Sscottl request_t *req; 1678170252Sscottl cfgparms_t params; 1679170252Sscottl int error; 1680170252Sscottl 1681170252Sscottl req = mpt_get_request(mpt, sleep_ok); 1682170252Sscottl if (req == NULL) { 1683186878Smarius mpt_prt(mpt, "mpt_read_extcfg_page: Get request failed!\n"); 1684170252Sscottl return (-1); 1685170252Sscottl } 1686170252Sscottl 1687170252Sscottl params.Action = Action; 1688170252Sscottl params.PageVersion = hdr->PageVersion; 1689170252Sscottl params.PageLength = 0; 1690170252Sscottl params.PageNumber = hdr->PageNumber; 1691170252Sscottl params.PageType = MPI_CONFIG_PAGETYPE_EXTENDED; 1692170252Sscottl params.PageAddress = PageAddress; 1693170252Sscottl params.ExtPageType = hdr->ExtPageType; 1694170252Sscottl params.ExtPageLength = hdr->ExtPageLength; 1695170252Sscottl error = mpt_issue_cfg_req(mpt, req, ¶ms, 1696170252Sscottl req->req_pbuf + MPT_RQSL(mpt), 1697170252Sscottl len, sleep_ok, timeout_ms); 1698170252Sscottl if (error != 0) { 1699170252Sscottl mpt_prt(mpt, "read_extcfg_page(%d) timed out\n", Action); 1700170252Sscottl return (-1); 1701170252Sscottl } 1702170252Sscottl 1703170252Sscottl if ((req->IOCStatus & MPI_IOCSTATUS_MASK) != MPI_IOCSTATUS_SUCCESS) { 1704170252Sscottl mpt_prt(mpt, "mpt_read_extcfg_page: Config Info Status %x\n", 1705170252Sscottl req->IOCStatus); 1706170252Sscottl mpt_free_request(mpt, req); 1707170252Sscottl return (-1); 1708170252Sscottl } 1709170252Sscottl memcpy(buf, ((uint8_t *)req->req_vbuf)+MPT_RQSL(mpt), len); 1710170252Sscottl mpt_free_request(mpt, req); 1711170252Sscottl return (0); 1712170252Sscottl} 1713170252Sscottl 1714170252Sscottlint 1715147883Sscottlmpt_read_cfg_header(struct mpt_softc *mpt, int PageType, int PageNumber, 1716147883Sscottl uint32_t PageAddress, CONFIG_PAGE_HEADER *rslt, 1717147883Sscottl int sleep_ok, int timeout_ms) 1718147883Sscottl{ 1719147883Sscottl request_t *req; 1720170252Sscottl cfgparms_t params; 1721156104Smjacob MSG_CONFIG *cfgp; 1722147883Sscottl int error; 1723147883Sscottl 1724147883Sscottl req = mpt_get_request(mpt, sleep_ok); 1725147883Sscottl if (req == NULL) { 1726147883Sscottl mpt_prt(mpt, "mpt_read_cfg_header: Get request failed!\n"); 1727156104Smjacob return (ENOMEM); 1728102199Smjacob } 1729147883Sscottl 1730170252Sscottl params.Action = MPI_CONFIG_ACTION_PAGE_HEADER; 1731170252Sscottl params.PageVersion = 0; 1732170252Sscottl params.PageLength = 0; 1733170252Sscottl params.PageNumber = PageNumber; 1734170252Sscottl params.PageType = PageType; 1735170252Sscottl params.PageAddress = PageAddress; 1736170252Sscottl error = mpt_issue_cfg_req(mpt, req, ¶ms, /*addr*/0, /*len*/0, 1737147883Sscottl sleep_ok, timeout_ms); 1738147883Sscottl if (error != 0) { 1739160396Smjacob /* 1740160396Smjacob * Leave the request. Without resetting the chip, it's 1741160396Smjacob * still owned by it and we'll just get into trouble 1742160396Smjacob * freeing it now. Mark it as abandoned so that if it 1743160396Smjacob * shows up later it can be freed. 1744160396Smjacob */ 1745147883Sscottl mpt_prt(mpt, "read_cfg_header timed out\n"); 1746156104Smjacob return (ETIMEDOUT); 1747147883Sscottl } 1748147883Sscottl 1749156104Smjacob switch (req->IOCStatus & MPI_IOCSTATUS_MASK) { 1750156104Smjacob case MPI_IOCSTATUS_SUCCESS: 1751147883Sscottl cfgp = req->req_vbuf; 1752147883Sscottl bcopy(&cfgp->Header, rslt, sizeof(*rslt)); 1753147883Sscottl error = 0; 1754156104Smjacob break; 1755156104Smjacob case MPI_IOCSTATUS_CONFIG_INVALID_PAGE: 1756156104Smjacob mpt_lprt(mpt, MPT_PRT_DEBUG, 1757156104Smjacob "Invalid Page Type %d Number %d Addr 0x%0x\n", 1758156104Smjacob PageType, PageNumber, PageAddress); 1759156104Smjacob error = EINVAL; 1760156104Smjacob break; 1761156104Smjacob default: 1762156104Smjacob mpt_prt(mpt, "mpt_read_cfg_header: Config Info Status %x\n", 1763156104Smjacob req->IOCStatus); 1764156104Smjacob error = EIO; 1765156104Smjacob break; 1766147883Sscottl } 1767102199Smjacob mpt_free_request(mpt, req); 1768147883Sscottl return (error); 1769102199Smjacob} 1770102199Smjacob 1771102822Smjacobint 1772147883Sscottlmpt_read_cfg_page(struct mpt_softc *mpt, int Action, uint32_t PageAddress, 1773147883Sscottl CONFIG_PAGE_HEADER *hdr, size_t len, int sleep_ok, 1774147883Sscottl int timeout_ms) 1775102199Smjacob{ 1776147883Sscottl request_t *req; 1777170252Sscottl cfgparms_t params; 1778147883Sscottl int error; 1779102199Smjacob 1780147883Sscottl req = mpt_get_request(mpt, sleep_ok); 1781147883Sscottl if (req == NULL) { 1782147883Sscottl mpt_prt(mpt, "mpt_read_cfg_page: Get request failed!\n"); 1783147883Sscottl return (-1); 1784147883Sscottl } 1785102199Smjacob 1786170252Sscottl params.Action = Action; 1787170252Sscottl params.PageVersion = hdr->PageVersion; 1788170252Sscottl params.PageLength = hdr->PageLength; 1789170252Sscottl params.PageNumber = hdr->PageNumber; 1790170252Sscottl params.PageType = hdr->PageType & MPI_CONFIG_PAGETYPE_MASK; 1791170252Sscottl params.PageAddress = PageAddress; 1792170252Sscottl error = mpt_issue_cfg_req(mpt, req, ¶ms, 1793170252Sscottl req->req_pbuf + MPT_RQSL(mpt), 1794147883Sscottl len, sleep_ok, timeout_ms); 1795147883Sscottl if (error != 0) { 1796147883Sscottl mpt_prt(mpt, "read_cfg_page(%d) timed out\n", Action); 1797147883Sscottl return (-1); 1798147883Sscottl } 1799102199Smjacob 1800147883Sscottl if ((req->IOCStatus & MPI_IOCSTATUS_MASK) != MPI_IOCSTATUS_SUCCESS) { 1801147883Sscottl mpt_prt(mpt, "mpt_read_cfg_page: Config Info Status %x\n", 1802147883Sscottl req->IOCStatus); 1803147883Sscottl mpt_free_request(mpt, req); 1804102199Smjacob return (-1); 1805102199Smjacob } 1806157117Smjacob memcpy(hdr, ((uint8_t *)req->req_vbuf)+MPT_RQSL(mpt), len); 1807102199Smjacob mpt_free_request(mpt, req); 1808102199Smjacob return (0); 1809102199Smjacob} 1810102199Smjacob 1811102822Smjacobint 1812147883Sscottlmpt_write_cfg_page(struct mpt_softc *mpt, int Action, uint32_t PageAddress, 1813147883Sscottl CONFIG_PAGE_HEADER *hdr, size_t len, int sleep_ok, 1814147883Sscottl int timeout_ms) 1815102199Smjacob{ 1816147883Sscottl request_t *req; 1817170252Sscottl cfgparms_t params; 1818147883Sscottl u_int hdr_attr; 1819147883Sscottl int error; 1820102199Smjacob 1821102199Smjacob hdr_attr = hdr->PageType & MPI_CONFIG_PAGEATTR_MASK; 1822102199Smjacob if (hdr_attr != MPI_CONFIG_PAGEATTR_CHANGEABLE && 1823102199Smjacob hdr_attr != MPI_CONFIG_PAGEATTR_PERSISTENT) { 1824147883Sscottl mpt_prt(mpt, "page type 0x%x not changeable\n", 1825147883Sscottl hdr->PageType & MPI_CONFIG_PAGETYPE_MASK); 1826102199Smjacob return (-1); 1827102199Smjacob } 1828102199Smjacob 1829160290Smjacob#if 0 1830160290Smjacob /* 1831160290Smjacob * We shouldn't mask off other bits here. 1832160290Smjacob */ 1833160290Smjacob hdr->PageType &= MPI_CONFIG_PAGETYPE_MASK; 1834160290Smjacob#endif 1835160290Smjacob 1836147883Sscottl req = mpt_get_request(mpt, sleep_ok); 1837147883Sscottl if (req == NULL) 1838147883Sscottl return (-1); 1839102199Smjacob 1840160290Smjacob memcpy(((caddr_t)req->req_vbuf) + MPT_RQSL(mpt), hdr, len); 1841160290Smjacob 1842160290Smjacob /* 1843160290Smjacob * There isn't any point in restoring stripped out attributes 1844160290Smjacob * if you then mask them going down to issue the request. 1845160290Smjacob */ 1846160290Smjacob 1847170252Sscottl params.Action = Action; 1848170252Sscottl params.PageVersion = hdr->PageVersion; 1849170252Sscottl params.PageLength = hdr->PageLength; 1850170252Sscottl params.PageNumber = hdr->PageNumber; 1851170252Sscottl params.PageAddress = PageAddress; 1852160290Smjacob#if 0 1853147883Sscottl /* Restore stripped out attributes */ 1854147883Sscottl hdr->PageType |= hdr_attr; 1855170252Sscottl params.PageType = hdr->PageType & MPI_CONFIG_PAGETYPE_MASK; 1856160290Smjacob#else 1857170252Sscottl params.PageType = hdr->PageType; 1858170252Sscottl#endif 1859170252Sscottl error = mpt_issue_cfg_req(mpt, req, ¶ms, 1860160290Smjacob req->req_pbuf + MPT_RQSL(mpt), 1861160290Smjacob len, sleep_ok, timeout_ms); 1862147883Sscottl if (error != 0) { 1863147883Sscottl mpt_prt(mpt, "mpt_write_cfg_page timed out\n"); 1864147883Sscottl return (-1); 1865147883Sscottl } 1866102199Smjacob 1867147883Sscottl if ((req->IOCStatus & MPI_IOCSTATUS_MASK) != MPI_IOCSTATUS_SUCCESS) { 1868147883Sscottl mpt_prt(mpt, "mpt_write_cfg_page: Config Info Status %x\n", 1869147883Sscottl req->IOCStatus); 1870147883Sscottl mpt_free_request(mpt, req); 1871147883Sscottl return (-1); 1872102199Smjacob } 1873147883Sscottl mpt_free_request(mpt, req); 1874147883Sscottl return (0); 1875147883Sscottl} 1876102199Smjacob 1877147883Sscottl/* 1878147883Sscottl * Read IOC configuration information 1879147883Sscottl */ 1880147883Sscottlstatic int 1881147883Sscottlmpt_read_config_info_ioc(struct mpt_softc *mpt) 1882147883Sscottl{ 1883147883Sscottl CONFIG_PAGE_HEADER hdr; 1884147883Sscottl struct mpt_raid_volume *mpt_raid; 1885147883Sscottl int rv; 1886147883Sscottl int i; 1887147883Sscottl size_t len; 1888147883Sscottl 1889147883Sscottl rv = mpt_read_cfg_header(mpt, MPI_CONFIG_PAGETYPE_IOC, 1890158982Smjacob 2, 0, &hdr, FALSE, 5000); 1891156104Smjacob /* 1892156104Smjacob * If it's an invalid page, so what? Not a supported function.... 1893156104Smjacob */ 1894158982Smjacob if (rv == EINVAL) { 1895156104Smjacob return (0); 1896158982Smjacob } 1897158982Smjacob if (rv) { 1898156104Smjacob return (rv); 1899158982Smjacob } 1900147883Sscottl 1901164990Smjacob mpt_lprt(mpt, MPT_PRT_DEBUG, 1902164990Smjacob "IOC Page 2 Header: Version %x len %x PageNumber %x PageType %x\n", 1903164990Smjacob hdr.PageVersion, hdr.PageLength << 2, 1904164990Smjacob hdr.PageNumber, hdr.PageType); 1905147883Sscottl 1906147883Sscottl len = hdr.PageLength * sizeof(uint32_t); 1907151075Sscottl mpt->ioc_page2 = malloc(len, M_DEVBUF, M_NOWAIT | M_ZERO); 1908158982Smjacob if (mpt->ioc_page2 == NULL) { 1909158982Smjacob mpt_prt(mpt, "unable to allocate memory for IOC page 2\n"); 1910158982Smjacob mpt_raid_free_mem(mpt); 1911147883Sscottl return (ENOMEM); 1912158982Smjacob } 1913147883Sscottl memcpy(&mpt->ioc_page2->Header, &hdr, sizeof(hdr)); 1914158982Smjacob rv = mpt_read_cur_cfg_page(mpt, 0, 1915158982Smjacob &mpt->ioc_page2->Header, len, FALSE, 5000); 1916147883Sscottl if (rv) { 1917147883Sscottl mpt_prt(mpt, "failed to read IOC Page 2\n"); 1918158982Smjacob mpt_raid_free_mem(mpt); 1919158982Smjacob return (EIO); 1920158982Smjacob } 1921164990Smjacob mpt2host_config_page_ioc2(mpt->ioc_page2); 1922158982Smjacob 1923158982Smjacob if (mpt->ioc_page2->CapabilitiesFlags != 0) { 1924147883Sscottl uint32_t mask; 1925147883Sscottl 1926147883Sscottl mpt_prt(mpt, "Capabilities: ("); 1927147883Sscottl for (mask = 1; mask != 0; mask <<= 1) { 1928158982Smjacob if ((mpt->ioc_page2->CapabilitiesFlags & mask) == 0) { 1929147883Sscottl continue; 1930158982Smjacob } 1931147883Sscottl switch (mask) { 1932147883Sscottl case MPI_IOCPAGE2_CAP_FLAGS_IS_SUPPORT: 1933147883Sscottl mpt_prtc(mpt, " RAID-0"); 1934147883Sscottl break; 1935147883Sscottl case MPI_IOCPAGE2_CAP_FLAGS_IME_SUPPORT: 1936147883Sscottl mpt_prtc(mpt, " RAID-1E"); 1937147883Sscottl break; 1938147883Sscottl case MPI_IOCPAGE2_CAP_FLAGS_IM_SUPPORT: 1939147883Sscottl mpt_prtc(mpt, " RAID-1"); 1940147883Sscottl break; 1941147883Sscottl case MPI_IOCPAGE2_CAP_FLAGS_SES_SUPPORT: 1942147883Sscottl mpt_prtc(mpt, " SES"); 1943147883Sscottl break; 1944147883Sscottl case MPI_IOCPAGE2_CAP_FLAGS_SAFTE_SUPPORT: 1945147883Sscottl mpt_prtc(mpt, " SAFTE"); 1946147883Sscottl break; 1947147883Sscottl case MPI_IOCPAGE2_CAP_FLAGS_CROSS_CHANNEL_SUPPORT: 1948147883Sscottl mpt_prtc(mpt, " Multi-Channel-Arrays"); 1949147883Sscottl default: 1950147883Sscottl break; 1951147883Sscottl } 1952102199Smjacob } 1953147883Sscottl mpt_prtc(mpt, " )\n"); 1954147883Sscottl if ((mpt->ioc_page2->CapabilitiesFlags 1955147883Sscottl & (MPI_IOCPAGE2_CAP_FLAGS_IS_SUPPORT 1956147883Sscottl | MPI_IOCPAGE2_CAP_FLAGS_IME_SUPPORT 1957147883Sscottl | MPI_IOCPAGE2_CAP_FLAGS_IM_SUPPORT)) != 0) { 1958147883Sscottl mpt_prt(mpt, "%d Active Volume%s(%d Max)\n", 1959147883Sscottl mpt->ioc_page2->NumActiveVolumes, 1960147883Sscottl mpt->ioc_page2->NumActiveVolumes != 1 1961147883Sscottl ? "s " : " ", 1962147883Sscottl mpt->ioc_page2->MaxVolumes); 1963147883Sscottl mpt_prt(mpt, "%d Hidden Drive Member%s(%d Max)\n", 1964147883Sscottl mpt->ioc_page2->NumActivePhysDisks, 1965147883Sscottl mpt->ioc_page2->NumActivePhysDisks != 1 1966147883Sscottl ? "s " : " ", 1967147883Sscottl mpt->ioc_page2->MaxPhysDisks); 1968147883Sscottl } 1969147883Sscottl } 1970102199Smjacob 1971147883Sscottl len = mpt->ioc_page2->MaxVolumes * sizeof(struct mpt_raid_volume); 1972158982Smjacob mpt->raid_volumes = malloc(len, M_DEVBUF, M_NOWAIT | M_ZERO); 1973147883Sscottl if (mpt->raid_volumes == NULL) { 1974147883Sscottl mpt_prt(mpt, "Could not allocate RAID volume data\n"); 1975158982Smjacob mpt_raid_free_mem(mpt); 1976158982Smjacob return (ENOMEM); 1977147883Sscottl } 1978147883Sscottl 1979147883Sscottl /* 1980147883Sscottl * Copy critical data out of ioc_page2 so that we can 1981147883Sscottl * safely refresh the page without windows of unreliable 1982147883Sscottl * data. 1983147883Sscottl */ 1984147883Sscottl mpt->raid_max_volumes = mpt->ioc_page2->MaxVolumes; 1985147883Sscottl 1986158982Smjacob len = sizeof(*mpt->raid_volumes->config_page) + 1987158982Smjacob (sizeof (RAID_VOL0_PHYS_DISK) * (mpt->ioc_page2->MaxPhysDisks - 1)); 1988147883Sscottl for (i = 0; i < mpt->ioc_page2->MaxVolumes; i++) { 1989147883Sscottl mpt_raid = &mpt->raid_volumes[i]; 1990158982Smjacob mpt_raid->config_page = 1991158982Smjacob malloc(len, M_DEVBUF, M_NOWAIT | M_ZERO); 1992147883Sscottl if (mpt_raid->config_page == NULL) { 1993147883Sscottl mpt_prt(mpt, "Could not allocate RAID page data\n"); 1994158982Smjacob mpt_raid_free_mem(mpt); 1995158982Smjacob return (ENOMEM); 1996147883Sscottl } 1997147883Sscottl } 1998147883Sscottl mpt->raid_page0_len = len; 1999147883Sscottl 2000147883Sscottl len = mpt->ioc_page2->MaxPhysDisks * sizeof(struct mpt_raid_disk); 2001158982Smjacob mpt->raid_disks = malloc(len, M_DEVBUF, M_NOWAIT | M_ZERO); 2002147883Sscottl if (mpt->raid_disks == NULL) { 2003147883Sscottl mpt_prt(mpt, "Could not allocate RAID disk data\n"); 2004158982Smjacob mpt_raid_free_mem(mpt); 2005158982Smjacob return (ENOMEM); 2006147883Sscottl } 2007147883Sscottl mpt->raid_max_disks = mpt->ioc_page2->MaxPhysDisks; 2008147883Sscottl 2009158982Smjacob /* 2010158982Smjacob * Load page 3. 2011158982Smjacob */ 2012147883Sscottl rv = mpt_read_cfg_header(mpt, MPI_CONFIG_PAGETYPE_IOC, 2013158982Smjacob 3, 0, &hdr, FALSE, 5000); 2014158982Smjacob if (rv) { 2015158982Smjacob mpt_raid_free_mem(mpt); 2016147883Sscottl return (EIO); 2017158982Smjacob } 2018147883Sscottl 2019147883Sscottl mpt_lprt(mpt, MPT_PRT_DEBUG, "IOC Page 3 Header: %x %x %x %x\n", 2020158982Smjacob hdr.PageVersion, hdr.PageLength, hdr.PageNumber, hdr.PageType); 2021147883Sscottl 2022147883Sscottl len = hdr.PageLength * sizeof(uint32_t); 2023151075Sscottl mpt->ioc_page3 = malloc(len, M_DEVBUF, M_NOWAIT | M_ZERO); 2024158982Smjacob if (mpt->ioc_page3 == NULL) { 2025158982Smjacob mpt_prt(mpt, "unable to allocate memory for IOC page 3\n"); 2026158982Smjacob mpt_raid_free_mem(mpt); 2027158982Smjacob return (ENOMEM); 2028158982Smjacob } 2029147883Sscottl memcpy(&mpt->ioc_page3->Header, &hdr, sizeof(hdr)); 2030158982Smjacob rv = mpt_read_cur_cfg_page(mpt, 0, 2031158982Smjacob &mpt->ioc_page3->Header, len, FALSE, 5000); 2032147883Sscottl if (rv) { 2033158982Smjacob mpt_raid_free_mem(mpt); 2034158982Smjacob return (EIO); 2035102199Smjacob } 2036186878Smarius mpt2host_config_page_ioc3(mpt->ioc_page3); 2037147883Sscottl mpt_raid_wakeup(mpt); 2038102199Smjacob return (0); 2039102199Smjacob} 2040102199Smjacob 2041102199Smjacob/* 2042102199Smjacob * Enable IOC port 2043102199Smjacob */ 2044102199Smjacobstatic int 2045147883Sscottlmpt_send_port_enable(struct mpt_softc *mpt, int port) 2046102199Smjacob{ 2047147883Sscottl request_t *req; 2048101704Smjacob MSG_PORT_ENABLE *enable_req; 2049147883Sscottl int error; 2050101704Smjacob 2051147883Sscottl req = mpt_get_request(mpt, /*sleep_ok*/FALSE); 2052147883Sscottl if (req == NULL) 2053147883Sscottl return (-1); 2054101704Smjacob 2055101704Smjacob enable_req = req->req_vbuf; 2056157354Smjacob memset(enable_req, 0, MPT_RQSL(mpt)); 2057101704Smjacob 2058101704Smjacob enable_req->Function = MPI_FUNCTION_PORT_ENABLE; 2059147883Sscottl enable_req->MsgContext = htole32(req->index | MPT_REPLY_HANDLER_CONFIG); 2060101704Smjacob enable_req->PortNumber = port; 2061101704Smjacob 2062101704Smjacob mpt_check_doorbell(mpt); 2063147883Sscottl mpt_lprt(mpt, MPT_PRT_DEBUG, "enabling port %d\n", port); 2064147883Sscottl 2065147883Sscottl mpt_send_cmd(mpt, req); 2066147883Sscottl error = mpt_wait_req(mpt, req, REQ_STATE_DONE, REQ_STATE_DONE, 2067157662Smjacob FALSE, (mpt->is_sas || mpt->is_fc)? 30000 : 3000); 2068147883Sscottl if (error != 0) { 2069157117Smjacob mpt_prt(mpt, "port %d enable timed out\n", port); 2070147883Sscottl return (-1); 2071101704Smjacob } 2072101704Smjacob mpt_free_request(mpt, req); 2073157117Smjacob mpt_lprt(mpt, MPT_PRT_DEBUG, "enabled port %d\n", port); 2074101704Smjacob return (0); 2075101704Smjacob} 2076101704Smjacob 2077101704Smjacob/* 2078101704Smjacob * Enable/Disable asynchronous event reporting. 2079101704Smjacob */ 2080101704Smjacobstatic int 2081147883Sscottlmpt_send_event_request(struct mpt_softc *mpt, int onoff) 2082101704Smjacob{ 2083101704Smjacob request_t *req; 2084101704Smjacob MSG_EVENT_NOTIFY *enable_req; 2085101704Smjacob 2086157354Smjacob req = mpt_get_request(mpt, FALSE); 2087157354Smjacob if (req == NULL) { 2088157354Smjacob return (ENOMEM); 2089157354Smjacob } 2090101704Smjacob enable_req = req->req_vbuf; 2091157354Smjacob memset(enable_req, 0, sizeof *enable_req); 2092101704Smjacob 2093101704Smjacob enable_req->Function = MPI_FUNCTION_EVENT_NOTIFICATION; 2094147883Sscottl enable_req->MsgContext = htole32(req->index | MPT_REPLY_HANDLER_EVENTS); 2095101704Smjacob enable_req->Switch = onoff; 2096101704Smjacob 2097101704Smjacob mpt_check_doorbell(mpt); 2098157354Smjacob mpt_lprt(mpt, MPT_PRT_DEBUG, "%sabling async events\n", 2099157354Smjacob onoff ? "en" : "dis"); 2100157354Smjacob /* 2101157354Smjacob * Send the command off, but don't wait for it. 2102157354Smjacob */ 2103101704Smjacob mpt_send_cmd(mpt, req); 2104101704Smjacob return (0); 2105101704Smjacob} 2106101704Smjacob 2107101704Smjacob/* 2108172568Skevlo * Un-mask the interrupts on the chip. 2109101704Smjacob */ 2110101704Smjacobvoid 2111147883Sscottlmpt_enable_ints(struct mpt_softc *mpt) 2112101704Smjacob{ 2113101704Smjacob /* Unmask every thing except door bell int */ 2114101704Smjacob mpt_write(mpt, MPT_OFFSET_INTR_MASK, MPT_INTR_DB_MASK); 2115101704Smjacob} 2116101704Smjacob 2117101704Smjacob/* 2118172568Skevlo * Mask the interrupts on the chip. 2119101704Smjacob */ 2120101704Smjacobvoid 2121147883Sscottlmpt_disable_ints(struct mpt_softc *mpt) 2122101704Smjacob{ 2123101704Smjacob /* Mask all interrupts */ 2124156104Smjacob mpt_write(mpt, MPT_OFFSET_INTR_MASK, 2125101704Smjacob MPT_INTR_REPLY_MASK | MPT_INTR_DB_MASK); 2126101704Smjacob} 2127101704Smjacob 2128147883Sscottlstatic void 2129147883Sscottlmpt_sysctl_attach(struct mpt_softc *mpt) 2130147883Sscottl{ 2131157117Smjacob#if __FreeBSD_version >= 500000 2132147883Sscottl struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(mpt->dev); 2133147883Sscottl struct sysctl_oid *tree = device_get_sysctl_tree(mpt->dev); 2134147883Sscottl 2135217323Smdf SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, 2136147883Sscottl "debug", CTLFLAG_RW, &mpt->verbose, 0, 2137147883Sscottl "Debugging/Verbose level"); 2138217323Smdf SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, 2139160290Smjacob "role", CTLFLAG_RD, &mpt->role, 0, 2140160290Smjacob "HBA role"); 2141165814Smjacob#ifdef MPT_TEST_MULTIPATH 2142165814Smjacob SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, 2143165814Smjacob "failure_id", CTLFLAG_RW, &mpt->failure_id, -1, 2144165814Smjacob "Next Target to Fail"); 2145157117Smjacob#endif 2146165814Smjacob#endif 2147147883Sscottl} 2148147883Sscottl 2149101704Smjacobint 2150147883Sscottlmpt_attach(struct mpt_softc *mpt) 2151101704Smjacob{ 2152157117Smjacob struct mpt_personality *pers; 2153147883Sscottl int i; 2154157117Smjacob int error; 2155147883Sscottl 2156177808Sscottl mpt_core_attach(mpt); 2157177808Sscottl mpt_core_enable(mpt); 2158177808Sscottl 2159162133Smjacob TAILQ_INSERT_TAIL(&mpt_tailq, mpt, links); 2160147883Sscottl for (i = 0; i < MPT_MAX_PERSONALITIES; i++) { 2161147883Sscottl pers = mpt_personalities[i]; 2162157117Smjacob if (pers == NULL) { 2163147883Sscottl continue; 2164157117Smjacob } 2165147883Sscottl if (pers->probe(mpt) == 0) { 2166147883Sscottl error = pers->attach(mpt); 2167147883Sscottl if (error != 0) { 2168147883Sscottl mpt_detach(mpt); 2169147883Sscottl return (error); 2170147883Sscottl } 2171147883Sscottl mpt->mpt_pers_mask |= (0x1 << pers->id); 2172147883Sscottl pers->use_count++; 2173147883Sscottl } 2174147883Sscottl } 2175155521Smjacob 2176157117Smjacob /* 2177157117Smjacob * Now that we've attached everything, do the enable function 2178157117Smjacob * for all of the personalities. This allows the personalities 2179157117Smjacob * to do setups that are appropriate for them prior to enabling 2180157117Smjacob * any ports. 2181157117Smjacob */ 2182157117Smjacob for (i = 0; i < MPT_MAX_PERSONALITIES; i++) { 2183157117Smjacob pers = mpt_personalities[i]; 2184157117Smjacob if (pers != NULL && MPT_PERS_ATTACHED(pers, mpt) != 0) { 2185157117Smjacob error = pers->enable(mpt); 2186157117Smjacob if (error != 0) { 2187157117Smjacob mpt_prt(mpt, "personality %s attached but would" 2188157117Smjacob " not enable (%d)\n", pers->name, error); 2189157117Smjacob mpt_detach(mpt); 2190157117Smjacob return (error); 2191157117Smjacob } 2192157117Smjacob } 2193157117Smjacob } 2194147883Sscottl return (0); 2195147883Sscottl} 2196147883Sscottl 2197147883Sscottlint 2198147883Sscottlmpt_shutdown(struct mpt_softc *mpt) 2199147883Sscottl{ 2200147883Sscottl struct mpt_personality *pers; 2201147883Sscottl 2202157117Smjacob MPT_PERS_FOREACH_REVERSE(mpt, pers) { 2203147883Sscottl pers->shutdown(mpt); 2204157117Smjacob } 2205147883Sscottl return (0); 2206147883Sscottl} 2207147883Sscottl 2208147883Sscottlint 2209147883Sscottlmpt_detach(struct mpt_softc *mpt) 2210147883Sscottl{ 2211147883Sscottl struct mpt_personality *pers; 2212147883Sscottl 2213147883Sscottl MPT_PERS_FOREACH_REVERSE(mpt, pers) { 2214147883Sscottl pers->detach(mpt); 2215147883Sscottl mpt->mpt_pers_mask &= ~(0x1 << pers->id); 2216147883Sscottl pers->use_count--; 2217147883Sscottl } 2218162133Smjacob TAILQ_REMOVE(&mpt_tailq, mpt, links); 2219147883Sscottl return (0); 2220147883Sscottl} 2221147883Sscottl 2222147883Sscottlint 2223147883Sscottlmpt_core_load(struct mpt_personality *pers) 2224147883Sscottl{ 2225147883Sscottl int i; 2226147883Sscottl 2227147883Sscottl /* 2228147883Sscottl * Setup core handlers and insert the default handler 2229147883Sscottl * into all "empty slots". 2230147883Sscottl */ 2231157117Smjacob for (i = 0; i < MPT_NUM_REPLY_HANDLERS; i++) { 2232147883Sscottl mpt_reply_handlers[i] = mpt_default_reply_handler; 2233157117Smjacob } 2234147883Sscottl 2235147883Sscottl mpt_reply_handlers[MPT_CBI(MPT_REPLY_HANDLER_EVENTS)] = 2236147883Sscottl mpt_event_reply_handler; 2237147883Sscottl mpt_reply_handlers[MPT_CBI(MPT_REPLY_HANDLER_CONFIG)] = 2238147883Sscottl mpt_config_reply_handler; 2239147883Sscottl mpt_reply_handlers[MPT_CBI(MPT_REPLY_HANDLER_HANDSHAKE)] = 2240147883Sscottl mpt_handshake_reply_handler; 2241147883Sscottl return (0); 2242147883Sscottl} 2243147883Sscottl 2244147883Sscottl/* 2245147883Sscottl * Initialize per-instance driver data and perform 2246147883Sscottl * initial controller configuration. 2247147883Sscottl */ 2248147883Sscottlint 2249147883Sscottlmpt_core_attach(struct mpt_softc *mpt) 2250147883Sscottl{ 2251169293Smjacob int val, error; 2252101704Smjacob 2253147883Sscottl LIST_INIT(&mpt->ack_frames); 2254147883Sscottl /* Put all request buffers on the free list */ 2255147883Sscottl TAILQ_INIT(&mpt->request_pending_list); 2256147883Sscottl TAILQ_INIT(&mpt->request_free_list); 2257157354Smjacob TAILQ_INIT(&mpt->request_timeout_list); 2258157117Smjacob for (val = 0; val < MPT_MAX_LUNS; val++) { 2259157117Smjacob STAILQ_INIT(&mpt->trt[val].atios); 2260157117Smjacob STAILQ_INIT(&mpt->trt[val].inots); 2261157117Smjacob } 2262157117Smjacob STAILQ_INIT(&mpt->trt_wildcard.atios); 2263157117Smjacob STAILQ_INIT(&mpt->trt_wildcard.inots); 2264165814Smjacob#ifdef MPT_TEST_MULTIPATH 2265165814Smjacob mpt->failure_id = -1; 2266165814Smjacob#endif 2267157117Smjacob mpt->scsi_tgt_handler_id = MPT_HANDLER_ID_NONE; 2268147883Sscottl mpt_sysctl_attach(mpt); 2269147883Sscottl mpt_lprt(mpt, MPT_PRT_DEBUG, "doorbell req = %s\n", 2270157117Smjacob mpt_ioc_diag(mpt_read(mpt, MPT_OFFSET_DOORBELL))); 2271169293Smjacob 2272169293Smjacob MPT_LOCK(mpt); 2273177881Sscottl error = mpt_configure_ioc(mpt, 0, 0); 2274169293Smjacob MPT_UNLOCK(mpt); 2275169293Smjacob 2276169293Smjacob return (error); 2277147883Sscottl} 2278147883Sscottl 2279157117Smjacobint 2280157117Smjacobmpt_core_enable(struct mpt_softc *mpt) 2281157117Smjacob{ 2282157117Smjacob /* 2283157117Smjacob * We enter with the IOC enabled, but async events 2284157117Smjacob * not enabled, ports not enabled and interrupts 2285157117Smjacob * not enabled. 2286157117Smjacob */ 2287169293Smjacob MPT_LOCK(mpt); 2288157117Smjacob 2289157117Smjacob /* 2290157117Smjacob * Enable asynchronous event reporting- all personalities 2291157117Smjacob * have attached so that they should be able to now field 2292157117Smjacob * async events. 2293157117Smjacob */ 2294157117Smjacob mpt_send_event_request(mpt, 1); 2295157117Smjacob 2296157117Smjacob /* 2297157117Smjacob * Catch any pending interrupts 2298157117Smjacob * 2299157117Smjacob * This seems to be crucial- otherwise 2300157117Smjacob * the portenable below times out. 2301157117Smjacob */ 2302157117Smjacob mpt_intr(mpt); 2303157117Smjacob 2304157117Smjacob /* 2305157117Smjacob * Enable Interrupts 2306157117Smjacob */ 2307157117Smjacob mpt_enable_ints(mpt); 2308157117Smjacob 2309157117Smjacob /* 2310157117Smjacob * Catch any pending interrupts 2311157117Smjacob * 2312157117Smjacob * This seems to be crucial- otherwise 2313157117Smjacob * the portenable below times out. 2314157117Smjacob */ 2315157117Smjacob mpt_intr(mpt); 2316157117Smjacob 2317157117Smjacob /* 2318157662Smjacob * Enable the port. 2319157117Smjacob */ 2320157117Smjacob if (mpt_send_port_enable(mpt, 0) != MPT_OK) { 2321157117Smjacob mpt_prt(mpt, "failed to enable port 0\n"); 2322169293Smjacob MPT_UNLOCK(mpt); 2323157117Smjacob return (ENXIO); 2324157117Smjacob } 2325169293Smjacob MPT_UNLOCK(mpt); 2326157117Smjacob return (0); 2327157117Smjacob} 2328157117Smjacob 2329147883Sscottlvoid 2330147883Sscottlmpt_core_shutdown(struct mpt_softc *mpt) 2331147883Sscottl{ 2332157117Smjacob mpt_disable_ints(mpt); 2333147883Sscottl} 2334147883Sscottl 2335147883Sscottlvoid 2336147883Sscottlmpt_core_detach(struct mpt_softc *mpt) 2337147883Sscottl{ 2338198262Skan int val; 2339198262Skan 2340164990Smjacob /* 2341164990Smjacob * XXX: FREE MEMORY 2342164990Smjacob */ 2343157117Smjacob mpt_disable_ints(mpt); 2344198262Skan 2345198262Skan /* Make sure no request has pending timeouts. */ 2346198262Skan for (val = 0; val < MPT_MAX_REQUESTS(mpt); val++) { 2347198262Skan request_t *req = &mpt->request_pool[val]; 2348198262Skan mpt_callout_drain(mpt, &req->callout); 2349198262Skan } 2350209599Sken 2351209599Sken mpt_dma_buf_free(mpt); 2352147883Sscottl} 2353147883Sscottl 2354147883Sscottlint 2355147883Sscottlmpt_core_unload(struct mpt_personality *pers) 2356147883Sscottl{ 2357220945Smarius /* Unload is always successful. */ 2358147883Sscottl return (0); 2359147883Sscottl} 2360147883Sscottl 2361147883Sscottl#define FW_UPLOAD_REQ_SIZE \ 2362147883Sscottl (sizeof(MSG_FW_UPLOAD) - sizeof(SGE_MPI_UNION) \ 2363147883Sscottl + sizeof(FW_UPLOAD_TCSGE) + sizeof(SGE_SIMPLE32)) 2364147883Sscottl 2365147883Sscottlstatic int 2366147883Sscottlmpt_upload_fw(struct mpt_softc *mpt) 2367147883Sscottl{ 2368147883Sscottl uint8_t fw_req_buf[FW_UPLOAD_REQ_SIZE]; 2369147883Sscottl MSG_FW_UPLOAD_REPLY fw_reply; 2370147883Sscottl MSG_FW_UPLOAD *fw_req; 2371147883Sscottl FW_UPLOAD_TCSGE *tsge; 2372147883Sscottl SGE_SIMPLE32 *sge; 2373147883Sscottl uint32_t flags; 2374147883Sscottl int error; 2375147883Sscottl 2376147883Sscottl memset(&fw_req_buf, 0, sizeof(fw_req_buf)); 2377147883Sscottl fw_req = (MSG_FW_UPLOAD *)fw_req_buf; 2378147883Sscottl fw_req->ImageType = MPI_FW_UPLOAD_ITYPE_FW_IOC_MEM; 2379147883Sscottl fw_req->Function = MPI_FUNCTION_FW_UPLOAD; 2380147883Sscottl fw_req->MsgContext = htole32(MPT_REPLY_HANDLER_HANDSHAKE); 2381147883Sscottl tsge = (FW_UPLOAD_TCSGE *)&fw_req->SGL; 2382147883Sscottl tsge->DetailsLength = 12; 2383147883Sscottl tsge->Flags = MPI_SGE_FLAGS_TRANSACTION_ELEMENT; 2384147883Sscottl tsge->ImageSize = htole32(mpt->fw_image_size); 2385147883Sscottl sge = (SGE_SIMPLE32 *)(tsge + 1); 2386147883Sscottl flags = (MPI_SGE_FLAGS_LAST_ELEMENT | MPI_SGE_FLAGS_END_OF_BUFFER 2387147883Sscottl | MPI_SGE_FLAGS_END_OF_LIST | MPI_SGE_FLAGS_SIMPLE_ELEMENT 2388147883Sscottl | MPI_SGE_FLAGS_32_BIT_ADDRESSING | MPI_SGE_FLAGS_IOC_TO_HOST); 2389147883Sscottl flags <<= MPI_SGE_FLAGS_SHIFT; 2390147883Sscottl sge->FlagsLength = htole32(flags | mpt->fw_image_size); 2391147883Sscottl sge->Address = htole32(mpt->fw_phys); 2392219335Smarius bus_dmamap_sync(mpt->fw_dmat, mpt->fw_dmap, BUS_DMASYNC_PREREAD); 2393147883Sscottl error = mpt_send_handshake_cmd(mpt, sizeof(fw_req_buf), &fw_req_buf); 2394147883Sscottl if (error) 2395147883Sscottl return(error); 2396147883Sscottl error = mpt_recv_handshake_reply(mpt, sizeof(fw_reply), &fw_reply); 2397219335Smarius bus_dmamap_sync(mpt->fw_dmat, mpt->fw_dmap, BUS_DMASYNC_POSTREAD); 2398147883Sscottl return (error); 2399147883Sscottl} 2400147883Sscottl 2401147883Sscottlstatic void 2402147883Sscottlmpt_diag_outsl(struct mpt_softc *mpt, uint32_t addr, 2403147883Sscottl uint32_t *data, bus_size_t len) 2404147883Sscottl{ 2405147883Sscottl uint32_t *data_end; 2406147883Sscottl 2407147883Sscottl data_end = data + (roundup2(len, sizeof(uint32_t)) / 4); 2408159919Smjacob if (mpt->is_sas) { 2409159919Smjacob pci_enable_io(mpt->dev, SYS_RES_IOPORT); 2410159919Smjacob } 2411147883Sscottl mpt_pio_write(mpt, MPT_OFFSET_DIAG_ADDR, addr); 2412147883Sscottl while (data != data_end) { 2413147883Sscottl mpt_pio_write(mpt, MPT_OFFSET_DIAG_DATA, *data); 2414147883Sscottl data++; 2415101704Smjacob } 2416159919Smjacob if (mpt->is_sas) { 2417159919Smjacob pci_disable_io(mpt->dev, SYS_RES_IOPORT); 2418159919Smjacob } 2419147883Sscottl} 2420101704Smjacob 2421147883Sscottlstatic int 2422147883Sscottlmpt_download_fw(struct mpt_softc *mpt) 2423147883Sscottl{ 2424147883Sscottl MpiFwHeader_t *fw_hdr; 2425147883Sscottl int error; 2426147883Sscottl uint32_t ext_offset; 2427147883Sscottl uint32_t data; 2428147883Sscottl 2429147883Sscottl mpt_prt(mpt, "Downloading Firmware - Image Size %d\n", 2430147883Sscottl mpt->fw_image_size); 2431147883Sscottl 2432147883Sscottl error = mpt_enable_diag_mode(mpt); 2433147883Sscottl if (error != 0) { 2434147883Sscottl mpt_prt(mpt, "Could not enter diagnostic mode!\n"); 2435147883Sscottl return (EIO); 2436101704Smjacob } 2437101704Smjacob 2438147883Sscottl mpt_write(mpt, MPT_OFFSET_DIAGNOSTIC, 2439147883Sscottl MPI_DIAG_RW_ENABLE|MPI_DIAG_DISABLE_ARM); 2440147883Sscottl 2441147883Sscottl fw_hdr = (MpiFwHeader_t *)mpt->fw_image; 2442219335Smarius bus_dmamap_sync(mpt->fw_dmat, mpt->fw_dmap, BUS_DMASYNC_PREWRITE); 2443147883Sscottl mpt_diag_outsl(mpt, fw_hdr->LoadStartAddress, (uint32_t*)fw_hdr, 2444147883Sscottl fw_hdr->ImageSize); 2445219335Smarius bus_dmamap_sync(mpt->fw_dmat, mpt->fw_dmap, BUS_DMASYNC_POSTWRITE); 2446147883Sscottl 2447147883Sscottl ext_offset = fw_hdr->NextImageHeaderOffset; 2448147883Sscottl while (ext_offset != 0) { 2449147883Sscottl MpiExtImageHeader_t *ext; 2450147883Sscottl 2451147883Sscottl ext = (MpiExtImageHeader_t *)((uintptr_t)fw_hdr + ext_offset); 2452147883Sscottl ext_offset = ext->NextImageHeaderOffset; 2453219335Smarius bus_dmamap_sync(mpt->fw_dmat, mpt->fw_dmap, 2454219335Smarius BUS_DMASYNC_PREWRITE); 2455147883Sscottl mpt_diag_outsl(mpt, ext->LoadStartAddress, (uint32_t*)ext, 2456147883Sscottl ext->ImageSize); 2457219335Smarius bus_dmamap_sync(mpt->fw_dmat, mpt->fw_dmap, 2458219335Smarius BUS_DMASYNC_POSTWRITE); 2459147883Sscottl } 2460147883Sscottl 2461159919Smjacob if (mpt->is_sas) { 2462159919Smjacob pci_enable_io(mpt->dev, SYS_RES_IOPORT); 2463159919Smjacob } 2464147883Sscottl /* Setup the address to jump to on reset. */ 2465147883Sscottl mpt_pio_write(mpt, MPT_OFFSET_DIAG_ADDR, fw_hdr->IopResetRegAddr); 2466147883Sscottl mpt_pio_write(mpt, MPT_OFFSET_DIAG_DATA, fw_hdr->IopResetVectorValue); 2467147883Sscottl 2468101704Smjacob /* 2469147883Sscottl * The controller sets the "flash bad" status after attempting 2470147883Sscottl * to auto-boot from flash. Clear the status so that the controller 2471147883Sscottl * will continue the boot process with our newly installed firmware. 2472101704Smjacob */ 2473147883Sscottl mpt_pio_write(mpt, MPT_OFFSET_DIAG_ADDR, MPT_DIAG_MEM_CFG_BASE); 2474147883Sscottl data = mpt_pio_read(mpt, MPT_OFFSET_DIAG_DATA) | MPT_DIAG_MEM_CFG_BADFL; 2475147883Sscottl mpt_pio_write(mpt, MPT_OFFSET_DIAG_ADDR, MPT_DIAG_MEM_CFG_BASE); 2476147883Sscottl mpt_pio_write(mpt, MPT_OFFSET_DIAG_DATA, data); 2477147883Sscottl 2478159919Smjacob if (mpt->is_sas) { 2479159919Smjacob pci_disable_io(mpt->dev, SYS_RES_IOPORT); 2480159919Smjacob } 2481155521Smjacob 2482147883Sscottl /* 2483147883Sscottl * Re-enable the processor and clear the boot halt flag. 2484147883Sscottl */ 2485147883Sscottl data = mpt_read(mpt, MPT_OFFSET_DIAGNOSTIC); 2486147883Sscottl data &= ~(MPI_DIAG_PREVENT_IOC_BOOT|MPI_DIAG_DISABLE_ARM); 2487147883Sscottl mpt_write(mpt, MPT_OFFSET_DIAGNOSTIC, data); 2488147883Sscottl 2489147883Sscottl mpt_disable_diag_mode(mpt); 2490147883Sscottl return (0); 2491147883Sscottl} 2492147883Sscottl 2493209960Smariusstatic int 2494209599Skenmpt_dma_buf_alloc(struct mpt_softc *mpt) 2495209599Sken{ 2496209599Sken struct mpt_map_info mi; 2497209599Sken uint8_t *vptr; 2498209599Sken uint32_t pptr, end; 2499209599Sken int i, error; 2500209599Sken 2501209599Sken /* Create a child tag for data buffers */ 2502209599Sken if (mpt_dma_tag_create(mpt, mpt->parent_dmat, 1, 2503209599Sken 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, 2504209960Smarius NULL, NULL, (mpt->max_cam_seg_cnt - 1) * PAGE_SIZE, 2505209960Smarius mpt->max_cam_seg_cnt, BUS_SPACE_MAXSIZE_32BIT, 0, 2506209960Smarius &mpt->buffer_dmat) != 0) { 2507209599Sken mpt_prt(mpt, "cannot create a dma tag for data buffers\n"); 2508209599Sken return (1); 2509209599Sken } 2510209599Sken 2511209599Sken /* Create a child tag for request buffers */ 2512209599Sken if (mpt_dma_tag_create(mpt, mpt->parent_dmat, PAGE_SIZE, 0, 2513209599Sken BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, 2514209599Sken NULL, NULL, MPT_REQ_MEM_SIZE(mpt), 1, BUS_SPACE_MAXSIZE_32BIT, 0, 2515209599Sken &mpt->request_dmat) != 0) { 2516209599Sken mpt_prt(mpt, "cannot create a dma tag for requests\n"); 2517209599Sken return (1); 2518209599Sken } 2519209599Sken 2520220945Smarius /* Allocate some DMA accessible memory for requests */ 2521209599Sken if (bus_dmamem_alloc(mpt->request_dmat, (void **)&mpt->request, 2522219335Smarius BUS_DMA_NOWAIT | BUS_DMA_COHERENT, &mpt->request_dmap) != 0) { 2523209599Sken mpt_prt(mpt, "cannot allocate %d bytes of request memory\n", 2524209599Sken MPT_REQ_MEM_SIZE(mpt)); 2525209599Sken return (1); 2526209599Sken } 2527209599Sken 2528209599Sken mi.mpt = mpt; 2529209599Sken mi.error = 0; 2530209599Sken 2531209599Sken /* Load and lock it into "bus space" */ 2532209599Sken bus_dmamap_load(mpt->request_dmat, mpt->request_dmap, mpt->request, 2533209599Sken MPT_REQ_MEM_SIZE(mpt), mpt_map_rquest, &mi, 0); 2534209599Sken 2535209599Sken if (mi.error) { 2536209599Sken mpt_prt(mpt, "error %d loading dma map for DMA request queue\n", 2537209599Sken mi.error); 2538209599Sken return (1); 2539209599Sken } 2540209599Sken mpt->request_phys = mi.phys; 2541209599Sken 2542209599Sken /* 2543209599Sken * Now create per-request dma maps 2544209599Sken */ 2545209599Sken i = 0; 2546209599Sken pptr = mpt->request_phys; 2547209599Sken vptr = mpt->request; 2548209599Sken end = pptr + MPT_REQ_MEM_SIZE(mpt); 2549209599Sken while(pptr < end) { 2550209599Sken request_t *req = &mpt->request_pool[i]; 2551209599Sken req->index = i++; 2552209599Sken 2553209599Sken /* Store location of Request Data */ 2554209599Sken req->req_pbuf = pptr; 2555209599Sken req->req_vbuf = vptr; 2556209599Sken 2557209599Sken pptr += MPT_REQUEST_AREA; 2558209599Sken vptr += MPT_REQUEST_AREA; 2559209599Sken 2560209599Sken req->sense_pbuf = (pptr - MPT_SENSE_SIZE); 2561209599Sken req->sense_vbuf = (vptr - MPT_SENSE_SIZE); 2562209599Sken 2563209599Sken error = bus_dmamap_create(mpt->buffer_dmat, 0, &req->dmap); 2564209599Sken if (error) { 2565209599Sken mpt_prt(mpt, "error %d creating per-cmd DMA maps\n", 2566209599Sken error); 2567209599Sken return (1); 2568209599Sken } 2569209599Sken } 2570209599Sken 2571209599Sken return (0); 2572209599Sken} 2573209599Sken 2574209599Skenstatic void 2575209599Skenmpt_dma_buf_free(struct mpt_softc *mpt) 2576209599Sken{ 2577209599Sken int i; 2578209599Sken if (mpt->request_dmat == 0) { 2579209599Sken mpt_lprt(mpt, MPT_PRT_DEBUG, "already released dma memory\n"); 2580209599Sken return; 2581209599Sken } 2582209599Sken for (i = 0; i < MPT_MAX_REQUESTS(mpt); i++) { 2583209599Sken bus_dmamap_destroy(mpt->buffer_dmat, mpt->request_pool[i].dmap); 2584209599Sken } 2585209599Sken bus_dmamap_unload(mpt->request_dmat, mpt->request_dmap); 2586209599Sken bus_dmamem_free(mpt->request_dmat, mpt->request, mpt->request_dmap); 2587209599Sken bus_dma_tag_destroy(mpt->request_dmat); 2588209599Sken mpt->request_dmat = 0; 2589209599Sken bus_dma_tag_destroy(mpt->buffer_dmat); 2590209599Sken} 2591209599Sken 2592147883Sscottl/* 2593147883Sscottl * Allocate/Initialize data structures for the controller. Called 2594147883Sscottl * once at instance startup. 2595147883Sscottl */ 2596147883Sscottlstatic int 2597164990Smjacobmpt_configure_ioc(struct mpt_softc *mpt, int tn, int needreset) 2598147883Sscottl{ 2599164990Smjacob PTR_MSG_PORT_FACTS_REPLY pfp; 2600209599Sken int error, port, val; 2601164990Smjacob size_t len; 2602147883Sscottl 2603164990Smjacob if (tn == MPT_MAX_TRYS) { 2604164990Smjacob return (-1); 2605164990Smjacob } 2606147883Sscottl 2607164990Smjacob /* 2608164990Smjacob * No need to reset if the IOC is already in the READY state. 2609164990Smjacob * 2610164990Smjacob * Force reset if initialization failed previously. 2611164990Smjacob * Note that a hard_reset of the second channel of a '929 2612164990Smjacob * will stop operation of the first channel. Hopefully, if the 2613164990Smjacob * first channel is ok, the second will not require a hard 2614164990Smjacob * reset. 2615164990Smjacob */ 2616164990Smjacob if (needreset || MPT_STATE(mpt_rd_db(mpt)) != MPT_DB_STATE_READY) { 2617164990Smjacob if (mpt_reset(mpt, FALSE) != MPT_OK) { 2618164990Smjacob return (mpt_configure_ioc(mpt, tn++, 1)); 2619101704Smjacob } 2620147883Sscottl needreset = 0; 2621164990Smjacob } 2622101704Smjacob 2623164990Smjacob if (mpt_get_iocfacts(mpt, &mpt->ioc_facts) != MPT_OK) { 2624164990Smjacob mpt_prt(mpt, "mpt_get_iocfacts failed\n"); 2625164990Smjacob return (mpt_configure_ioc(mpt, tn++, 1)); 2626164990Smjacob } 2627164990Smjacob mpt2host_iocfacts_reply(&mpt->ioc_facts); 2628102199Smjacob 2629164990Smjacob mpt_prt(mpt, "MPI Version=%d.%d.%d.%d\n", 2630164990Smjacob mpt->ioc_facts.MsgVersion >> 8, 2631164990Smjacob mpt->ioc_facts.MsgVersion & 0xFF, 2632164990Smjacob mpt->ioc_facts.HeaderVersion >> 8, 2633164990Smjacob mpt->ioc_facts.HeaderVersion & 0xFF); 2634155521Smjacob 2635164990Smjacob /* 2636164990Smjacob * Now that we know request frame size, we can calculate 2637164990Smjacob * the actual (reasonable) segment limit for read/write I/O. 2638164990Smjacob * 2639164990Smjacob * This limit is constrained by: 2640164990Smjacob * 2641164990Smjacob * + The size of each area we allocate per command (and how 2642164990Smjacob * many chain segments we can fit into it). 2643164990Smjacob * + The total number of areas we've set up. 2644164990Smjacob * + The actual chain depth the card will allow. 2645164990Smjacob * 2646164990Smjacob * The first area's segment count is limited by the I/O request 2647164990Smjacob * at the head of it. We cannot allocate realistically more 2648164990Smjacob * than MPT_MAX_REQUESTS areas. Therefore, to account for both 2649164990Smjacob * conditions, we'll just start out with MPT_MAX_REQUESTS-2. 2650164990Smjacob * 2651164990Smjacob */ 2652164990Smjacob /* total number of request areas we (can) allocate */ 2653164990Smjacob mpt->max_seg_cnt = MPT_MAX_REQUESTS(mpt) - 2; 2654155521Smjacob 2655164990Smjacob /* converted to the number of chain areas possible */ 2656164990Smjacob mpt->max_seg_cnt *= MPT_NRFM(mpt); 2657155521Smjacob 2658164990Smjacob /* limited by the number of chain areas the card will support */ 2659164990Smjacob if (mpt->max_seg_cnt > mpt->ioc_facts.MaxChainDepth) { 2660209599Sken mpt_lprt(mpt, MPT_PRT_INFO, 2661164990Smjacob "chain depth limited to %u (from %u)\n", 2662164990Smjacob mpt->ioc_facts.MaxChainDepth, mpt->max_seg_cnt); 2663164990Smjacob mpt->max_seg_cnt = mpt->ioc_facts.MaxChainDepth; 2664164990Smjacob } 2665155521Smjacob 2666164990Smjacob /* converted to the number of simple sges in chain segments. */ 2667164990Smjacob mpt->max_seg_cnt *= (MPT_NSGL(mpt) - 1); 2668155521Smjacob 2669209599Sken /* 2670209599Sken * Use this as the basis for reporting the maximum I/O size to CAM. 2671209599Sken */ 2672209599Sken mpt->max_cam_seg_cnt = min(mpt->max_seg_cnt, (MAXPHYS / PAGE_SIZE) + 1); 2673209599Sken 2674209599Sken error = mpt_dma_buf_alloc(mpt); 2675209599Sken if (error != 0) { 2676209599Sken mpt_prt(mpt, "mpt_dma_buf_alloc() failed!\n"); 2677209599Sken return (EIO); 2678209599Sken } 2679209599Sken 2680209599Sken for (val = 0; val < MPT_MAX_REQUESTS(mpt); val++) { 2681209599Sken request_t *req = &mpt->request_pool[val]; 2682209599Sken req->state = REQ_STATE_ALLOCATED; 2683209599Sken mpt_callout_init(mpt, &req->callout); 2684209599Sken mpt_free_request(mpt, req); 2685209599Sken } 2686209599Sken 2687209599Sken mpt_lprt(mpt, MPT_PRT_INFO, "Maximum Segment Count: %u, Maximum " 2688209599Sken "CAM Segment Count: %u\n", mpt->max_seg_cnt, 2689209599Sken mpt->max_cam_seg_cnt); 2690209599Sken 2691209599Sken mpt_lprt(mpt, MPT_PRT_INFO, "MsgLength=%u IOCNumber = %d\n", 2692164990Smjacob mpt->ioc_facts.MsgLength, mpt->ioc_facts.IOCNumber); 2693209599Sken mpt_lprt(mpt, MPT_PRT_INFO, 2694164990Smjacob "IOCFACTS: GlobalCredits=%d BlockSize=%u bytes " 2695164990Smjacob "Request Frame Size %u bytes Max Chain Depth %u\n", 2696164990Smjacob mpt->ioc_facts.GlobalCredits, mpt->ioc_facts.BlockSize, 2697164990Smjacob mpt->ioc_facts.RequestFrameSize << 2, 2698164990Smjacob mpt->ioc_facts.MaxChainDepth); 2699209599Sken mpt_lprt(mpt, MPT_PRT_INFO, "IOCFACTS: Num Ports %d, FWImageSize %d, " 2700164990Smjacob "Flags=%#x\n", mpt->ioc_facts.NumberOfPorts, 2701164990Smjacob mpt->ioc_facts.FWImageSize, mpt->ioc_facts.Flags); 2702155521Smjacob 2703164990Smjacob len = mpt->ioc_facts.NumberOfPorts * sizeof (MSG_PORT_FACTS_REPLY); 2704164990Smjacob mpt->port_facts = malloc(len, M_DEVBUF, M_NOWAIT | M_ZERO); 2705164990Smjacob if (mpt->port_facts == NULL) { 2706164990Smjacob mpt_prt(mpt, "unable to allocate memory for port facts\n"); 2707164990Smjacob return (ENOMEM); 2708164990Smjacob } 2709147883Sscottl 2710155521Smjacob 2711164990Smjacob if ((mpt->ioc_facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT) && 2712164990Smjacob (mpt->fw_uploaded == 0)) { 2713164990Smjacob struct mpt_map_info mi; 2714147883Sscottl 2715164990Smjacob /* 2716164990Smjacob * In some configurations, the IOC's firmware is 2717164990Smjacob * stored in a shared piece of system NVRAM that 2718220945Smarius * is only accessible via the BIOS. In this 2719164990Smjacob * case, the firmware keeps a copy of firmware in 2720164990Smjacob * RAM until the OS driver retrieves it. Once 2721164990Smjacob * retrieved, we are responsible for re-downloading 2722164990Smjacob * the firmware after any hard-reset. 2723164990Smjacob */ 2724164990Smjacob mpt->fw_image_size = mpt->ioc_facts.FWImageSize; 2725164990Smjacob error = mpt_dma_tag_create(mpt, mpt->parent_dmat, 1, 0, 2726164990Smjacob BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL, 2727164990Smjacob mpt->fw_image_size, 1, mpt->fw_image_size, 0, 2728164990Smjacob &mpt->fw_dmat); 2729164990Smjacob if (error != 0) { 2730219335Smarius mpt_prt(mpt, "cannot create firmware dma tag\n"); 2731164990Smjacob return (ENOMEM); 2732101704Smjacob } 2733164990Smjacob error = bus_dmamem_alloc(mpt->fw_dmat, 2734219335Smarius (void **)&mpt->fw_image, BUS_DMA_NOWAIT | 2735219335Smarius BUS_DMA_COHERENT, &mpt->fw_dmap); 2736164990Smjacob if (error != 0) { 2737164990Smjacob mpt_prt(mpt, "cannot allocate firmware memory\n"); 2738164990Smjacob bus_dma_tag_destroy(mpt->fw_dmat); 2739164990Smjacob return (ENOMEM); 2740164990Smjacob } 2741164990Smjacob mi.mpt = mpt; 2742164990Smjacob mi.error = 0; 2743164990Smjacob bus_dmamap_load(mpt->fw_dmat, mpt->fw_dmap, 2744164990Smjacob mpt->fw_image, mpt->fw_image_size, mpt_map_rquest, &mi, 0); 2745164990Smjacob mpt->fw_phys = mi.phys; 2746101704Smjacob 2747164990Smjacob error = mpt_upload_fw(mpt); 2748164990Smjacob if (error != 0) { 2749164990Smjacob mpt_prt(mpt, "firmware upload failed.\n"); 2750164990Smjacob bus_dmamap_unload(mpt->fw_dmat, mpt->fw_dmap); 2751164990Smjacob bus_dmamem_free(mpt->fw_dmat, mpt->fw_image, 2752164990Smjacob mpt->fw_dmap); 2753164990Smjacob bus_dma_tag_destroy(mpt->fw_dmat); 2754164990Smjacob mpt->fw_image = NULL; 2755164990Smjacob return (EIO); 2756102199Smjacob } 2757164990Smjacob mpt->fw_uploaded = 1; 2758164990Smjacob } 2759102199Smjacob 2760164990Smjacob for (port = 0; port < mpt->ioc_facts.NumberOfPorts; port++) { 2761164990Smjacob pfp = &mpt->port_facts[port]; 2762164990Smjacob error = mpt_get_portfacts(mpt, 0, pfp); 2763164990Smjacob if (error != MPT_OK) { 2764164990Smjacob mpt_prt(mpt, 2765164990Smjacob "mpt_get_portfacts on port %d failed\n", port); 2766164990Smjacob free(mpt->port_facts, M_DEVBUF); 2767164990Smjacob mpt->port_facts = NULL; 2768164990Smjacob return (mpt_configure_ioc(mpt, tn++, 1)); 2769102199Smjacob } 2770164990Smjacob mpt2host_portfacts_reply(pfp); 2771157117Smjacob 2772164990Smjacob if (port > 0) { 2773164990Smjacob error = MPT_PRT_INFO; 2774102199Smjacob } else { 2775164990Smjacob error = MPT_PRT_DEBUG; 2776102199Smjacob } 2777164990Smjacob mpt_lprt(mpt, error, 2778164990Smjacob "PORTFACTS[%d]: Type %x PFlags %x IID %d MaxDev %d\n", 2779164990Smjacob port, pfp->PortType, pfp->ProtocolFlags, pfp->PortSCSIID, 2780164990Smjacob pfp->MaxDevices); 2781102199Smjacob 2782164990Smjacob } 2783157117Smjacob 2784164990Smjacob /* 2785164990Smjacob * XXX: Not yet supporting more than port 0 2786164990Smjacob */ 2787164990Smjacob pfp = &mpt->port_facts[0]; 2788164990Smjacob if (pfp->PortType == MPI_PORTFACTS_PORTTYPE_FC) { 2789164990Smjacob mpt->is_fc = 1; 2790164990Smjacob mpt->is_sas = 0; 2791164990Smjacob mpt->is_spi = 0; 2792164990Smjacob } else if (pfp->PortType == MPI_PORTFACTS_PORTTYPE_SAS) { 2793164990Smjacob mpt->is_fc = 0; 2794164990Smjacob mpt->is_sas = 1; 2795164990Smjacob mpt->is_spi = 0; 2796164990Smjacob } else if (pfp->PortType == MPI_PORTFACTS_PORTTYPE_SCSI) { 2797164990Smjacob mpt->is_fc = 0; 2798164990Smjacob mpt->is_sas = 0; 2799164990Smjacob mpt->is_spi = 1; 2800207287Smarius if (mpt->mpt_ini_id == MPT_INI_ID_NONE) 2801207287Smarius mpt->mpt_ini_id = pfp->PortSCSIID; 2802164990Smjacob } else if (pfp->PortType == MPI_PORTFACTS_PORTTYPE_ISCSI) { 2803164990Smjacob mpt_prt(mpt, "iSCSI not supported yet\n"); 2804164990Smjacob return (ENXIO); 2805164990Smjacob } else if (pfp->PortType == MPI_PORTFACTS_PORTTYPE_INACTIVE) { 2806164990Smjacob mpt_prt(mpt, "Inactive Port\n"); 2807164990Smjacob return (ENXIO); 2808164990Smjacob } else { 2809164990Smjacob mpt_prt(mpt, "unknown Port Type %#x\n", pfp->PortType); 2810164990Smjacob return (ENXIO); 2811164990Smjacob } 2812101704Smjacob 2813164990Smjacob /* 2814164990Smjacob * Set our role with what this port supports. 2815164990Smjacob * 2816164990Smjacob * Note this might be changed later in different modules 2817164990Smjacob * if this is different from what is wanted. 2818164990Smjacob */ 2819164990Smjacob mpt->role = MPT_ROLE_NONE; 2820164990Smjacob if (pfp->ProtocolFlags & MPI_PORTFACTS_PROTOCOL_INITIATOR) { 2821164990Smjacob mpt->role |= MPT_ROLE_INITIATOR; 2822101704Smjacob } 2823164990Smjacob if (pfp->ProtocolFlags & MPI_PORTFACTS_PROTOCOL_TARGET) { 2824164990Smjacob mpt->role |= MPT_ROLE_TARGET; 2825164990Smjacob } 2826101704Smjacob 2827164990Smjacob /* 2828164990Smjacob * Enable the IOC 2829164990Smjacob */ 2830177808Sscottl if (mpt_enable_ioc(mpt, 1) != MPT_OK) { 2831164990Smjacob mpt_prt(mpt, "unable to initialize IOC\n"); 2832164990Smjacob return (ENXIO); 2833101704Smjacob } 2834101704Smjacob 2835164990Smjacob /* 2836164990Smjacob * Read IOC configuration information. 2837164990Smjacob * 2838164990Smjacob * We need this to determine whether or not we have certain 2839164990Smjacob * settings for Integrated Mirroring (e.g.). 2840164990Smjacob */ 2841164990Smjacob mpt_read_config_info_ioc(mpt); 2842164990Smjacob 2843101704Smjacob return (0); 2844101704Smjacob} 2845147883Sscottl 2846147883Sscottlstatic int 2847157117Smjacobmpt_enable_ioc(struct mpt_softc *mpt, int portenable) 2848147883Sscottl{ 2849147883Sscottl uint32_t pptr; 2850147883Sscottl int val; 2851147883Sscottl 2852155521Smjacob if (mpt_send_ioc_init(mpt, MPI_WHOINIT_HOST_DRIVER) != MPT_OK) { 2853147883Sscottl mpt_prt(mpt, "mpt_send_ioc_init failed\n"); 2854147883Sscottl return (EIO); 2855147883Sscottl } 2856147883Sscottl 2857147883Sscottl mpt_lprt(mpt, MPT_PRT_DEBUG, "mpt_send_ioc_init ok\n"); 2858147883Sscottl 2859147883Sscottl if (mpt_wait_state(mpt, MPT_DB_STATE_RUNNING) != MPT_OK) { 2860147883Sscottl mpt_prt(mpt, "IOC failed to go to run state\n"); 2861147883Sscottl return (ENXIO); 2862147883Sscottl } 2863155521Smjacob mpt_lprt(mpt, MPT_PRT_DEBUG, "IOC now at RUNSTATE\n"); 2864147883Sscottl 2865147883Sscottl /* 2866147883Sscottl * Give it reply buffers 2867147883Sscottl * 2868147883Sscottl * Do *not* exceed global credits. 2869147883Sscottl */ 2870156104Smjacob for (val = 0, pptr = mpt->reply_phys; 2871156104Smjacob (pptr + MPT_REPLY_SIZE) < (mpt->reply_phys + PAGE_SIZE); 2872147883Sscottl pptr += MPT_REPLY_SIZE) { 2873147883Sscottl mpt_free_reply(mpt, pptr); 2874164990Smjacob if (++val == mpt->ioc_facts.GlobalCredits - 1) 2875147883Sscottl break; 2876147883Sscottl } 2877147883Sscottl 2878157117Smjacob 2879147883Sscottl /* 2880157354Smjacob * Enable the port if asked. This is only done if we're resetting 2881157354Smjacob * the IOC after initial startup. 2882147883Sscottl */ 2883157117Smjacob if (portenable) { 2884157117Smjacob /* 2885157117Smjacob * Enable asynchronous event reporting 2886157117Smjacob */ 2887157117Smjacob mpt_send_event_request(mpt, 1); 2888147883Sscottl 2889157117Smjacob if (mpt_send_port_enable(mpt, 0) != MPT_OK) { 2890209599Sken mpt_prt(mpt, "%s: failed to enable port 0\n", __func__); 2891157117Smjacob return (ENXIO); 2892157117Smjacob } 2893147883Sscottl } 2894156104Smjacob return (MPT_OK); 2895147883Sscottl} 2896164990Smjacob 2897164990Smjacob/* 2898164990Smjacob * Endian Conversion Functions- only used on Big Endian machines 2899164990Smjacob */ 2900164990Smjacob#if _BYTE_ORDER == _BIG_ENDIAN 2901164990Smjacobvoid 2902164990Smjacobmpt2host_sge_simple_union(SGE_SIMPLE_UNION *sge) 2903164990Smjacob{ 2904186878Smarius 2905164990Smjacob MPT_2_HOST32(sge, FlagsLength); 2906164998Smjacob MPT_2_HOST32(sge, u.Address64.Low); 2907164998Smjacob MPT_2_HOST32(sge, u.Address64.High); 2908164998Smjacob} 2909164990Smjacob 2910164990Smjacobvoid 2911164990Smjacobmpt2host_iocfacts_reply(MSG_IOC_FACTS_REPLY *rp) 2912164990Smjacob{ 2913186878Smarius 2914164990Smjacob MPT_2_HOST16(rp, MsgVersion); 2915164990Smjacob MPT_2_HOST16(rp, HeaderVersion); 2916164990Smjacob MPT_2_HOST32(rp, MsgContext); 2917164990Smjacob MPT_2_HOST16(rp, IOCExceptions); 2918164990Smjacob MPT_2_HOST16(rp, IOCStatus); 2919164990Smjacob MPT_2_HOST32(rp, IOCLogInfo); 2920164990Smjacob MPT_2_HOST16(rp, ReplyQueueDepth); 2921164990Smjacob MPT_2_HOST16(rp, RequestFrameSize); 2922164990Smjacob MPT_2_HOST16(rp, Reserved_0101_FWVersion); 2923164990Smjacob MPT_2_HOST16(rp, ProductID); 2924164990Smjacob MPT_2_HOST32(rp, CurrentHostMfaHighAddr); 2925164990Smjacob MPT_2_HOST16(rp, GlobalCredits); 2926164990Smjacob MPT_2_HOST32(rp, CurrentSenseBufferHighAddr); 2927164990Smjacob MPT_2_HOST16(rp, CurReplyFrameSize); 2928164990Smjacob MPT_2_HOST32(rp, FWImageSize); 2929164990Smjacob MPT_2_HOST32(rp, IOCCapabilities); 2930164990Smjacob MPT_2_HOST32(rp, FWVersion.Word); 2931164990Smjacob MPT_2_HOST16(rp, HighPriorityQueueDepth); 2932164990Smjacob MPT_2_HOST16(rp, Reserved2); 2933164990Smjacob mpt2host_sge_simple_union(&rp->HostPageBufferSGE); 2934164990Smjacob MPT_2_HOST32(rp, ReplyFifoHostSignalingAddr); 2935164990Smjacob} 2936164990Smjacob 2937164990Smjacobvoid 2938164990Smjacobmpt2host_portfacts_reply(MSG_PORT_FACTS_REPLY *pfp) 2939164990Smjacob{ 2940186878Smarius 2941164990Smjacob MPT_2_HOST16(pfp, Reserved); 2942164990Smjacob MPT_2_HOST16(pfp, Reserved1); 2943164990Smjacob MPT_2_HOST32(pfp, MsgContext); 2944164990Smjacob MPT_2_HOST16(pfp, Reserved2); 2945164990Smjacob MPT_2_HOST16(pfp, IOCStatus); 2946164990Smjacob MPT_2_HOST32(pfp, IOCLogInfo); 2947164990Smjacob MPT_2_HOST16(pfp, MaxDevices); 2948164990Smjacob MPT_2_HOST16(pfp, PortSCSIID); 2949164990Smjacob MPT_2_HOST16(pfp, ProtocolFlags); 2950164990Smjacob MPT_2_HOST16(pfp, MaxPostedCmdBuffers); 2951164990Smjacob MPT_2_HOST16(pfp, MaxPersistentIDs); 2952164990Smjacob MPT_2_HOST16(pfp, MaxLanBuckets); 2953164990Smjacob MPT_2_HOST16(pfp, Reserved4); 2954164990Smjacob MPT_2_HOST32(pfp, Reserved5); 2955164990Smjacob} 2956186878Smarius 2957164990Smjacobvoid 2958164990Smjacobmpt2host_config_page_ioc2(CONFIG_PAGE_IOC_2 *ioc2) 2959164990Smjacob{ 2960164990Smjacob int i; 2961186878Smarius 2962186878Smarius MPT_2_HOST32(ioc2, CapabilitiesFlags); 2963164990Smjacob for (i = 0; i < MPI_IOC_PAGE_2_RAID_VOLUME_MAX; i++) { 2964164998Smjacob MPT_2_HOST16(ioc2, RaidVolume[i].Reserved3); 2965164990Smjacob } 2966164990Smjacob} 2967164990Smjacob 2968164990Smjacobvoid 2969186878Smariusmpt2host_config_page_ioc3(CONFIG_PAGE_IOC_3 *ioc3) 2970186878Smarius{ 2971186878Smarius 2972186878Smarius MPT_2_HOST16(ioc3, Reserved2); 2973186878Smarius} 2974186878Smarius 2975186878Smariusvoid 2976186878Smariusmpt2host_config_page_scsi_port_0(CONFIG_PAGE_SCSI_PORT_0 *sp0) 2977186878Smarius{ 2978186878Smarius 2979186878Smarius MPT_2_HOST32(sp0, Capabilities); 2980186878Smarius MPT_2_HOST32(sp0, PhysicalInterface); 2981186878Smarius} 2982186878Smarius 2983186878Smariusvoid 2984186878Smariusmpt2host_config_page_scsi_port_1(CONFIG_PAGE_SCSI_PORT_1 *sp1) 2985186878Smarius{ 2986186878Smarius 2987186878Smarius MPT_2_HOST32(sp1, Configuration); 2988186878Smarius MPT_2_HOST32(sp1, OnBusTimerValue); 2989186878Smarius MPT_2_HOST16(sp1, IDConfig); 2990186878Smarius} 2991186878Smarius 2992186878Smariusvoid 2993186878Smariushost2mpt_config_page_scsi_port_1(CONFIG_PAGE_SCSI_PORT_1 *sp1) 2994186878Smarius{ 2995186878Smarius 2996186878Smarius HOST_2_MPT32(sp1, Configuration); 2997186878Smarius HOST_2_MPT32(sp1, OnBusTimerValue); 2998186878Smarius HOST_2_MPT16(sp1, IDConfig); 2999186878Smarius} 3000186878Smarius 3001186878Smariusvoid 3002186878Smariusmpt2host_config_page_scsi_port_2(CONFIG_PAGE_SCSI_PORT_2 *sp2) 3003186878Smarius{ 3004186878Smarius int i; 3005186878Smarius 3006186878Smarius MPT_2_HOST32(sp2, PortFlags); 3007186878Smarius MPT_2_HOST32(sp2, PortSettings); 3008186878Smarius for (i = 0; i < sizeof(sp2->DeviceSettings) / 3009186878Smarius sizeof(*sp2->DeviceSettings); i++) { 3010186878Smarius MPT_2_HOST16(sp2, DeviceSettings[i].DeviceFlags); 3011186878Smarius } 3012186878Smarius} 3013186878Smarius 3014186878Smariusvoid 3015186878Smariusmpt2host_config_page_scsi_device_0(CONFIG_PAGE_SCSI_DEVICE_0 *sd0) 3016186878Smarius{ 3017186878Smarius 3018186878Smarius MPT_2_HOST32(sd0, NegotiatedParameters); 3019186878Smarius MPT_2_HOST32(sd0, Information); 3020186878Smarius} 3021186878Smarius 3022186878Smariusvoid 3023186878Smariusmpt2host_config_page_scsi_device_1(CONFIG_PAGE_SCSI_DEVICE_1 *sd1) 3024186878Smarius{ 3025186878Smarius 3026186878Smarius MPT_2_HOST32(sd1, RequestedParameters); 3027186878Smarius MPT_2_HOST32(sd1, Reserved); 3028186878Smarius MPT_2_HOST32(sd1, Configuration); 3029186878Smarius} 3030186878Smarius 3031186878Smariusvoid 3032186878Smariushost2mpt_config_page_scsi_device_1(CONFIG_PAGE_SCSI_DEVICE_1 *sd1) 3033186878Smarius{ 3034186878Smarius 3035186878Smarius HOST_2_MPT32(sd1, RequestedParameters); 3036186878Smarius HOST_2_MPT32(sd1, Reserved); 3037186878Smarius HOST_2_MPT32(sd1, Configuration); 3038186878Smarius} 3039186878Smarius 3040186878Smariusvoid 3041186878Smariusmpt2host_config_page_fc_port_0(CONFIG_PAGE_FC_PORT_0 *fp0) 3042186878Smarius{ 3043186878Smarius 3044186878Smarius MPT_2_HOST32(fp0, Flags); 3045186878Smarius MPT_2_HOST32(fp0, PortIdentifier); 3046186878Smarius MPT_2_HOST32(fp0, WWNN.Low); 3047186878Smarius MPT_2_HOST32(fp0, WWNN.High); 3048186878Smarius MPT_2_HOST32(fp0, WWPN.Low); 3049186878Smarius MPT_2_HOST32(fp0, WWPN.High); 3050186878Smarius MPT_2_HOST32(fp0, SupportedServiceClass); 3051186878Smarius MPT_2_HOST32(fp0, SupportedSpeeds); 3052186878Smarius MPT_2_HOST32(fp0, CurrentSpeed); 3053186878Smarius MPT_2_HOST32(fp0, MaxFrameSize); 3054186878Smarius MPT_2_HOST32(fp0, FabricWWNN.Low); 3055186878Smarius MPT_2_HOST32(fp0, FabricWWNN.High); 3056186878Smarius MPT_2_HOST32(fp0, FabricWWPN.Low); 3057186878Smarius MPT_2_HOST32(fp0, FabricWWPN.High); 3058186878Smarius MPT_2_HOST32(fp0, DiscoveredPortsCount); 3059186878Smarius MPT_2_HOST32(fp0, MaxInitiators); 3060186878Smarius} 3061186878Smarius 3062186878Smariusvoid 3063186878Smariusmpt2host_config_page_fc_port_1(CONFIG_PAGE_FC_PORT_1 *fp1) 3064186878Smarius{ 3065186878Smarius 3066186878Smarius MPT_2_HOST32(fp1, Flags); 3067186878Smarius MPT_2_HOST32(fp1, NoSEEPROMWWNN.Low); 3068186878Smarius MPT_2_HOST32(fp1, NoSEEPROMWWNN.High); 3069186878Smarius MPT_2_HOST32(fp1, NoSEEPROMWWPN.Low); 3070186878Smarius MPT_2_HOST32(fp1, NoSEEPROMWWPN.High); 3071186878Smarius} 3072186878Smarius 3073186878Smariusvoid 3074186878Smariushost2mpt_config_page_fc_port_1(CONFIG_PAGE_FC_PORT_1 *fp1) 3075186878Smarius{ 3076186878Smarius 3077186878Smarius HOST_2_MPT32(fp1, Flags); 3078186878Smarius HOST_2_MPT32(fp1, NoSEEPROMWWNN.Low); 3079186878Smarius HOST_2_MPT32(fp1, NoSEEPROMWWNN.High); 3080186878Smarius HOST_2_MPT32(fp1, NoSEEPROMWWPN.Low); 3081186878Smarius HOST_2_MPT32(fp1, NoSEEPROMWWPN.High); 3082186878Smarius} 3083186878Smarius 3084186878Smariusvoid 3085164990Smjacobmpt2host_config_page_raid_vol_0(CONFIG_PAGE_RAID_VOL_0 *volp) 3086164990Smjacob{ 3087164990Smjacob int i; 3088186878Smarius 3089164990Smjacob MPT_2_HOST16(volp, VolumeStatus.Reserved); 3090164990Smjacob MPT_2_HOST16(volp, VolumeSettings.Settings); 3091164990Smjacob MPT_2_HOST32(volp, MaxLBA); 3092170276Sscottl MPT_2_HOST32(volp, MaxLBAHigh); 3093164990Smjacob MPT_2_HOST32(volp, StripeSize); 3094164990Smjacob MPT_2_HOST32(volp, Reserved2); 3095164990Smjacob MPT_2_HOST32(volp, Reserved3); 3096164990Smjacob for (i = 0; i < MPI_RAID_VOL_PAGE_0_PHYSDISK_MAX; i++) { 3097164998Smjacob MPT_2_HOST16(volp, PhysDisk[i].Reserved); 3098164990Smjacob } 3099164990Smjacob} 3100164990Smjacob 3101164990Smjacobvoid 3102186878Smariusmpt2host_config_page_raid_phys_disk_0(CONFIG_PAGE_RAID_PHYS_DISK_0 *rpd0) 3103186878Smarius{ 3104186878Smarius 3105186878Smarius MPT_2_HOST32(rpd0, Reserved1); 3106186878Smarius MPT_2_HOST16(rpd0, PhysDiskStatus.Reserved); 3107186878Smarius MPT_2_HOST32(rpd0, MaxLBA); 3108186878Smarius MPT_2_HOST16(rpd0, ErrorData.Reserved); 3109186878Smarius MPT_2_HOST16(rpd0, ErrorData.ErrorCount); 3110186878Smarius MPT_2_HOST16(rpd0, ErrorData.SmartCount); 3111186878Smarius} 3112186878Smarius 3113186878Smariusvoid 3114164990Smjacobmpt2host_mpi_raid_vol_indicator(MPI_RAID_VOL_INDICATOR *vi) 3115164990Smjacob{ 3116186878Smarius 3117164998Smjacob MPT_2_HOST16(vi, TotalBlocks.High); 3118164998Smjacob MPT_2_HOST16(vi, TotalBlocks.Low); 3119164998Smjacob MPT_2_HOST16(vi, BlocksRemaining.High); 3120164998Smjacob MPT_2_HOST16(vi, BlocksRemaining.Low); 3121164990Smjacob} 3122164990Smjacob#endif 3123