| 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 | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4 | * Copyright (C) 2004-2008 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" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 33 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 34 | #include "lpfc_disc.h" |
| 35 | #include "lpfc_scsi.h" |
| 36 | #include "lpfc.h" |
| 37 | #include "lpfc_logmsg.h" |
| 38 | #include "lpfc_crtn.h" |
| 39 | #include "lpfc_compat.h" |
| 40 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 41 | /** |
| 42 | * lpfc_dump_mem: Prepare a mailbox command for retrieving HBA's VPD memory. |
| 43 | * @phba: pointer to lpfc hba data structure. |
| 44 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 45 | * @offset: offset for dumping VPD memory mailbox command. |
| 46 | * |
| 47 | * The dump mailbox command provides a method for the device driver to obtain |
| 48 | * various types of information from the HBA device. |
| 49 | * |
| 50 | * This routine prepares the mailbox command for dumping HBA Vital Product |
| 51 | * Data (VPD) memory. This mailbox command is to be used for retrieving a |
| 52 | * portion (DMP_RSP_SIZE bytes) of a HBA's VPD from the HBA at an address |
| 53 | * offset specified by the offset parameter. |
| 54 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 55 | void |
| 56 | lpfc_dump_mem(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, uint16_t offset) |
| 57 | { |
| 58 | MAILBOX_t *mb; |
| 59 | void *ctx; |
| 60 | |
| 61 | mb = &pmb->mb; |
| 62 | ctx = pmb->context2; |
| 63 | |
| 64 | /* Setup to dump VPD region */ |
| 65 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 66 | mb->mbxCommand = MBX_DUMP_MEMORY; |
| 67 | mb->un.varDmp.cv = 1; |
| 68 | mb->un.varDmp.type = DMP_NV_PARAMS; |
| 69 | mb->un.varDmp.entry_index = offset; |
| 70 | mb->un.varDmp.region_id = DMP_REGION_VPD; |
| 71 | mb->un.varDmp.word_cnt = (DMP_RSP_SIZE / sizeof (uint32_t)); |
| 72 | mb->un.varDmp.co = 0; |
| 73 | mb->un.varDmp.resp_offset = 0; |
| 74 | pmb->context2 = ctx; |
| 75 | mb->mbxOwner = OWN_HOST; |
| 76 | return; |
| 77 | } |
| 78 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 79 | /** |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 80 | * lpfc_dump_mem: Prepare a mailbox command for retrieving wakeup params. |
| 81 | * @phba: pointer to lpfc hba data structure. |
| 82 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 83 | * This function create a dump memory mailbox command to dump wake up |
| 84 | * parameters. |
| 85 | */ |
| 86 | void |
| 87 | lpfc_dump_wakeup_param(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 88 | { |
| 89 | MAILBOX_t *mb; |
| 90 | void *ctx; |
| 91 | |
| 92 | mb = &pmb->mb; |
| 93 | /* Save context so that we can restore after memset */ |
| 94 | ctx = pmb->context2; |
| 95 | |
| 96 | /* Setup to dump VPD region */ |
| 97 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
| 98 | mb->mbxCommand = MBX_DUMP_MEMORY; |
| 99 | mb->mbxOwner = OWN_HOST; |
| 100 | mb->un.varDmp.cv = 1; |
| 101 | mb->un.varDmp.type = DMP_NV_PARAMS; |
| 102 | mb->un.varDmp.entry_index = 0; |
| 103 | mb->un.varDmp.region_id = WAKE_UP_PARMS_REGION_ID; |
| 104 | mb->un.varDmp.word_cnt = WAKE_UP_PARMS_WORD_SIZE; |
| 105 | mb->un.varDmp.co = 0; |
| 106 | mb->un.varDmp.resp_offset = 0; |
| 107 | pmb->context2 = ctx; |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | /** |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 112 | * lpfc_read_nv: Prepare a mailbox command for reading HBA's NVRAM param. |
| 113 | * @phba: pointer to lpfc hba data structure. |
| 114 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 115 | * |
| 116 | * The read NVRAM mailbox command returns the HBA's non-volatile parameters |
| 117 | * that are used as defaults when the Fibre Channel link is brought on-line. |
| 118 | * |
| 119 | * This routine prepares the mailbox command for reading information stored |
| 120 | * in the HBA's NVRAM. Specifically, the HBA's WWNN and WWPN. |
| 121 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 122 | void |
| 123 | lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 124 | { |
| 125 | MAILBOX_t *mb; |
| 126 | |
| 127 | mb = &pmb->mb; |
| 128 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 129 | mb->mbxCommand = MBX_READ_NV; |
| 130 | mb->mbxOwner = OWN_HOST; |
| 131 | return; |
| 132 | } |
| 133 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 134 | /** |
| 135 | * lpfc_config_async: Prepare a mailbox command for enabling HBA async event. |
| 136 | * @phba: pointer to lpfc hba data structure. |
| 137 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 138 | * @ring: ring number for the asynchronous event to be configured. |
| 139 | * |
| 140 | * The asynchronous event enable mailbox command is used to enable the |
| 141 | * asynchronous event posting via the ASYNC_STATUS_CN IOCB response and |
| 142 | * specifies the default ring to which events are posted. |
| 143 | * |
| 144 | * This routine prepares the mailbox command for enabling HBA asynchronous |
| 145 | * event support on a IOCB ring. |
| 146 | **/ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 147 | void |
| 148 | lpfc_config_async(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, |
| 149 | uint32_t ring) |
| 150 | { |
| 151 | MAILBOX_t *mb; |
| 152 | |
| 153 | mb = &pmb->mb; |
| 154 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 155 | mb->mbxCommand = MBX_ASYNCEVT_ENABLE; |
| 156 | mb->un.varCfgAsyncEvent.ring = ring; |
| 157 | mb->mbxOwner = OWN_HOST; |
| 158 | return; |
| 159 | } |
| 160 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 161 | /** |
| 162 | * lpfc_heart_beat: Prepare a mailbox command for heart beat. |
| 163 | * @phba: pointer to lpfc hba data structure. |
| 164 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 165 | * |
| 166 | * The heart beat mailbox command is used to detect an unresponsive HBA, which |
| 167 | * is defined as any device where no error attention is sent and both mailbox |
| 168 | * and rings are not processed. |
| 169 | * |
| 170 | * This routine prepares the mailbox command for issuing a heart beat in the |
| 171 | * form of mailbox command to the HBA. The timely completion of the heart |
| 172 | * beat mailbox command indicates the health of the HBA. |
| 173 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 174 | void |
| 175 | lpfc_heart_beat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 176 | { |
| 177 | MAILBOX_t *mb; |
| 178 | |
| 179 | mb = &pmb->mb; |
| 180 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 181 | mb->mbxCommand = MBX_HEARTBEAT; |
| 182 | mb->mbxOwner = OWN_HOST; |
| 183 | return; |
| 184 | } |
| 185 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 186 | /** |
| 187 | * lpfc_read_la: Prepare a mailbox command for reading HBA link attention. |
| 188 | * @phba: pointer to lpfc hba data structure. |
| 189 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 190 | * @mp: DMA buffer memory for reading the link attention information into. |
| 191 | * |
| 192 | * The read link attention mailbox command is issued to read the Link Event |
| 193 | * Attention information indicated by the HBA port when the Link Event bit |
| 194 | * of the Host Attention (HSTATT) register is set to 1. A Link Event |
| 195 | * Attention occurs based on an exception detected at the Fibre Channel link |
| 196 | * interface. |
| 197 | * |
| 198 | * This routine prepares the mailbox command for reading HBA link attention |
| 199 | * information. A DMA memory has been set aside and address passed to the |
| 200 | * HBA through @mp for the HBA to DMA link attention information into the |
| 201 | * memory as part of the execution of the mailbox command. |
| 202 | * |
| 203 | * Return codes |
| 204 | * 0 - Success (currently always return 0) |
| 205 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 206 | int |
| 207 | lpfc_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, struct lpfc_dmabuf *mp) |
| 208 | { |
| 209 | MAILBOX_t *mb; |
| 210 | struct lpfc_sli *psli; |
| 211 | |
| 212 | psli = &phba->sli; |
| 213 | mb = &pmb->mb; |
| 214 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 215 | |
| 216 | INIT_LIST_HEAD(&mp->list); |
| 217 | mb->mbxCommand = MBX_READ_LA64; |
| 218 | mb->un.varReadLA.un.lilpBde64.tus.f.bdeSize = 128; |
| 219 | mb->un.varReadLA.un.lilpBde64.addrHigh = putPaddrHigh(mp->phys); |
| 220 | mb->un.varReadLA.un.lilpBde64.addrLow = putPaddrLow(mp->phys); |
| 221 | |
| 222 | /* Save address for later completion and set the owner to host so that |
| 223 | * the FW knows this mailbox is available for processing. |
| 224 | */ |
| 225 | pmb->context1 = (uint8_t *) mp; |
| 226 | mb->mbxOwner = OWN_HOST; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 227 | return (0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 228 | } |
| 229 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 230 | /** |
| 231 | * lpfc_clear_la: Prepare a mailbox command for clearing HBA link attention. |
| 232 | * @phba: pointer to lpfc hba data structure. |
| 233 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 234 | * |
| 235 | * The clear link attention mailbox command is issued to clear the link event |
| 236 | * attention condition indicated by the Link Event bit of the Host Attention |
| 237 | * (HSTATT) register. The link event attention condition is cleared only if |
| 238 | * the event tag specified matches that of the current link event counter. |
| 239 | * The current event tag is read using the read link attention event mailbox |
| 240 | * command. |
| 241 | * |
| 242 | * This routine prepares the mailbox command for clearing HBA link attention |
| 243 | * information. |
| 244 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 245 | void |
| 246 | lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 247 | { |
| 248 | MAILBOX_t *mb; |
| 249 | |
| 250 | mb = &pmb->mb; |
| 251 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 252 | |
| 253 | mb->un.varClearLA.eventTag = phba->fc_eventTag; |
| 254 | mb->mbxCommand = MBX_CLEAR_LA; |
| 255 | mb->mbxOwner = OWN_HOST; |
| 256 | return; |
| 257 | } |
| 258 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 259 | /** |
| 260 | * lpfc_config_link: Prepare a mailbox command for configuring link on a HBA. |
| 261 | * @phba: pointer to lpfc hba data structure. |
| 262 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 263 | * |
| 264 | * The configure link mailbox command is used before the initialize link |
| 265 | * mailbox command to override default value and to configure link-oriented |
| 266 | * parameters such as DID address and various timers. Typically, this |
| 267 | * command would be used after an F_Port login to set the returned DID address |
| 268 | * and the fabric timeout values. This command is not valid before a configure |
| 269 | * port command has configured the HBA port. |
| 270 | * |
| 271 | * This routine prepares the mailbox command for configuring link on a HBA. |
| 272 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 273 | void |
| 274 | lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 275 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 276 | struct lpfc_vport *vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 277 | MAILBOX_t *mb = &pmb->mb; |
| 278 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 279 | |
| 280 | /* NEW_FEATURE |
| 281 | * SLI-2, Coalescing Response Feature. |
| 282 | */ |
| 283 | if (phba->cfg_cr_delay) { |
| 284 | mb->un.varCfgLnk.cr = 1; |
| 285 | mb->un.varCfgLnk.ci = 1; |
| 286 | mb->un.varCfgLnk.cr_delay = phba->cfg_cr_delay; |
| 287 | mb->un.varCfgLnk.cr_count = phba->cfg_cr_count; |
| 288 | } |
| 289 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 290 | mb->un.varCfgLnk.myId = vport->fc_myDID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 291 | mb->un.varCfgLnk.edtov = phba->fc_edtov; |
| 292 | mb->un.varCfgLnk.arbtov = phba->fc_arbtov; |
| 293 | mb->un.varCfgLnk.ratov = phba->fc_ratov; |
| 294 | mb->un.varCfgLnk.rttov = phba->fc_rttov; |
| 295 | mb->un.varCfgLnk.altov = phba->fc_altov; |
| 296 | mb->un.varCfgLnk.crtov = phba->fc_crtov; |
| 297 | mb->un.varCfgLnk.citov = phba->fc_citov; |
| 298 | |
| 299 | if (phba->cfg_ack0) |
| 300 | mb->un.varCfgLnk.ack0_enable = 1; |
| 301 | |
| 302 | mb->mbxCommand = MBX_CONFIG_LINK; |
| 303 | mb->mbxOwner = OWN_HOST; |
| 304 | return; |
| 305 | } |
| 306 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 307 | /** |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 308 | * lpfc_config_msi: Prepare a mailbox command for configuring msi-x. |
| 309 | * @phba: pointer to lpfc hba data structure. |
| 310 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 311 | * |
| 312 | * The configure MSI-X mailbox command is used to configure the HBA's SLI-3 |
| 313 | * MSI-X multi-message interrupt vector association to interrupt attention |
| 314 | * conditions. |
| 315 | * |
| 316 | * Return codes |
| 317 | * 0 - Success |
| 318 | * -EINVAL - Failure |
| 319 | **/ |
| 320 | int |
| 321 | lpfc_config_msi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 322 | { |
| 323 | MAILBOX_t *mb = &pmb->mb; |
| 324 | uint32_t attentionConditions[2]; |
| 325 | |
| 326 | /* Sanity check */ |
| 327 | if (phba->cfg_use_msi != 2) { |
| 328 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 329 | "0475 Not configured for supporting MSI-X " |
| 330 | "cfg_use_msi: 0x%x\n", phba->cfg_use_msi); |
| 331 | return -EINVAL; |
| 332 | } |
| 333 | |
| 334 | if (phba->sli_rev < 3) { |
| 335 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 336 | "0476 HBA not supporting SLI-3 or later " |
| 337 | "SLI Revision: 0x%x\n", phba->sli_rev); |
| 338 | return -EINVAL; |
| 339 | } |
| 340 | |
| 341 | /* Clear mailbox command fields */ |
| 342 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
| 343 | |
| 344 | /* |
| 345 | * SLI-3, Message Signaled Interrupt Fearure. |
| 346 | */ |
| 347 | |
| 348 | /* Multi-message attention configuration */ |
| 349 | attentionConditions[0] = (HA_R0ATT | HA_R1ATT | HA_R2ATT | HA_ERATT | |
| 350 | HA_LATT | HA_MBATT); |
| 351 | attentionConditions[1] = 0; |
| 352 | |
| 353 | mb->un.varCfgMSI.attentionConditions[0] = attentionConditions[0]; |
| 354 | mb->un.varCfgMSI.attentionConditions[1] = attentionConditions[1]; |
| 355 | |
| 356 | /* |
| 357 | * Set up message number to HA bit association |
| 358 | */ |
| 359 | #ifdef __BIG_ENDIAN_BITFIELD |
| 360 | /* RA0 (FCP Ring) */ |
| 361 | mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS] = 1; |
| 362 | /* RA1 (Other Protocol Extra Ring) */ |
| 363 | mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS] = 1; |
| 364 | #else /* __LITTLE_ENDIAN_BITFIELD */ |
| 365 | /* RA0 (FCP Ring) */ |
| 366 | mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS^3] = 1; |
| 367 | /* RA1 (Other Protocol Extra Ring) */ |
| 368 | mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS^3] = 1; |
| 369 | #endif |
| 370 | /* Multi-message interrupt autoclear configuration*/ |
| 371 | mb->un.varCfgMSI.autoClearHA[0] = attentionConditions[0]; |
| 372 | mb->un.varCfgMSI.autoClearHA[1] = attentionConditions[1]; |
| 373 | |
| 374 | /* For now, HBA autoclear does not work reliably, disable it */ |
| 375 | mb->un.varCfgMSI.autoClearHA[0] = 0; |
| 376 | mb->un.varCfgMSI.autoClearHA[1] = 0; |
| 377 | |
| 378 | /* Set command and owner bit */ |
| 379 | mb->mbxCommand = MBX_CONFIG_MSI; |
| 380 | mb->mbxOwner = OWN_HOST; |
| 381 | |
| 382 | return 0; |
| 383 | } |
| 384 | |
| 385 | /** |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 386 | * lpfc_init_link: Prepare a mailbox command for initialize link on a HBA. |
| 387 | * @phba: pointer to lpfc hba data structure. |
| 388 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 389 | * @topology: the link topology for the link to be initialized to. |
| 390 | * @linkspeed: the link speed for the link to be initialized to. |
| 391 | * |
| 392 | * The initialize link mailbox command is used to initialize the Fibre |
| 393 | * Channel link. This command must follow a configure port command that |
| 394 | * establishes the mode of operation. |
| 395 | * |
| 396 | * This routine prepares the mailbox command for initializing link on a HBA |
| 397 | * with the specified link topology and speed. |
| 398 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 399 | void |
| 400 | lpfc_init_link(struct lpfc_hba * phba, |
| 401 | LPFC_MBOXQ_t * pmb, uint32_t topology, uint32_t linkspeed) |
| 402 | { |
| 403 | lpfc_vpd_t *vpd; |
| 404 | struct lpfc_sli *psli; |
| 405 | MAILBOX_t *mb; |
| 406 | |
| 407 | mb = &pmb->mb; |
| 408 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 409 | |
| 410 | psli = &phba->sli; |
| 411 | switch (topology) { |
| 412 | case FLAGS_TOPOLOGY_MODE_LOOP_PT: |
| 413 | mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP; |
| 414 | mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER; |
| 415 | break; |
| 416 | case FLAGS_TOPOLOGY_MODE_PT_PT: |
| 417 | mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT; |
| 418 | break; |
| 419 | case FLAGS_TOPOLOGY_MODE_LOOP: |
| 420 | mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP; |
| 421 | break; |
| 422 | case FLAGS_TOPOLOGY_MODE_PT_LOOP: |
| 423 | mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT; |
| 424 | mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER; |
| 425 | break; |
Jamie Wellnitz | 367c271 | 2006-02-28 19:25:32 -0500 | [diff] [blame] | 426 | case FLAGS_LOCAL_LB: |
| 427 | mb->un.varInitLnk.link_flags = FLAGS_LOCAL_LB; |
| 428 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 429 | } |
| 430 | |
James Smart | 4b0b91d | 2006-04-15 11:53:00 -0400 | [diff] [blame] | 431 | /* Enable asynchronous ABTS responses from firmware */ |
| 432 | mb->un.varInitLnk.link_flags |= FLAGS_IMED_ABORT; |
| 433 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 434 | /* NEW_FEATURE |
| 435 | * Setting up the link speed |
| 436 | */ |
| 437 | vpd = &phba->vpd; |
| 438 | if (vpd->rev.feaLevelHigh >= 0x02){ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 439 | switch(linkspeed){ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 440 | case LINK_SPEED_1G: |
| 441 | case LINK_SPEED_2G: |
| 442 | case LINK_SPEED_4G: |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 443 | case LINK_SPEED_8G: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 444 | mb->un.varInitLnk.link_flags |= |
| 445 | FLAGS_LINK_SPEED; |
| 446 | mb->un.varInitLnk.link_speed = linkspeed; |
| 447 | break; |
| 448 | case LINK_SPEED_AUTO: |
| 449 | default: |
| 450 | mb->un.varInitLnk.link_speed = |
| 451 | LINK_SPEED_AUTO; |
| 452 | break; |
| 453 | } |
| 454 | |
| 455 | } |
| 456 | else |
| 457 | mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO; |
| 458 | |
| 459 | mb->mbxCommand = (volatile uint8_t)MBX_INIT_LINK; |
| 460 | mb->mbxOwner = OWN_HOST; |
| 461 | mb->un.varInitLnk.fabric_AL_PA = phba->fc_pref_ALPA; |
| 462 | return; |
| 463 | } |
| 464 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 465 | /** |
| 466 | * lpfc_read_sparam: Prepare a mailbox command for reading HBA parameters. |
| 467 | * @phba: pointer to lpfc hba data structure. |
| 468 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 469 | * @vpi: virtual N_Port identifier. |
| 470 | * |
| 471 | * The read service parameter mailbox command is used to read the HBA port |
| 472 | * service parameters. The service parameters are read into the buffer |
| 473 | * specified directly by a BDE in the mailbox command. These service |
| 474 | * parameters may then be used to build the payload of an N_Port/F_POrt |
| 475 | * login request and reply (LOGI/ACC). |
| 476 | * |
| 477 | * This routine prepares the mailbox command for reading HBA port service |
| 478 | * parameters. The DMA memory is allocated in this function and the addresses |
| 479 | * are populated into the mailbox command for the HBA to DMA the service |
| 480 | * parameters into. |
| 481 | * |
| 482 | * Return codes |
| 483 | * 0 - Success |
| 484 | * 1 - DMA memory allocation failed |
| 485 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 486 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 487 | lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 488 | { |
| 489 | struct lpfc_dmabuf *mp; |
| 490 | MAILBOX_t *mb; |
| 491 | struct lpfc_sli *psli; |
| 492 | |
| 493 | psli = &phba->sli; |
| 494 | mb = &pmb->mb; |
| 495 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 496 | |
| 497 | mb->mbxOwner = OWN_HOST; |
| 498 | |
| 499 | /* Get a buffer to hold the HBAs Service Parameters */ |
| 500 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 501 | mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 502 | if (mp) |
| 503 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 504 | if (!mp || !mp->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 505 | kfree(mp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 506 | mb->mbxCommand = MBX_READ_SPARM64; |
| 507 | /* READ_SPARAM: no buffers */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 508 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
| 509 | "0301 READ_SPARAM: no buffers\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 510 | return (1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 511 | } |
| 512 | INIT_LIST_HEAD(&mp->list); |
| 513 | mb->mbxCommand = MBX_READ_SPARM64; |
| 514 | mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm); |
| 515 | mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys); |
| 516 | mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 517 | mb->un.varRdSparm.vpi = vpi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 518 | |
| 519 | /* save address for completion */ |
| 520 | pmb->context1 = mp; |
| 521 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 522 | return (0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 523 | } |
| 524 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 525 | /** |
| 526 | * lpfc_unreg_did: Prepare a mailbox command for unregistering DID. |
| 527 | * @phba: pointer to lpfc hba data structure. |
| 528 | * @vpi: virtual N_Port identifier. |
| 529 | * @did: remote port identifier. |
| 530 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 531 | * |
| 532 | * The unregister DID mailbox command is used to unregister an N_Port/F_Port |
| 533 | * login for an unknown RPI by specifying the DID of a remote port. This |
| 534 | * command frees an RPI context in the HBA port. This has the effect of |
| 535 | * performing an implicit N_Port/F_Port logout. |
| 536 | * |
| 537 | * This routine prepares the mailbox command for unregistering a remote |
| 538 | * N_Port/F_Port (DID) login. |
| 539 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 540 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 541 | lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did, |
| 542 | LPFC_MBOXQ_t * pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 543 | { |
| 544 | MAILBOX_t *mb; |
| 545 | |
| 546 | mb = &pmb->mb; |
| 547 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 548 | |
| 549 | mb->un.varUnregDID.did = did; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 550 | mb->un.varUnregDID.vpi = vpi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 551 | |
| 552 | mb->mbxCommand = MBX_UNREG_D_ID; |
| 553 | mb->mbxOwner = OWN_HOST; |
| 554 | return; |
| 555 | } |
| 556 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 557 | /** |
| 558 | * lpfc_read_config: Prepare a mailbox command for reading HBA configuration. |
| 559 | * @phba: pointer to lpfc hba data structure. |
| 560 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 561 | * |
| 562 | * The read configuration mailbox command is used to read the HBA port |
| 563 | * configuration parameters. This mailbox command provides a method for |
| 564 | * seeing any parameters that may have changed via various configuration |
| 565 | * mailbox commands. |
| 566 | * |
| 567 | * This routine prepares the mailbox command for reading out HBA configuration |
| 568 | * parameters. |
| 569 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 570 | void |
| 571 | lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 572 | { |
| 573 | MAILBOX_t *mb; |
| 574 | |
| 575 | mb = &pmb->mb; |
| 576 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 577 | |
| 578 | mb->mbxCommand = MBX_READ_CONFIG; |
| 579 | mb->mbxOwner = OWN_HOST; |
| 580 | return; |
| 581 | } |
| 582 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 583 | /** |
| 584 | * lpfc_read_lnk_stat: Prepare a mailbox command for reading HBA link stats. |
| 585 | * @phba: pointer to lpfc hba data structure. |
| 586 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 587 | * |
| 588 | * The read link status mailbox command is used to read the link status from |
| 589 | * the HBA. Link status includes all link-related error counters. These |
| 590 | * counters are maintained by the HBA and originated in the link hardware |
| 591 | * unit. Note that all of these counters wrap. |
| 592 | * |
| 593 | * This routine prepares the mailbox command for reading out HBA link status. |
| 594 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 595 | void |
| 596 | lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 597 | { |
| 598 | MAILBOX_t *mb; |
| 599 | |
| 600 | mb = &pmb->mb; |
| 601 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 602 | |
| 603 | mb->mbxCommand = MBX_READ_LNK_STAT; |
| 604 | mb->mbxOwner = OWN_HOST; |
| 605 | return; |
| 606 | } |
| 607 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 608 | /** |
| 609 | * lpfc_reg_login: Prepare a mailbox command for registering remote login. |
| 610 | * @phba: pointer to lpfc hba data structure. |
| 611 | * @vpi: virtual N_Port identifier. |
| 612 | * @did: remote port identifier. |
| 613 | * @param: pointer to memory holding the server parameters. |
| 614 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 615 | * @flag: action flag to be passed back for the complete function. |
| 616 | * |
| 617 | * The registration login mailbox command is used to register an N_Port or |
| 618 | * F_Port login. This registration allows the HBA to cache the remote N_Port |
| 619 | * service parameters internally and thereby make the appropriate FC-2 |
| 620 | * decisions. The remote port service parameters are handed off by the driver |
| 621 | * to the HBA using a descriptor entry that directly identifies a buffer in |
| 622 | * host memory. In exchange, the HBA returns an RPI identifier. |
| 623 | * |
| 624 | * This routine prepares the mailbox command for registering remote port login. |
| 625 | * The function allocates DMA buffer for passing the service parameters to the |
| 626 | * HBA with the mailbox command. |
| 627 | * |
| 628 | * Return codes |
| 629 | * 0 - Success |
| 630 | * 1 - DMA memory allocation failed |
| 631 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 632 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 633 | lpfc_reg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t did, |
| 634 | uint8_t *param, LPFC_MBOXQ_t *pmb, uint32_t flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 635 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 636 | MAILBOX_t *mb = &pmb->mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 637 | uint8_t *sparam; |
| 638 | struct lpfc_dmabuf *mp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 639 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 640 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 641 | |
| 642 | mb->un.varRegLogin.rpi = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 643 | mb->un.varRegLogin.vpi = vpi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 644 | mb->un.varRegLogin.did = did; |
| 645 | mb->un.varWords[30] = flag; /* Set flag to issue action on cmpl */ |
| 646 | |
| 647 | mb->mbxOwner = OWN_HOST; |
| 648 | |
| 649 | /* Get a buffer to hold NPorts Service Parameters */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 650 | mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 651 | if (mp) |
| 652 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 653 | if (!mp || !mp->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 654 | kfree(mp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 655 | mb->mbxCommand = MBX_REG_LOGIN64; |
| 656 | /* REG_LOGIN: no buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 657 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 658 | "0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, " |
| 659 | "flag x%x\n", vpi, did, flag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 660 | return (1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 661 | } |
| 662 | INIT_LIST_HEAD(&mp->list); |
| 663 | sparam = mp->virt; |
| 664 | |
| 665 | /* Copy param's into a new buffer */ |
| 666 | memcpy(sparam, param, sizeof (struct serv_parm)); |
| 667 | |
| 668 | /* save address for completion */ |
| 669 | pmb->context1 = (uint8_t *) mp; |
| 670 | |
| 671 | mb->mbxCommand = MBX_REG_LOGIN64; |
| 672 | mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm); |
| 673 | mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys); |
| 674 | mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys); |
| 675 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 676 | return (0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 677 | } |
| 678 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 679 | /** |
| 680 | * lpfc_unreg_login: Prepare a mailbox command for unregistering remote login. |
| 681 | * @phba: pointer to lpfc hba data structure. |
| 682 | * @vpi: virtual N_Port identifier. |
| 683 | * @rpi: remote port identifier |
| 684 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 685 | * |
| 686 | * The unregistration login mailbox command is used to unregister an N_Port |
| 687 | * or F_Port login. This command frees an RPI context in the HBA. It has the |
| 688 | * effect of performing an implicit N_Port/F_Port logout. |
| 689 | * |
| 690 | * This routine prepares the mailbox command for unregistering remote port |
| 691 | * login. |
| 692 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 693 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 694 | lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi, |
| 695 | LPFC_MBOXQ_t * pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 696 | { |
| 697 | MAILBOX_t *mb; |
| 698 | |
| 699 | mb = &pmb->mb; |
| 700 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 701 | |
| 702 | mb->un.varUnregLogin.rpi = (uint16_t) rpi; |
| 703 | mb->un.varUnregLogin.rsvd1 = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 704 | mb->un.varUnregLogin.vpi = vpi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 705 | |
| 706 | mb->mbxCommand = MBX_UNREG_LOGIN; |
| 707 | mb->mbxOwner = OWN_HOST; |
| 708 | return; |
| 709 | } |
| 710 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 711 | /** |
| 712 | * lpfc_reg_vpi: Prepare a mailbox command for registering vport identifier. |
| 713 | * @phba: pointer to lpfc hba data structure. |
| 714 | * @vpi: virtual N_Port identifier. |
| 715 | * @sid: Fibre Channel S_ID (N_Port_ID assigned to a virtual N_Port). |
| 716 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 717 | * |
| 718 | * The registration vport identifier mailbox command is used to activate a |
| 719 | * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the |
| 720 | * N_Port_ID against the information in the selected virtual N_Port context |
| 721 | * block and marks it active to allow normal processing of IOCB commands and |
| 722 | * received unsolicited exchanges. |
| 723 | * |
| 724 | * This routine prepares the mailbox command for registering a virtual N_Port. |
| 725 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 726 | void |
| 727 | lpfc_reg_vpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t sid, |
| 728 | LPFC_MBOXQ_t *pmb) |
| 729 | { |
| 730 | MAILBOX_t *mb = &pmb->mb; |
| 731 | |
| 732 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 733 | |
| 734 | mb->un.varRegVpi.vpi = vpi; |
| 735 | mb->un.varRegVpi.sid = sid; |
| 736 | |
| 737 | mb->mbxCommand = MBX_REG_VPI; |
| 738 | mb->mbxOwner = OWN_HOST; |
| 739 | return; |
| 740 | |
| 741 | } |
| 742 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 743 | /** |
| 744 | * lpfc_unreg_vpi: Prepare a mailbox command for unregistering vport id. |
| 745 | * @phba: pointer to lpfc hba data structure. |
| 746 | * @vpi: virtual N_Port identifier. |
| 747 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 748 | * |
| 749 | * The unregistration vport identifier mailbox command is used to inactivate |
| 750 | * a virtual N_Port. The driver must have logged out and unregistered all |
| 751 | * remote N_Ports to abort any activity on the virtual N_Port. The HBA will |
| 752 | * unregisters any default RPIs associated with the specified vpi, aborting |
| 753 | * any active exchanges. The HBA will post the mailbox response after making |
| 754 | * the virtual N_Port inactive. |
| 755 | * |
| 756 | * This routine prepares the mailbox command for unregistering a virtual |
| 757 | * N_Port. |
| 758 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 759 | void |
| 760 | lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb) |
| 761 | { |
| 762 | MAILBOX_t *mb = &pmb->mb; |
| 763 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 764 | |
| 765 | mb->un.varUnregVpi.vpi = vpi; |
| 766 | |
| 767 | mb->mbxCommand = MBX_UNREG_VPI; |
| 768 | mb->mbxOwner = OWN_HOST; |
| 769 | return; |
| 770 | |
| 771 | } |
| 772 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 773 | /** |
| 774 | * lpfc_config_pcb_setup: Set up IOCB rings in the Port Control Block (PCB) |
| 775 | * @phba: pointer to lpfc hba data structure. |
| 776 | * |
| 777 | * This routine sets up and initializes the IOCB rings in the Port Control |
| 778 | * Block (PCB). |
| 779 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 780 | static void |
| 781 | lpfc_config_pcb_setup(struct lpfc_hba * phba) |
| 782 | { |
| 783 | struct lpfc_sli *psli = &phba->sli; |
| 784 | struct lpfc_sli_ring *pring; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 785 | PCB_t *pcbp = phba->pcb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 786 | dma_addr_t pdma_addr; |
| 787 | uint32_t offset; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 788 | uint32_t iocbCnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 789 | int i; |
| 790 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 791 | pcbp->maxRing = (psli->num_rings - 1); |
| 792 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 793 | for (i = 0; i < psli->num_rings; i++) { |
| 794 | pring = &psli->ring[i]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 795 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 796 | pring->sizeCiocb = phba->sli_rev == 3 ? SLI3_IOCB_CMD_SIZE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 797 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 798 | pring->sizeRiocb = phba->sli_rev == 3 ? SLI3_IOCB_RSP_SIZE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 799 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 800 | /* A ring MUST have both cmd and rsp entries defined to be |
| 801 | valid */ |
| 802 | if ((pring->numCiocb == 0) || (pring->numRiocb == 0)) { |
| 803 | pcbp->rdsc[i].cmdEntries = 0; |
| 804 | pcbp->rdsc[i].rspEntries = 0; |
| 805 | pcbp->rdsc[i].cmdAddrHigh = 0; |
| 806 | pcbp->rdsc[i].rspAddrHigh = 0; |
| 807 | pcbp->rdsc[i].cmdAddrLow = 0; |
| 808 | pcbp->rdsc[i].rspAddrLow = 0; |
| 809 | pring->cmdringaddr = NULL; |
| 810 | pring->rspringaddr = NULL; |
| 811 | continue; |
| 812 | } |
| 813 | /* Command ring setup for ring */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 814 | pring->cmdringaddr = (void *)&phba->IOCBs[iocbCnt]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 815 | pcbp->rdsc[i].cmdEntries = pring->numCiocb; |
| 816 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 817 | offset = (uint8_t *) &phba->IOCBs[iocbCnt] - |
| 818 | (uint8_t *) phba->slim2p.virt; |
| 819 | pdma_addr = phba->slim2p.phys + offset; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 820 | pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr); |
| 821 | pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr); |
| 822 | iocbCnt += pring->numCiocb; |
| 823 | |
| 824 | /* Response ring setup for ring */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 825 | pring->rspringaddr = (void *) &phba->IOCBs[iocbCnt]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 826 | |
| 827 | pcbp->rdsc[i].rspEntries = pring->numRiocb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 828 | offset = (uint8_t *)&phba->IOCBs[iocbCnt] - |
| 829 | (uint8_t *)phba->slim2p.virt; |
| 830 | pdma_addr = phba->slim2p.phys + offset; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 831 | pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr); |
| 832 | pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr); |
| 833 | iocbCnt += pring->numRiocb; |
| 834 | } |
| 835 | } |
| 836 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 837 | /** |
| 838 | * lpfc_read_rev: Prepare a mailbox command for reading HBA revision. |
| 839 | * @phba: pointer to lpfc hba data structure. |
| 840 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 841 | * |
| 842 | * The read revision mailbox command is used to read the revision levels of |
| 843 | * the HBA components. These components include hardware units, resident |
| 844 | * firmware, and available firmware. HBAs that supports SLI-3 mode of |
| 845 | * operation provide different response information depending on the version |
| 846 | * requested by the driver. |
| 847 | * |
| 848 | * This routine prepares the mailbox command for reading HBA revision |
| 849 | * information. |
| 850 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 851 | void |
| 852 | lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 853 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 854 | MAILBOX_t *mb = &pmb->mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 855 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 856 | mb->un.varRdRev.cv = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 857 | mb->un.varRdRev.v3req = 1; /* Request SLI3 info */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 858 | mb->mbxCommand = MBX_READ_REV; |
| 859 | mb->mbxOwner = OWN_HOST; |
| 860 | return; |
| 861 | } |
| 862 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 863 | /** |
| 864 | * lpfc_build_hbq_profile2: Set up the HBQ Selection Profile 2. |
| 865 | * @hbqmb: pointer to the HBQ configuration data structure in mailbox command. |
| 866 | * @hbq_desc: pointer to the HBQ selection profile descriptor. |
| 867 | * |
| 868 | * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA |
| 869 | * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs |
| 870 | * the Sequence Length Test using the fields in the Selection Profile 2 |
| 871 | * extension in words 20:31. |
| 872 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 873 | static void |
| 874 | lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb, |
| 875 | struct lpfc_hbq_init *hbq_desc) |
| 876 | { |
| 877 | hbqmb->profiles.profile2.seqlenbcnt = hbq_desc->seqlenbcnt; |
| 878 | hbqmb->profiles.profile2.maxlen = hbq_desc->maxlen; |
| 879 | hbqmb->profiles.profile2.seqlenoff = hbq_desc->seqlenoff; |
| 880 | } |
| 881 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 882 | /** |
| 883 | * lpfc_build_hbq_profile3: Set up the HBQ Selection Profile 3. |
| 884 | * @hbqmb: pointer to the HBQ configuration data structure in mailbox command. |
| 885 | * @hbq_desc: pointer to the HBQ selection profile descriptor. |
| 886 | * |
| 887 | * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA |
| 888 | * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs |
| 889 | * the Sequence Length Test and Byte Field Test using the fields in the |
| 890 | * Selection Profile 3 extension in words 20:31. |
| 891 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 892 | static void |
| 893 | lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb, |
| 894 | struct lpfc_hbq_init *hbq_desc) |
| 895 | { |
| 896 | hbqmb->profiles.profile3.seqlenbcnt = hbq_desc->seqlenbcnt; |
| 897 | hbqmb->profiles.profile3.maxlen = hbq_desc->maxlen; |
| 898 | hbqmb->profiles.profile3.cmdcodeoff = hbq_desc->cmdcodeoff; |
| 899 | hbqmb->profiles.profile3.seqlenoff = hbq_desc->seqlenoff; |
| 900 | memcpy(&hbqmb->profiles.profile3.cmdmatch, hbq_desc->cmdmatch, |
| 901 | sizeof(hbqmb->profiles.profile3.cmdmatch)); |
| 902 | } |
| 903 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 904 | /** |
| 905 | * lpfc_build_hbq_profile5: Set up the HBQ Selection Profile 5. |
| 906 | * @hbqmb: pointer to the HBQ configuration data structure in mailbox command. |
| 907 | * @hbq_desc: pointer to the HBQ selection profile descriptor. |
| 908 | * |
| 909 | * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The |
| 910 | * HBA tests the initial frame of an incoming sequence using the frame's |
| 911 | * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test |
| 912 | * and Byte Field Test using the fields in the Selection Profile 5 extension |
| 913 | * words 20:31. |
| 914 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 915 | static void |
| 916 | lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb, |
| 917 | struct lpfc_hbq_init *hbq_desc) |
| 918 | { |
| 919 | hbqmb->profiles.profile5.seqlenbcnt = hbq_desc->seqlenbcnt; |
| 920 | hbqmb->profiles.profile5.maxlen = hbq_desc->maxlen; |
| 921 | hbqmb->profiles.profile5.cmdcodeoff = hbq_desc->cmdcodeoff; |
| 922 | hbqmb->profiles.profile5.seqlenoff = hbq_desc->seqlenoff; |
| 923 | memcpy(&hbqmb->profiles.profile5.cmdmatch, hbq_desc->cmdmatch, |
| 924 | sizeof(hbqmb->profiles.profile5.cmdmatch)); |
| 925 | } |
| 926 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 927 | /** |
| 928 | * lpfc_config_hbq: Prepare a mailbox command for configuring an HBQ. |
| 929 | * @phba: pointer to lpfc hba data structure. |
| 930 | * @id: HBQ identifier. |
| 931 | * @hbq_desc: pointer to the HBA descriptor data structure. |
| 932 | * @hbq_entry_index: index of the HBQ entry data structures. |
| 933 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 934 | * |
| 935 | * The configure HBQ (Host Buffer Queue) mailbox command is used to configure |
| 936 | * an HBQ. The configuration binds events that require buffers to a particular |
| 937 | * ring and HBQ based on a selection profile. |
| 938 | * |
| 939 | * This routine prepares the mailbox command for configuring an HBQ. |
| 940 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 941 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 942 | lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id, |
| 943 | struct lpfc_hbq_init *hbq_desc, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 944 | uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb) |
| 945 | { |
| 946 | int i; |
| 947 | MAILBOX_t *mb = &pmb->mb; |
| 948 | struct config_hbq_var *hbqmb = &mb->un.varCfgHbq; |
| 949 | |
| 950 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 951 | hbqmb->hbqId = id; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 952 | hbqmb->entry_count = hbq_desc->entry_count; /* # entries in HBQ */ |
| 953 | hbqmb->recvNotify = hbq_desc->rn; /* Receive |
| 954 | * Notification */ |
| 955 | hbqmb->numMask = hbq_desc->mask_count; /* # R_CTL/TYPE masks |
| 956 | * # in words 0-19 */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 957 | hbqmb->profile = hbq_desc->profile; /* Selection profile: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 958 | * 0 = all, |
| 959 | * 7 = logentry */ |
| 960 | hbqmb->ringMask = hbq_desc->ring_mask; /* Binds HBQ to a ring |
| 961 | * e.g. Ring0=b0001, |
| 962 | * ring2=b0100 */ |
| 963 | hbqmb->headerLen = hbq_desc->headerLen; /* 0 if not profile 4 |
| 964 | * or 5 */ |
| 965 | hbqmb->logEntry = hbq_desc->logEntry; /* Set to 1 if this |
| 966 | * HBQ will be used |
| 967 | * for LogEntry |
| 968 | * buffers */ |
| 969 | hbqmb->hbqaddrLow = putPaddrLow(phba->hbqslimp.phys) + |
| 970 | hbq_entry_index * sizeof(struct lpfc_hbq_entry); |
| 971 | hbqmb->hbqaddrHigh = putPaddrHigh(phba->hbqslimp.phys); |
| 972 | |
| 973 | mb->mbxCommand = MBX_CONFIG_HBQ; |
| 974 | mb->mbxOwner = OWN_HOST; |
| 975 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 976 | /* Copy info for profiles 2,3,5. Other |
| 977 | * profiles this area is reserved |
| 978 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 979 | if (hbq_desc->profile == 2) |
| 980 | lpfc_build_hbq_profile2(hbqmb, hbq_desc); |
| 981 | else if (hbq_desc->profile == 3) |
| 982 | lpfc_build_hbq_profile3(hbqmb, hbq_desc); |
| 983 | else if (hbq_desc->profile == 5) |
| 984 | lpfc_build_hbq_profile5(hbqmb, hbq_desc); |
| 985 | |
| 986 | /* Return if no rctl / type masks for this HBQ */ |
| 987 | if (!hbq_desc->mask_count) |
| 988 | return; |
| 989 | |
| 990 | /* Otherwise we setup specific rctl / type masks for this HBQ */ |
| 991 | for (i = 0; i < hbq_desc->mask_count; i++) { |
| 992 | hbqmb->hbqMasks[i].tmatch = hbq_desc->hbqMasks[i].tmatch; |
| 993 | hbqmb->hbqMasks[i].tmask = hbq_desc->hbqMasks[i].tmask; |
| 994 | hbqmb->hbqMasks[i].rctlmatch = hbq_desc->hbqMasks[i].rctlmatch; |
| 995 | hbqmb->hbqMasks[i].rctlmask = hbq_desc->hbqMasks[i].rctlmask; |
| 996 | } |
| 997 | |
| 998 | return; |
| 999 | } |
| 1000 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1001 | /** |
| 1002 | * lpfc_config_ring: Prepare a mailbox command for configuring an IOCB ring. |
| 1003 | * @phba: pointer to lpfc hba data structure. |
| 1004 | * @ring: |
| 1005 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 1006 | * |
| 1007 | * The configure ring mailbox command is used to configure an IOCB ring. This |
| 1008 | * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the |
| 1009 | * ring. This is used to map incoming sequences to a particular ring whose |
| 1010 | * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not |
| 1011 | * attempt to configure a ring whose number is greater than the number |
| 1012 | * specified in the Port Control Block (PCB). It is an error to issue the |
| 1013 | * configure ring command more than once with the same ring number. The HBA |
| 1014 | * returns an error if the driver attempts this. |
| 1015 | * |
| 1016 | * This routine prepares the mailbox command for configuring IOCB ring. |
| 1017 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1018 | void |
| 1019 | lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb) |
| 1020 | { |
| 1021 | int i; |
| 1022 | MAILBOX_t *mb = &pmb->mb; |
| 1023 | struct lpfc_sli *psli; |
| 1024 | struct lpfc_sli_ring *pring; |
| 1025 | |
| 1026 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 1027 | |
| 1028 | mb->un.varCfgRing.ring = ring; |
| 1029 | mb->un.varCfgRing.maxOrigXchg = 0; |
| 1030 | mb->un.varCfgRing.maxRespXchg = 0; |
| 1031 | mb->un.varCfgRing.recvNotify = 1; |
| 1032 | |
| 1033 | psli = &phba->sli; |
| 1034 | pring = &psli->ring[ring]; |
| 1035 | mb->un.varCfgRing.numMask = pring->num_mask; |
| 1036 | mb->mbxCommand = MBX_CONFIG_RING; |
| 1037 | mb->mbxOwner = OWN_HOST; |
| 1038 | |
| 1039 | /* Is this ring configured for a specific profile */ |
| 1040 | if (pring->prt[0].profile) { |
| 1041 | mb->un.varCfgRing.profile = pring->prt[0].profile; |
| 1042 | return; |
| 1043 | } |
| 1044 | |
| 1045 | /* Otherwise we setup specific rctl / type masks for this ring */ |
| 1046 | for (i = 0; i < pring->num_mask; i++) { |
| 1047 | mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl; |
| 1048 | if (mb->un.varCfgRing.rrRegs[i].rval != FC_ELS_REQ) |
| 1049 | mb->un.varCfgRing.rrRegs[i].rmask = 0xff; |
| 1050 | else |
| 1051 | mb->un.varCfgRing.rrRegs[i].rmask = 0xfe; |
| 1052 | mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type; |
| 1053 | mb->un.varCfgRing.rrRegs[i].tmask = 0xff; |
| 1054 | } |
| 1055 | |
| 1056 | return; |
| 1057 | } |
| 1058 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1059 | /** |
| 1060 | * lpfc_config_port: Prepare a mailbox command for configuring port. |
| 1061 | * @phba: pointer to lpfc hba data structure. |
| 1062 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 1063 | * |
| 1064 | * The configure port mailbox command is used to identify the Port Control |
| 1065 | * Block (PCB) in the driver memory. After this command is issued, the |
| 1066 | * driver must not access the mailbox in the HBA without first resetting |
| 1067 | * the HBA. The HBA may copy the PCB information to internal storage for |
| 1068 | * subsequent use; the driver can not change the PCB information unless it |
| 1069 | * resets the HBA. |
| 1070 | * |
| 1071 | * This routine prepares the mailbox command for configuring port. |
| 1072 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1073 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1074 | lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1075 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1076 | MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1077 | MAILBOX_t *mb = &pmb->mb; |
| 1078 | dma_addr_t pdma_addr; |
| 1079 | uint32_t bar_low, bar_high; |
| 1080 | size_t offset; |
James.Smart@Emulex.Com | 4cc2da1 | 2005-06-25 10:34:00 -0400 | [diff] [blame] | 1081 | struct lpfc_hgp hgp; |
James.Smart@Emulex.Com | f91b392 | 2005-10-28 20:29:28 -0400 | [diff] [blame] | 1082 | int i; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1083 | uint32_t pgp_offset; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1084 | |
| 1085 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
| 1086 | mb->mbxCommand = MBX_CONFIG_PORT; |
| 1087 | mb->mbxOwner = OWN_HOST; |
| 1088 | |
| 1089 | mb->un.varCfgPort.pcbLen = sizeof(PCB_t); |
| 1090 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1091 | offset = (uint8_t *)phba->pcb - (uint8_t *)phba->slim2p.virt; |
| 1092 | pdma_addr = phba->slim2p.phys + offset; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1093 | mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr); |
| 1094 | mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr); |
| 1095 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 1096 | /* Always Host Group Pointer is in SLIM */ |
| 1097 | mb->un.varCfgPort.hps = 1; |
| 1098 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1099 | /* If HBA supports SLI=3 ask for it */ |
| 1100 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1101 | if (phba->sli_rev == 3 && phba->vpd.sli3Feat.cerbm) { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1102 | if (phba->cfg_enable_bg) |
| 1103 | mb->un.varCfgPort.cbg = 1; /* configure BlockGuard */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1104 | mb->un.varCfgPort.cerbm = 1; /* Request HBQs */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1105 | mb->un.varCfgPort.ccrp = 1; /* Command Ring Polling */ |
| 1106 | mb->un.varCfgPort.cinb = 1; /* Interrupt Notification Block */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1107 | mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count(); |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 1108 | if (phba->max_vpi && phba->cfg_enable_npiv && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1109 | phba->vpd.sli3Feat.cmv) { |
| 1110 | mb->un.varCfgPort.max_vpi = phba->max_vpi; |
| 1111 | mb->un.varCfgPort.cmv = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1112 | } else |
| 1113 | mb->un.varCfgPort.max_vpi = phba->max_vpi = 0; |
| 1114 | } else |
| 1115 | phba->sli_rev = 2; |
| 1116 | mb->un.varCfgPort.sli_mode = phba->sli_rev; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1117 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1118 | /* Now setup pcb */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1119 | phba->pcb->type = TYPE_NATIVE_SLI2; |
| 1120 | phba->pcb->feature = FEATURE_INITIAL_SLI2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1121 | |
| 1122 | /* Setup Mailbox pointers */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1123 | phba->pcb->mailBoxSize = sizeof(MAILBOX_t); |
| 1124 | offset = (uint8_t *)phba->mbox - (uint8_t *)phba->slim2p.virt; |
| 1125 | pdma_addr = phba->slim2p.phys + offset; |
| 1126 | phba->pcb->mbAddrHigh = putPaddrHigh(pdma_addr); |
| 1127 | phba->pcb->mbAddrLow = putPaddrLow(pdma_addr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1128 | |
| 1129 | /* |
| 1130 | * Setup Host Group ring pointer. |
| 1131 | * |
| 1132 | * For efficiency reasons, the ring get/put pointers can be |
| 1133 | * placed in adapter memory (SLIM) rather than in host memory. |
| 1134 | * This allows firmware to avoid PCI reads/writes when updating |
| 1135 | * and checking pointers. |
| 1136 | * |
| 1137 | * The firmware recognizes the use of SLIM memory by comparing |
| 1138 | * the address of the get/put pointers structure with that of |
| 1139 | * the SLIM BAR (BAR0). |
| 1140 | * |
| 1141 | * Caution: be sure to use the PCI config space value of BAR0/BAR1 |
| 1142 | * (the hardware's view of the base address), not the OS's |
| 1143 | * value of pci_resource_start() as the OS value may be a cookie |
| 1144 | * for ioremap/iomap. |
| 1145 | */ |
| 1146 | |
| 1147 | |
| 1148 | pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low); |
| 1149 | pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high); |
| 1150 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1151 | /* |
| 1152 | * Set up HGP - Port Memory |
| 1153 | * |
| 1154 | * The port expects the host get/put pointers to reside in memory |
| 1155 | * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes) |
| 1156 | * area of SLIM. In SLI-2 mode, there's an additional 16 reserved |
| 1157 | * words (0x40 bytes). This area is not reserved if HBQs are |
| 1158 | * configured in SLI-3. |
| 1159 | * |
| 1160 | * CR0Put - SLI2(no HBQs) = 0xc0, With HBQs = 0x80 |
| 1161 | * RR0Get 0xc4 0x84 |
| 1162 | * CR1Put 0xc8 0x88 |
| 1163 | * RR1Get 0xcc 0x8c |
| 1164 | * CR2Put 0xd0 0x90 |
| 1165 | * RR2Get 0xd4 0x94 |
| 1166 | * CR3Put 0xd8 0x98 |
| 1167 | * RR3Get 0xdc 0x9c |
| 1168 | * |
| 1169 | * Reserved 0xa0-0xbf |
| 1170 | * If HBQs configured: |
| 1171 | * HBQ 0 Put ptr 0xc0 |
| 1172 | * HBQ 1 Put ptr 0xc4 |
| 1173 | * HBQ 2 Put ptr 0xc8 |
| 1174 | * ...... |
| 1175 | * HBQ(M-1)Put Pointer 0xc0+(M-1)*4 |
| 1176 | * |
| 1177 | */ |
| 1178 | |
| 1179 | if (phba->sli_rev == 3) { |
| 1180 | phba->host_gp = &mb_slim->us.s3.host[0]; |
| 1181 | phba->hbq_put = &mb_slim->us.s3.hbq_put[0]; |
| 1182 | } else { |
| 1183 | phba->host_gp = &mb_slim->us.s2.host[0]; |
| 1184 | phba->hbq_put = NULL; |
| 1185 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1186 | |
| 1187 | /* mask off BAR0's flag bits 0 - 3 */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1188 | phba->pcb->hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) + |
| 1189 | (void __iomem *)phba->host_gp - |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1190 | (void __iomem *)phba->MBslimaddr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1191 | if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1192 | phba->pcb->hgpAddrHigh = bar_high; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1193 | else |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1194 | phba->pcb->hgpAddrHigh = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1195 | /* write HGP data to SLIM at the required longword offset */ |
James.Smart@Emulex.Com | 4cc2da1 | 2005-06-25 10:34:00 -0400 | [diff] [blame] | 1196 | memset(&hgp, 0, sizeof(struct lpfc_hgp)); |
James.Smart@Emulex.Com | f91b392 | 2005-10-28 20:29:28 -0400 | [diff] [blame] | 1197 | |
| 1198 | for (i=0; i < phba->sli.num_rings; i++) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1199 | lpfc_memcpy_to_slim(phba->host_gp + i, &hgp, |
| 1200 | sizeof(*phba->host_gp)); |
James.Smart@Emulex.Com | f91b392 | 2005-10-28 20:29:28 -0400 | [diff] [blame] | 1201 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1202 | |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 1203 | /* Setup Port Group offset */ |
| 1204 | if (phba->sli_rev == 3) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1205 | pgp_offset = offsetof(struct lpfc_sli2_slim, |
| 1206 | mbx.us.s3_pgp.port); |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 1207 | else |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1208 | pgp_offset = offsetof(struct lpfc_sli2_slim, mbx.us.s2.port); |
| 1209 | pdma_addr = phba->slim2p.phys + pgp_offset; |
| 1210 | phba->pcb->pgpAddrHigh = putPaddrHigh(pdma_addr); |
| 1211 | phba->pcb->pgpAddrLow = putPaddrLow(pdma_addr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1212 | |
| 1213 | /* Use callback routine to setp rings in the pcb */ |
| 1214 | lpfc_config_pcb_setup(phba); |
| 1215 | |
| 1216 | /* special handling for LC HBAs */ |
| 1217 | if (lpfc_is_LC_HBA(phba->pcidev->device)) { |
| 1218 | uint32_t hbainit[5]; |
| 1219 | |
| 1220 | lpfc_hba_init(phba, hbainit); |
| 1221 | |
| 1222 | memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20); |
| 1223 | } |
| 1224 | |
| 1225 | /* Swap PCB if needed */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1226 | lpfc_sli_pcimem_bcopy(phba->pcb, phba->pcb, sizeof(PCB_t)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1227 | } |
| 1228 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1229 | /** |
| 1230 | * lpfc_kill_board: Prepare a mailbox command for killing board. |
| 1231 | * @phba: pointer to lpfc hba data structure. |
| 1232 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 1233 | * |
| 1234 | * The kill board mailbox command is used to tell firmware to perform a |
| 1235 | * graceful shutdown of a channel on a specified board to prepare for reset. |
| 1236 | * When the kill board mailbox command is received, the ER3 bit is set to 1 |
| 1237 | * in the Host Status register and the ER Attention bit is set to 1 in the |
| 1238 | * Host Attention register of the HBA function that received the kill board |
| 1239 | * command. |
| 1240 | * |
| 1241 | * This routine prepares the mailbox command for killing the board in |
| 1242 | * preparation for a graceful shutdown. |
| 1243 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1244 | void |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1245 | lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 1246 | { |
| 1247 | MAILBOX_t *mb = &pmb->mb; |
| 1248 | |
| 1249 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
| 1250 | mb->mbxCommand = MBX_KILL_BOARD; |
| 1251 | mb->mbxOwner = OWN_HOST; |
| 1252 | return; |
| 1253 | } |
| 1254 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1255 | /** |
| 1256 | * lpfc_mbox_put: Put a mailbox cmd into the tail of driver's mailbox queue. |
| 1257 | * @phba: pointer to lpfc hba data structure. |
| 1258 | * @mbq: pointer to the driver internal queue element for mailbox command. |
| 1259 | * |
| 1260 | * Driver maintains a internal mailbox command queue implemented as a linked |
| 1261 | * list. When a mailbox command is issued, it shall be put into the mailbox |
| 1262 | * command queue such that they shall be processed orderly as HBA can process |
| 1263 | * one mailbox command at a time. |
| 1264 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1265 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1266 | lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq) |
| 1267 | { |
| 1268 | struct lpfc_sli *psli; |
| 1269 | |
| 1270 | psli = &phba->sli; |
| 1271 | |
| 1272 | list_add_tail(&mbq->list, &psli->mboxq); |
| 1273 | |
| 1274 | psli->mboxq_cnt++; |
| 1275 | |
| 1276 | return; |
| 1277 | } |
| 1278 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1279 | /** |
| 1280 | * lpfc_mbox_get: Remove a mailbox cmd from the head of driver's mailbox queue. |
| 1281 | * @phba: pointer to lpfc hba data structure. |
| 1282 | * |
| 1283 | * Driver maintains a internal mailbox command queue implemented as a linked |
| 1284 | * list. When a mailbox command is issued, it shall be put into the mailbox |
| 1285 | * command queue such that they shall be processed orderly as HBA can process |
| 1286 | * one mailbox command at a time. After HBA finished processing a mailbox |
| 1287 | * command, the driver will remove a pending mailbox command from the head of |
| 1288 | * the mailbox command queue and send to the HBA for processing. |
| 1289 | * |
| 1290 | * Return codes |
| 1291 | * pointer to the driver internal queue element for mailbox command. |
| 1292 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1293 | LPFC_MBOXQ_t * |
| 1294 | lpfc_mbox_get(struct lpfc_hba * phba) |
| 1295 | { |
| 1296 | LPFC_MBOXQ_t *mbq = NULL; |
| 1297 | struct lpfc_sli *psli = &phba->sli; |
| 1298 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1299 | list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t, list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1300 | if (mbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1301 | psli->mboxq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1302 | |
| 1303 | return mbq; |
| 1304 | } |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 1305 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1306 | /** |
| 1307 | * lpfc_mbox_cmpl_put: Put mailbox command into mailbox command complete list. |
| 1308 | * @phba: pointer to lpfc hba data structure. |
| 1309 | * @mbq: pointer to the driver internal queue element for mailbox command. |
| 1310 | * |
| 1311 | * This routine put the completed mailbox command into the mailbox command |
| 1312 | * complete list. This routine is called from driver interrupt handler |
| 1313 | * context.The mailbox complete list is used by the driver worker thread |
| 1314 | * to process mailbox complete callback functions outside the driver interrupt |
| 1315 | * handler. |
| 1316 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1317 | void |
| 1318 | lpfc_mbox_cmpl_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq) |
| 1319 | { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 1320 | unsigned long iflag; |
| 1321 | |
Joe Perches | b1c1181 | 2008-02-03 17:28:22 +0200 | [diff] [blame] | 1322 | /* This function expects to be called from interrupt context */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 1323 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1324 | list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 1325 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1326 | return; |
| 1327 | } |
| 1328 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1329 | /** |
| 1330 | * lpfc_mbox_tmo_val: Retrieve mailbox command timeout value. |
| 1331 | * @phba: pointer to lpfc hba data structure. |
| 1332 | * @cmd: mailbox command code. |
| 1333 | * |
| 1334 | * This routine retrieves the proper timeout value according to the mailbox |
| 1335 | * command code. |
| 1336 | * |
| 1337 | * Return codes |
| 1338 | * Timeout value to be used for the given mailbox command |
| 1339 | **/ |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 1340 | int |
| 1341 | lpfc_mbox_tmo_val(struct lpfc_hba *phba, int cmd) |
| 1342 | { |
| 1343 | switch (cmd) { |
| 1344 | case MBX_WRITE_NV: /* 0x03 */ |
| 1345 | case MBX_UPDATE_CFG: /* 0x1B */ |
| 1346 | case MBX_DOWN_LOAD: /* 0x1C */ |
| 1347 | case MBX_DEL_LD_ENTRY: /* 0x1D */ |
| 1348 | case MBX_LOAD_AREA: /* 0x81 */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1349 | case MBX_WRITE_WWN: /* 0x98 */ |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 1350 | case MBX_LOAD_EXP_ROM: /* 0x9C */ |
| 1351 | return LPFC_MBOX_TMO_FLASH_CMD; |
| 1352 | } |
| 1353 | return LPFC_MBOX_TMO; |
| 1354 | } |