| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1 | /******************************************************************* |
| 2 | * This file is part of the Emulex Linux Device Driver for * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 3 | * Fibre Channel Host Bus Adapters. * |
James Smart | 9413aff | 2007-04-25 09:53:35 -0400 | [diff] [blame] | 4 | * Copyright (C) 2004-2007 Emulex. All rights reserved. * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 5 | * EMULEX and SLI are trademarks of Emulex. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6 | * www.emulex.com * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8 | * * |
| 9 | * This program is free software; you can redistribute it and/or * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 10 | * modify it under the terms of version 2 of the GNU General * |
| 11 | * Public License as published by the Free Software Foundation. * |
| 12 | * This program is distributed in the hope that it will be useful. * |
| 13 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * |
| 14 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * |
| 15 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * |
| 16 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * |
| 17 | * TO BE LEGALLY INVALID. See the GNU General Public License for * |
| 18 | * more details, a copy of which can be found in the file COPYING * |
| 19 | * included with this package. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 20 | *******************************************************************/ |
| 21 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 22 | #include <linux/blkdev.h> |
| 23 | #include <linux/pci.h> |
| 24 | #include <linux/interrupt.h> |
| 25 | |
James.Smart@Emulex.Com | f888ba3 | 2005-08-10 15:03:01 -0400 | [diff] [blame] | 26 | #include <scsi/scsi_device.h> |
| 27 | #include <scsi/scsi_transport_fc.h> |
| 28 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 29 | #include <scsi/scsi.h> |
| 30 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 31 | #include "lpfc_hw.h" |
| 32 | #include "lpfc_sli.h" |
| 33 | #include "lpfc_disc.h" |
| 34 | #include "lpfc_scsi.h" |
| 35 | #include "lpfc.h" |
| 36 | #include "lpfc_logmsg.h" |
| 37 | #include "lpfc_crtn.h" |
| 38 | #include "lpfc_compat.h" |
| 39 | |
| 40 | /**********************************************/ |
| 41 | |
| 42 | /* mailbox command */ |
| 43 | /**********************************************/ |
| 44 | void |
| 45 | lpfc_dump_mem(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, uint16_t offset) |
| 46 | { |
| 47 | MAILBOX_t *mb; |
| 48 | void *ctx; |
| 49 | |
| 50 | mb = &pmb->mb; |
| 51 | ctx = pmb->context2; |
| 52 | |
| 53 | /* Setup to dump VPD region */ |
| 54 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 55 | mb->mbxCommand = MBX_DUMP_MEMORY; |
| 56 | mb->un.varDmp.cv = 1; |
| 57 | mb->un.varDmp.type = DMP_NV_PARAMS; |
| 58 | mb->un.varDmp.entry_index = offset; |
| 59 | mb->un.varDmp.region_id = DMP_REGION_VPD; |
| 60 | mb->un.varDmp.word_cnt = (DMP_RSP_SIZE / sizeof (uint32_t)); |
| 61 | mb->un.varDmp.co = 0; |
| 62 | mb->un.varDmp.resp_offset = 0; |
| 63 | pmb->context2 = ctx; |
| 64 | mb->mbxOwner = OWN_HOST; |
| 65 | return; |
| 66 | } |
| 67 | |
| 68 | /**********************************************/ |
| 69 | /* lpfc_read_nv Issue a READ NVPARAM */ |
| 70 | /* mailbox command */ |
| 71 | /**********************************************/ |
| 72 | void |
| 73 | lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 74 | { |
| 75 | MAILBOX_t *mb; |
| 76 | |
| 77 | mb = &pmb->mb; |
| 78 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 79 | mb->mbxCommand = MBX_READ_NV; |
| 80 | mb->mbxOwner = OWN_HOST; |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | /**********************************************/ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 85 | /* lpfc_config_async Issue a */ |
| 86 | /* MBX_ASYNC_EVT_ENABLE mailbox command */ |
| 87 | /**********************************************/ |
| 88 | void |
| 89 | lpfc_config_async(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, |
| 90 | uint32_t ring) |
| 91 | { |
| 92 | MAILBOX_t *mb; |
| 93 | |
| 94 | mb = &pmb->mb; |
| 95 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 96 | mb->mbxCommand = MBX_ASYNCEVT_ENABLE; |
| 97 | mb->un.varCfgAsyncEvent.ring = ring; |
| 98 | mb->mbxOwner = OWN_HOST; |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | /**********************************************/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 103 | /* lpfc_heart_beat Issue a HEART_BEAT */ |
| 104 | /* mailbox command */ |
| 105 | /**********************************************/ |
| 106 | void |
| 107 | lpfc_heart_beat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 108 | { |
| 109 | MAILBOX_t *mb; |
| 110 | |
| 111 | mb = &pmb->mb; |
| 112 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 113 | mb->mbxCommand = MBX_HEARTBEAT; |
| 114 | mb->mbxOwner = OWN_HOST; |
| 115 | return; |
| 116 | } |
| 117 | |
| 118 | /**********************************************/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 119 | /* lpfc_read_la Issue a READ LA */ |
| 120 | /* mailbox command */ |
| 121 | /**********************************************/ |
| 122 | int |
| 123 | lpfc_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, struct lpfc_dmabuf *mp) |
| 124 | { |
| 125 | MAILBOX_t *mb; |
| 126 | struct lpfc_sli *psli; |
| 127 | |
| 128 | psli = &phba->sli; |
| 129 | mb = &pmb->mb; |
| 130 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 131 | |
| 132 | INIT_LIST_HEAD(&mp->list); |
| 133 | mb->mbxCommand = MBX_READ_LA64; |
| 134 | mb->un.varReadLA.un.lilpBde64.tus.f.bdeSize = 128; |
| 135 | mb->un.varReadLA.un.lilpBde64.addrHigh = putPaddrHigh(mp->phys); |
| 136 | mb->un.varReadLA.un.lilpBde64.addrLow = putPaddrLow(mp->phys); |
| 137 | |
| 138 | /* Save address for later completion and set the owner to host so that |
| 139 | * the FW knows this mailbox is available for processing. |
| 140 | */ |
| 141 | pmb->context1 = (uint8_t *) mp; |
| 142 | mb->mbxOwner = OWN_HOST; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 143 | return (0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | /**********************************************/ |
| 147 | /* lpfc_clear_la Issue a CLEAR LA */ |
| 148 | /* mailbox command */ |
| 149 | /**********************************************/ |
| 150 | void |
| 151 | lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 152 | { |
| 153 | MAILBOX_t *mb; |
| 154 | |
| 155 | mb = &pmb->mb; |
| 156 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 157 | |
| 158 | mb->un.varClearLA.eventTag = phba->fc_eventTag; |
| 159 | mb->mbxCommand = MBX_CLEAR_LA; |
| 160 | mb->mbxOwner = OWN_HOST; |
| 161 | return; |
| 162 | } |
| 163 | |
| 164 | /**************************************************/ |
| 165 | /* lpfc_config_link Issue a CONFIG LINK */ |
| 166 | /* mailbox command */ |
| 167 | /**************************************************/ |
| 168 | void |
| 169 | lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 170 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 171 | struct lpfc_vport *vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 172 | MAILBOX_t *mb = &pmb->mb; |
| 173 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 174 | |
| 175 | /* NEW_FEATURE |
| 176 | * SLI-2, Coalescing Response Feature. |
| 177 | */ |
| 178 | if (phba->cfg_cr_delay) { |
| 179 | mb->un.varCfgLnk.cr = 1; |
| 180 | mb->un.varCfgLnk.ci = 1; |
| 181 | mb->un.varCfgLnk.cr_delay = phba->cfg_cr_delay; |
| 182 | mb->un.varCfgLnk.cr_count = phba->cfg_cr_count; |
| 183 | } |
| 184 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 185 | mb->un.varCfgLnk.myId = vport->fc_myDID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 186 | mb->un.varCfgLnk.edtov = phba->fc_edtov; |
| 187 | mb->un.varCfgLnk.arbtov = phba->fc_arbtov; |
| 188 | mb->un.varCfgLnk.ratov = phba->fc_ratov; |
| 189 | mb->un.varCfgLnk.rttov = phba->fc_rttov; |
| 190 | mb->un.varCfgLnk.altov = phba->fc_altov; |
| 191 | mb->un.varCfgLnk.crtov = phba->fc_crtov; |
| 192 | mb->un.varCfgLnk.citov = phba->fc_citov; |
| 193 | |
| 194 | if (phba->cfg_ack0) |
| 195 | mb->un.varCfgLnk.ack0_enable = 1; |
| 196 | |
| 197 | mb->mbxCommand = MBX_CONFIG_LINK; |
| 198 | mb->mbxOwner = OWN_HOST; |
| 199 | return; |
| 200 | } |
| 201 | |
| 202 | /**********************************************/ |
| 203 | /* lpfc_init_link Issue an INIT LINK */ |
| 204 | /* mailbox command */ |
| 205 | /**********************************************/ |
| 206 | void |
| 207 | lpfc_init_link(struct lpfc_hba * phba, |
| 208 | LPFC_MBOXQ_t * pmb, uint32_t topology, uint32_t linkspeed) |
| 209 | { |
| 210 | lpfc_vpd_t *vpd; |
| 211 | struct lpfc_sli *psli; |
| 212 | MAILBOX_t *mb; |
| 213 | |
| 214 | mb = &pmb->mb; |
| 215 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 216 | |
| 217 | psli = &phba->sli; |
| 218 | switch (topology) { |
| 219 | case FLAGS_TOPOLOGY_MODE_LOOP_PT: |
| 220 | mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP; |
| 221 | mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER; |
| 222 | break; |
| 223 | case FLAGS_TOPOLOGY_MODE_PT_PT: |
| 224 | mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT; |
| 225 | break; |
| 226 | case FLAGS_TOPOLOGY_MODE_LOOP: |
| 227 | mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP; |
| 228 | break; |
| 229 | case FLAGS_TOPOLOGY_MODE_PT_LOOP: |
| 230 | mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT; |
| 231 | mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER; |
| 232 | break; |
Jamie Wellnitz | 367c271 | 2006-02-28 19:25:32 -0500 | [diff] [blame] | 233 | case FLAGS_LOCAL_LB: |
| 234 | mb->un.varInitLnk.link_flags = FLAGS_LOCAL_LB; |
| 235 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 236 | } |
| 237 | |
James Smart | 4b0b91d | 2006-04-15 11:53:00 -0400 | [diff] [blame] | 238 | /* Enable asynchronous ABTS responses from firmware */ |
| 239 | mb->un.varInitLnk.link_flags |= FLAGS_IMED_ABORT; |
| 240 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 241 | /* NEW_FEATURE |
| 242 | * Setting up the link speed |
| 243 | */ |
| 244 | vpd = &phba->vpd; |
| 245 | if (vpd->rev.feaLevelHigh >= 0x02){ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 246 | switch(linkspeed){ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 247 | case LINK_SPEED_1G: |
| 248 | case LINK_SPEED_2G: |
| 249 | case LINK_SPEED_4G: |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 250 | case LINK_SPEED_8G: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 251 | mb->un.varInitLnk.link_flags |= |
| 252 | FLAGS_LINK_SPEED; |
| 253 | mb->un.varInitLnk.link_speed = linkspeed; |
| 254 | break; |
| 255 | case LINK_SPEED_AUTO: |
| 256 | default: |
| 257 | mb->un.varInitLnk.link_speed = |
| 258 | LINK_SPEED_AUTO; |
| 259 | break; |
| 260 | } |
| 261 | |
| 262 | } |
| 263 | else |
| 264 | mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO; |
| 265 | |
| 266 | mb->mbxCommand = (volatile uint8_t)MBX_INIT_LINK; |
| 267 | mb->mbxOwner = OWN_HOST; |
| 268 | mb->un.varInitLnk.fabric_AL_PA = phba->fc_pref_ALPA; |
| 269 | return; |
| 270 | } |
| 271 | |
| 272 | /**********************************************/ |
| 273 | /* lpfc_read_sparam Issue a READ SPARAM */ |
| 274 | /* mailbox command */ |
| 275 | /**********************************************/ |
| 276 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 277 | lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 278 | { |
| 279 | struct lpfc_dmabuf *mp; |
| 280 | MAILBOX_t *mb; |
| 281 | struct lpfc_sli *psli; |
| 282 | |
| 283 | psli = &phba->sli; |
| 284 | mb = &pmb->mb; |
| 285 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 286 | |
| 287 | mb->mbxOwner = OWN_HOST; |
| 288 | |
| 289 | /* Get a buffer to hold the HBAs Service Parameters */ |
| 290 | |
| 291 | if (((mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL)) == 0) || |
| 292 | ((mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys))) == 0)) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 293 | kfree(mp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 294 | mb->mbxCommand = MBX_READ_SPARM64; |
| 295 | /* READ_SPARAM: no buffers */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 296 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
| 297 | "0301 READ_SPARAM: no buffers\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 298 | return (1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 299 | } |
| 300 | INIT_LIST_HEAD(&mp->list); |
| 301 | mb->mbxCommand = MBX_READ_SPARM64; |
| 302 | mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm); |
| 303 | mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys); |
| 304 | mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 305 | mb->un.varRdSparm.vpi = vpi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 306 | |
| 307 | /* save address for completion */ |
| 308 | pmb->context1 = mp; |
| 309 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 310 | return (0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | /********************************************/ |
| 314 | /* lpfc_unreg_did Issue a UNREG_DID */ |
| 315 | /* mailbox command */ |
| 316 | /********************************************/ |
| 317 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 318 | lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did, |
| 319 | LPFC_MBOXQ_t * pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 320 | { |
| 321 | MAILBOX_t *mb; |
| 322 | |
| 323 | mb = &pmb->mb; |
| 324 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 325 | |
| 326 | mb->un.varUnregDID.did = did; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 327 | mb->un.varUnregDID.vpi = vpi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 328 | |
| 329 | mb->mbxCommand = MBX_UNREG_D_ID; |
| 330 | mb->mbxOwner = OWN_HOST; |
| 331 | return; |
| 332 | } |
| 333 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 334 | /**********************************************/ |
| 335 | /* lpfc_read_nv Issue a READ CONFIG */ |
| 336 | /* mailbox command */ |
| 337 | /**********************************************/ |
| 338 | void |
| 339 | lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 340 | { |
| 341 | MAILBOX_t *mb; |
| 342 | |
| 343 | mb = &pmb->mb; |
| 344 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 345 | |
| 346 | mb->mbxCommand = MBX_READ_CONFIG; |
| 347 | mb->mbxOwner = OWN_HOST; |
| 348 | return; |
| 349 | } |
| 350 | |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 351 | /*************************************************/ |
| 352 | /* lpfc_read_lnk_stat Issue a READ LINK STATUS */ |
| 353 | /* mailbox command */ |
| 354 | /*************************************************/ |
| 355 | void |
| 356 | lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 357 | { |
| 358 | MAILBOX_t *mb; |
| 359 | |
| 360 | mb = &pmb->mb; |
| 361 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 362 | |
| 363 | mb->mbxCommand = MBX_READ_LNK_STAT; |
| 364 | mb->mbxOwner = OWN_HOST; |
| 365 | return; |
| 366 | } |
| 367 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 368 | /********************************************/ |
| 369 | /* lpfc_reg_login Issue a REG_LOGIN */ |
| 370 | /* mailbox command */ |
| 371 | /********************************************/ |
| 372 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 373 | lpfc_reg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t did, |
| 374 | uint8_t *param, LPFC_MBOXQ_t *pmb, uint32_t flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 375 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 376 | MAILBOX_t *mb = &pmb->mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 377 | uint8_t *sparam; |
| 378 | struct lpfc_dmabuf *mp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 379 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 380 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 381 | |
| 382 | mb->un.varRegLogin.rpi = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 383 | mb->un.varRegLogin.vpi = vpi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 384 | mb->un.varRegLogin.did = did; |
| 385 | mb->un.varWords[30] = flag; /* Set flag to issue action on cmpl */ |
| 386 | |
| 387 | mb->mbxOwner = OWN_HOST; |
| 388 | |
| 389 | /* Get a buffer to hold NPorts Service Parameters */ |
| 390 | if (((mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL)) == NULL) || |
| 391 | ((mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys))) == 0)) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 392 | kfree(mp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 393 | mb->mbxCommand = MBX_REG_LOGIN64; |
| 394 | /* REG_LOGIN: no buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 395 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 396 | "0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, " |
| 397 | "flag x%x\n", vpi, did, flag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 398 | return (1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 399 | } |
| 400 | INIT_LIST_HEAD(&mp->list); |
| 401 | sparam = mp->virt; |
| 402 | |
| 403 | /* Copy param's into a new buffer */ |
| 404 | memcpy(sparam, param, sizeof (struct serv_parm)); |
| 405 | |
| 406 | /* save address for completion */ |
| 407 | pmb->context1 = (uint8_t *) mp; |
| 408 | |
| 409 | mb->mbxCommand = MBX_REG_LOGIN64; |
| 410 | mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm); |
| 411 | mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys); |
| 412 | mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys); |
| 413 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 414 | return (0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | /**********************************************/ |
| 418 | /* lpfc_unreg_login Issue a UNREG_LOGIN */ |
| 419 | /* mailbox command */ |
| 420 | /**********************************************/ |
| 421 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 422 | lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi, |
| 423 | LPFC_MBOXQ_t * pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 424 | { |
| 425 | MAILBOX_t *mb; |
| 426 | |
| 427 | mb = &pmb->mb; |
| 428 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 429 | |
| 430 | mb->un.varUnregLogin.rpi = (uint16_t) rpi; |
| 431 | mb->un.varUnregLogin.rsvd1 = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 432 | mb->un.varUnregLogin.vpi = vpi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 433 | |
| 434 | mb->mbxCommand = MBX_UNREG_LOGIN; |
| 435 | mb->mbxOwner = OWN_HOST; |
| 436 | return; |
| 437 | } |
| 438 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 439 | /**************************************************/ |
| 440 | /* lpfc_reg_vpi Issue a REG_VPI */ |
| 441 | /* mailbox command */ |
| 442 | /**************************************************/ |
| 443 | void |
| 444 | lpfc_reg_vpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t sid, |
| 445 | LPFC_MBOXQ_t *pmb) |
| 446 | { |
| 447 | MAILBOX_t *mb = &pmb->mb; |
| 448 | |
| 449 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 450 | |
| 451 | mb->un.varRegVpi.vpi = vpi; |
| 452 | mb->un.varRegVpi.sid = sid; |
| 453 | |
| 454 | mb->mbxCommand = MBX_REG_VPI; |
| 455 | mb->mbxOwner = OWN_HOST; |
| 456 | return; |
| 457 | |
| 458 | } |
| 459 | |
| 460 | /**************************************************/ |
| 461 | /* lpfc_unreg_vpi Issue a UNREG_VNPI */ |
| 462 | /* mailbox command */ |
| 463 | /**************************************************/ |
| 464 | void |
| 465 | lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb) |
| 466 | { |
| 467 | MAILBOX_t *mb = &pmb->mb; |
| 468 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 469 | |
| 470 | mb->un.varUnregVpi.vpi = vpi; |
| 471 | |
| 472 | mb->mbxCommand = MBX_UNREG_VPI; |
| 473 | mb->mbxOwner = OWN_HOST; |
| 474 | return; |
| 475 | |
| 476 | } |
| 477 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 478 | static void |
| 479 | lpfc_config_pcb_setup(struct lpfc_hba * phba) |
| 480 | { |
| 481 | struct lpfc_sli *psli = &phba->sli; |
| 482 | struct lpfc_sli_ring *pring; |
| 483 | PCB_t *pcbp = &phba->slim2p->pcb; |
| 484 | dma_addr_t pdma_addr; |
| 485 | uint32_t offset; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 486 | uint32_t iocbCnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 487 | int i; |
| 488 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 489 | pcbp->maxRing = (psli->num_rings - 1); |
| 490 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 491 | for (i = 0; i < psli->num_rings; i++) { |
| 492 | pring = &psli->ring[i]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 493 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 494 | pring->sizeCiocb = phba->sli_rev == 3 ? SLI3_IOCB_CMD_SIZE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 495 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 496 | pring->sizeRiocb = phba->sli_rev == 3 ? SLI3_IOCB_RSP_SIZE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 497 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 498 | /* A ring MUST have both cmd and rsp entries defined to be |
| 499 | valid */ |
| 500 | if ((pring->numCiocb == 0) || (pring->numRiocb == 0)) { |
| 501 | pcbp->rdsc[i].cmdEntries = 0; |
| 502 | pcbp->rdsc[i].rspEntries = 0; |
| 503 | pcbp->rdsc[i].cmdAddrHigh = 0; |
| 504 | pcbp->rdsc[i].rspAddrHigh = 0; |
| 505 | pcbp->rdsc[i].cmdAddrLow = 0; |
| 506 | pcbp->rdsc[i].rspAddrLow = 0; |
| 507 | pring->cmdringaddr = NULL; |
| 508 | pring->rspringaddr = NULL; |
| 509 | continue; |
| 510 | } |
| 511 | /* Command ring setup for ring */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 512 | pring->cmdringaddr = (void *) &phba->slim2p->IOCBs[iocbCnt]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 513 | pcbp->rdsc[i].cmdEntries = pring->numCiocb; |
| 514 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 515 | offset = (uint8_t *) &phba->slim2p->IOCBs[iocbCnt] - |
| 516 | (uint8_t *) phba->slim2p; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 517 | pdma_addr = phba->slim2p_mapping + offset; |
| 518 | pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr); |
| 519 | pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr); |
| 520 | iocbCnt += pring->numCiocb; |
| 521 | |
| 522 | /* Response ring setup for ring */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 523 | pring->rspringaddr = (void *) &phba->slim2p->IOCBs[iocbCnt]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 524 | |
| 525 | pcbp->rdsc[i].rspEntries = pring->numRiocb; |
| 526 | offset = (uint8_t *)&phba->slim2p->IOCBs[iocbCnt] - |
| 527 | (uint8_t *)phba->slim2p; |
| 528 | pdma_addr = phba->slim2p_mapping + offset; |
| 529 | pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr); |
| 530 | pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr); |
| 531 | iocbCnt += pring->numRiocb; |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | void |
| 536 | lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 537 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 538 | MAILBOX_t *mb = &pmb->mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 539 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 540 | mb->un.varRdRev.cv = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 541 | mb->un.varRdRev.v3req = 1; /* Request SLI3 info */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 542 | mb->mbxCommand = MBX_READ_REV; |
| 543 | mb->mbxOwner = OWN_HOST; |
| 544 | return; |
| 545 | } |
| 546 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 547 | static void |
| 548 | lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb, |
| 549 | struct lpfc_hbq_init *hbq_desc) |
| 550 | { |
| 551 | hbqmb->profiles.profile2.seqlenbcnt = hbq_desc->seqlenbcnt; |
| 552 | hbqmb->profiles.profile2.maxlen = hbq_desc->maxlen; |
| 553 | hbqmb->profiles.profile2.seqlenoff = hbq_desc->seqlenoff; |
| 554 | } |
| 555 | |
| 556 | static void |
| 557 | lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb, |
| 558 | struct lpfc_hbq_init *hbq_desc) |
| 559 | { |
| 560 | hbqmb->profiles.profile3.seqlenbcnt = hbq_desc->seqlenbcnt; |
| 561 | hbqmb->profiles.profile3.maxlen = hbq_desc->maxlen; |
| 562 | hbqmb->profiles.profile3.cmdcodeoff = hbq_desc->cmdcodeoff; |
| 563 | hbqmb->profiles.profile3.seqlenoff = hbq_desc->seqlenoff; |
| 564 | memcpy(&hbqmb->profiles.profile3.cmdmatch, hbq_desc->cmdmatch, |
| 565 | sizeof(hbqmb->profiles.profile3.cmdmatch)); |
| 566 | } |
| 567 | |
| 568 | static void |
| 569 | lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb, |
| 570 | struct lpfc_hbq_init *hbq_desc) |
| 571 | { |
| 572 | hbqmb->profiles.profile5.seqlenbcnt = hbq_desc->seqlenbcnt; |
| 573 | hbqmb->profiles.profile5.maxlen = hbq_desc->maxlen; |
| 574 | hbqmb->profiles.profile5.cmdcodeoff = hbq_desc->cmdcodeoff; |
| 575 | hbqmb->profiles.profile5.seqlenoff = hbq_desc->seqlenoff; |
| 576 | memcpy(&hbqmb->profiles.profile5.cmdmatch, hbq_desc->cmdmatch, |
| 577 | sizeof(hbqmb->profiles.profile5.cmdmatch)); |
| 578 | } |
| 579 | |
| 580 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 581 | lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id, |
| 582 | struct lpfc_hbq_init *hbq_desc, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 583 | uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb) |
| 584 | { |
| 585 | int i; |
| 586 | MAILBOX_t *mb = &pmb->mb; |
| 587 | struct config_hbq_var *hbqmb = &mb->un.varCfgHbq; |
| 588 | |
| 589 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 590 | hbqmb->hbqId = id; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 591 | hbqmb->entry_count = hbq_desc->entry_count; /* # entries in HBQ */ |
| 592 | hbqmb->recvNotify = hbq_desc->rn; /* Receive |
| 593 | * Notification */ |
| 594 | hbqmb->numMask = hbq_desc->mask_count; /* # R_CTL/TYPE masks |
| 595 | * # in words 0-19 */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 596 | hbqmb->profile = hbq_desc->profile; /* Selection profile: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 597 | * 0 = all, |
| 598 | * 7 = logentry */ |
| 599 | hbqmb->ringMask = hbq_desc->ring_mask; /* Binds HBQ to a ring |
| 600 | * e.g. Ring0=b0001, |
| 601 | * ring2=b0100 */ |
| 602 | hbqmb->headerLen = hbq_desc->headerLen; /* 0 if not profile 4 |
| 603 | * or 5 */ |
| 604 | hbqmb->logEntry = hbq_desc->logEntry; /* Set to 1 if this |
| 605 | * HBQ will be used |
| 606 | * for LogEntry |
| 607 | * buffers */ |
| 608 | hbqmb->hbqaddrLow = putPaddrLow(phba->hbqslimp.phys) + |
| 609 | hbq_entry_index * sizeof(struct lpfc_hbq_entry); |
| 610 | hbqmb->hbqaddrHigh = putPaddrHigh(phba->hbqslimp.phys); |
| 611 | |
| 612 | mb->mbxCommand = MBX_CONFIG_HBQ; |
| 613 | mb->mbxOwner = OWN_HOST; |
| 614 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 615 | /* Copy info for profiles 2,3,5. Other |
| 616 | * profiles this area is reserved |
| 617 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 618 | if (hbq_desc->profile == 2) |
| 619 | lpfc_build_hbq_profile2(hbqmb, hbq_desc); |
| 620 | else if (hbq_desc->profile == 3) |
| 621 | lpfc_build_hbq_profile3(hbqmb, hbq_desc); |
| 622 | else if (hbq_desc->profile == 5) |
| 623 | lpfc_build_hbq_profile5(hbqmb, hbq_desc); |
| 624 | |
| 625 | /* Return if no rctl / type masks for this HBQ */ |
| 626 | if (!hbq_desc->mask_count) |
| 627 | return; |
| 628 | |
| 629 | /* Otherwise we setup specific rctl / type masks for this HBQ */ |
| 630 | for (i = 0; i < hbq_desc->mask_count; i++) { |
| 631 | hbqmb->hbqMasks[i].tmatch = hbq_desc->hbqMasks[i].tmatch; |
| 632 | hbqmb->hbqMasks[i].tmask = hbq_desc->hbqMasks[i].tmask; |
| 633 | hbqmb->hbqMasks[i].rctlmatch = hbq_desc->hbqMasks[i].rctlmatch; |
| 634 | hbqmb->hbqMasks[i].rctlmask = hbq_desc->hbqMasks[i].rctlmask; |
| 635 | } |
| 636 | |
| 637 | return; |
| 638 | } |
| 639 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 640 | |
| 641 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 642 | void |
| 643 | lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb) |
| 644 | { |
| 645 | int i; |
| 646 | MAILBOX_t *mb = &pmb->mb; |
| 647 | struct lpfc_sli *psli; |
| 648 | struct lpfc_sli_ring *pring; |
| 649 | |
| 650 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 651 | |
| 652 | mb->un.varCfgRing.ring = ring; |
| 653 | mb->un.varCfgRing.maxOrigXchg = 0; |
| 654 | mb->un.varCfgRing.maxRespXchg = 0; |
| 655 | mb->un.varCfgRing.recvNotify = 1; |
| 656 | |
| 657 | psli = &phba->sli; |
| 658 | pring = &psli->ring[ring]; |
| 659 | mb->un.varCfgRing.numMask = pring->num_mask; |
| 660 | mb->mbxCommand = MBX_CONFIG_RING; |
| 661 | mb->mbxOwner = OWN_HOST; |
| 662 | |
| 663 | /* Is this ring configured for a specific profile */ |
| 664 | if (pring->prt[0].profile) { |
| 665 | mb->un.varCfgRing.profile = pring->prt[0].profile; |
| 666 | return; |
| 667 | } |
| 668 | |
| 669 | /* Otherwise we setup specific rctl / type masks for this ring */ |
| 670 | for (i = 0; i < pring->num_mask; i++) { |
| 671 | mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl; |
| 672 | if (mb->un.varCfgRing.rrRegs[i].rval != FC_ELS_REQ) |
| 673 | mb->un.varCfgRing.rrRegs[i].rmask = 0xff; |
| 674 | else |
| 675 | mb->un.varCfgRing.rrRegs[i].rmask = 0xfe; |
| 676 | mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type; |
| 677 | mb->un.varCfgRing.rrRegs[i].tmask = 0xff; |
| 678 | } |
| 679 | |
| 680 | return; |
| 681 | } |
| 682 | |
| 683 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 684 | lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 685 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 686 | MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 687 | MAILBOX_t *mb = &pmb->mb; |
| 688 | dma_addr_t pdma_addr; |
| 689 | uint32_t bar_low, bar_high; |
| 690 | size_t offset; |
James.Smart@Emulex.Com | 4cc2da1 | 2005-06-25 10:34:00 -0400 | [diff] [blame] | 691 | struct lpfc_hgp hgp; |
James.Smart@Emulex.Com | f91b392 | 2005-10-28 20:29:28 -0400 | [diff] [blame] | 692 | int i; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 693 | uint32_t pgp_offset; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 694 | |
| 695 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
| 696 | mb->mbxCommand = MBX_CONFIG_PORT; |
| 697 | mb->mbxOwner = OWN_HOST; |
| 698 | |
| 699 | mb->un.varCfgPort.pcbLen = sizeof(PCB_t); |
| 700 | |
| 701 | offset = (uint8_t *)&phba->slim2p->pcb - (uint8_t *)phba->slim2p; |
| 702 | pdma_addr = phba->slim2p_mapping + offset; |
| 703 | mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr); |
| 704 | mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr); |
| 705 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 706 | /* If HBA supports SLI=3 ask for it */ |
| 707 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 708 | if (phba->sli_rev == 3 && phba->vpd.sli3Feat.cerbm) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 709 | mb->un.varCfgPort.cerbm = 1; /* Request HBQs */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 710 | mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count(); |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 711 | if (phba->max_vpi && phba->cfg_enable_npiv && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 712 | phba->vpd.sli3Feat.cmv) { |
| 713 | mb->un.varCfgPort.max_vpi = phba->max_vpi; |
| 714 | mb->un.varCfgPort.cmv = 1; |
| 715 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
| 716 | } else |
| 717 | mb->un.varCfgPort.max_vpi = phba->max_vpi = 0; |
| 718 | } else |
| 719 | phba->sli_rev = 2; |
| 720 | mb->un.varCfgPort.sli_mode = phba->sli_rev; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 721 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 722 | /* Now setup pcb */ |
| 723 | phba->slim2p->pcb.type = TYPE_NATIVE_SLI2; |
| 724 | phba->slim2p->pcb.feature = FEATURE_INITIAL_SLI2; |
| 725 | |
| 726 | /* Setup Mailbox pointers */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 727 | phba->slim2p->pcb.mailBoxSize = offsetof(MAILBOX_t, us) + |
| 728 | sizeof(struct sli2_desc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 729 | offset = (uint8_t *)&phba->slim2p->mbx - (uint8_t *)phba->slim2p; |
| 730 | pdma_addr = phba->slim2p_mapping + offset; |
| 731 | phba->slim2p->pcb.mbAddrHigh = putPaddrHigh(pdma_addr); |
| 732 | phba->slim2p->pcb.mbAddrLow = putPaddrLow(pdma_addr); |
| 733 | |
| 734 | /* |
| 735 | * Setup Host Group ring pointer. |
| 736 | * |
| 737 | * For efficiency reasons, the ring get/put pointers can be |
| 738 | * placed in adapter memory (SLIM) rather than in host memory. |
| 739 | * This allows firmware to avoid PCI reads/writes when updating |
| 740 | * and checking pointers. |
| 741 | * |
| 742 | * The firmware recognizes the use of SLIM memory by comparing |
| 743 | * the address of the get/put pointers structure with that of |
| 744 | * the SLIM BAR (BAR0). |
| 745 | * |
| 746 | * Caution: be sure to use the PCI config space value of BAR0/BAR1 |
| 747 | * (the hardware's view of the base address), not the OS's |
| 748 | * value of pci_resource_start() as the OS value may be a cookie |
| 749 | * for ioremap/iomap. |
| 750 | */ |
| 751 | |
| 752 | |
| 753 | pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low); |
| 754 | pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high); |
| 755 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 756 | /* |
| 757 | * Set up HGP - Port Memory |
| 758 | * |
| 759 | * The port expects the host get/put pointers to reside in memory |
| 760 | * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes) |
| 761 | * area of SLIM. In SLI-2 mode, there's an additional 16 reserved |
| 762 | * words (0x40 bytes). This area is not reserved if HBQs are |
| 763 | * configured in SLI-3. |
| 764 | * |
| 765 | * CR0Put - SLI2(no HBQs) = 0xc0, With HBQs = 0x80 |
| 766 | * RR0Get 0xc4 0x84 |
| 767 | * CR1Put 0xc8 0x88 |
| 768 | * RR1Get 0xcc 0x8c |
| 769 | * CR2Put 0xd0 0x90 |
| 770 | * RR2Get 0xd4 0x94 |
| 771 | * CR3Put 0xd8 0x98 |
| 772 | * RR3Get 0xdc 0x9c |
| 773 | * |
| 774 | * Reserved 0xa0-0xbf |
| 775 | * If HBQs configured: |
| 776 | * HBQ 0 Put ptr 0xc0 |
| 777 | * HBQ 1 Put ptr 0xc4 |
| 778 | * HBQ 2 Put ptr 0xc8 |
| 779 | * ...... |
| 780 | * HBQ(M-1)Put Pointer 0xc0+(M-1)*4 |
| 781 | * |
| 782 | */ |
| 783 | |
| 784 | if (phba->sli_rev == 3) { |
| 785 | phba->host_gp = &mb_slim->us.s3.host[0]; |
| 786 | phba->hbq_put = &mb_slim->us.s3.hbq_put[0]; |
| 787 | } else { |
| 788 | phba->host_gp = &mb_slim->us.s2.host[0]; |
| 789 | phba->hbq_put = NULL; |
| 790 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 791 | |
| 792 | /* mask off BAR0's flag bits 0 - 3 */ |
| 793 | phba->slim2p->pcb.hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) + |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 794 | (void __iomem *) phba->host_gp - |
| 795 | (void __iomem *)phba->MBslimaddr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 796 | if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64) |
| 797 | phba->slim2p->pcb.hgpAddrHigh = bar_high; |
| 798 | else |
| 799 | phba->slim2p->pcb.hgpAddrHigh = 0; |
| 800 | /* write HGP data to SLIM at the required longword offset */ |
James.Smart@Emulex.Com | 4cc2da1 | 2005-06-25 10:34:00 -0400 | [diff] [blame] | 801 | memset(&hgp, 0, sizeof(struct lpfc_hgp)); |
James.Smart@Emulex.Com | f91b392 | 2005-10-28 20:29:28 -0400 | [diff] [blame] | 802 | |
| 803 | for (i=0; i < phba->sli.num_rings; i++) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 804 | lpfc_memcpy_to_slim(phba->host_gp + i, &hgp, |
| 805 | sizeof(*phba->host_gp)); |
James.Smart@Emulex.Com | f91b392 | 2005-10-28 20:29:28 -0400 | [diff] [blame] | 806 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 807 | |
| 808 | /* Setup Port Group ring pointer */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 809 | if (phba->sli_rev == 3) |
| 810 | pgp_offset = (uint8_t *)&phba->slim2p->mbx.us.s3_pgp.port - |
| 811 | (uint8_t *)phba->slim2p; |
| 812 | else |
| 813 | pgp_offset = (uint8_t *)&phba->slim2p->mbx.us.s2.port - |
| 814 | (uint8_t *)phba->slim2p; |
| 815 | |
| 816 | pdma_addr = phba->slim2p_mapping + pgp_offset; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 817 | phba->slim2p->pcb.pgpAddrHigh = putPaddrHigh(pdma_addr); |
| 818 | phba->slim2p->pcb.pgpAddrLow = putPaddrLow(pdma_addr); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 819 | phba->hbq_get = &phba->slim2p->mbx.us.s3_pgp.hbq_get[0]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 820 | |
| 821 | /* Use callback routine to setp rings in the pcb */ |
| 822 | lpfc_config_pcb_setup(phba); |
| 823 | |
| 824 | /* special handling for LC HBAs */ |
| 825 | if (lpfc_is_LC_HBA(phba->pcidev->device)) { |
| 826 | uint32_t hbainit[5]; |
| 827 | |
| 828 | lpfc_hba_init(phba, hbainit); |
| 829 | |
| 830 | memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20); |
| 831 | } |
| 832 | |
| 833 | /* Swap PCB if needed */ |
| 834 | lpfc_sli_pcimem_bcopy(&phba->slim2p->pcb, &phba->slim2p->pcb, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 835 | sizeof(PCB_t)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | void |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 839 | lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 840 | { |
| 841 | MAILBOX_t *mb = &pmb->mb; |
| 842 | |
| 843 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
| 844 | mb->mbxCommand = MBX_KILL_BOARD; |
| 845 | mb->mbxOwner = OWN_HOST; |
| 846 | return; |
| 847 | } |
| 848 | |
| 849 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 850 | lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq) |
| 851 | { |
| 852 | struct lpfc_sli *psli; |
| 853 | |
| 854 | psli = &phba->sli; |
| 855 | |
| 856 | list_add_tail(&mbq->list, &psli->mboxq); |
| 857 | |
| 858 | psli->mboxq_cnt++; |
| 859 | |
| 860 | return; |
| 861 | } |
| 862 | |
| 863 | LPFC_MBOXQ_t * |
| 864 | lpfc_mbox_get(struct lpfc_hba * phba) |
| 865 | { |
| 866 | LPFC_MBOXQ_t *mbq = NULL; |
| 867 | struct lpfc_sli *psli = &phba->sli; |
| 868 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 869 | list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t, list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 870 | if (mbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 871 | psli->mboxq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 872 | |
| 873 | return mbq; |
| 874 | } |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 875 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 876 | void |
| 877 | lpfc_mbox_cmpl_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq) |
| 878 | { |
| 879 | /* This function expects to be called from interupt context */ |
| 880 | spin_lock(&phba->hbalock); |
| 881 | list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl); |
| 882 | spin_unlock(&phba->hbalock); |
| 883 | return; |
| 884 | } |
| 885 | |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 886 | int |
| 887 | lpfc_mbox_tmo_val(struct lpfc_hba *phba, int cmd) |
| 888 | { |
| 889 | switch (cmd) { |
| 890 | case MBX_WRITE_NV: /* 0x03 */ |
| 891 | case MBX_UPDATE_CFG: /* 0x1B */ |
| 892 | case MBX_DOWN_LOAD: /* 0x1C */ |
| 893 | case MBX_DEL_LD_ENTRY: /* 0x1D */ |
| 894 | case MBX_LOAD_AREA: /* 0x81 */ |
| 895 | case MBX_FLASH_WR_ULA: /* 0x98 */ |
| 896 | case MBX_LOAD_EXP_ROM: /* 0x9C */ |
| 897 | return LPFC_MBOX_TMO_FLASH_CMD; |
| 898 | } |
| 899 | return LPFC_MBOX_TMO; |
| 900 | } |