| 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 | d8e93df | 2009-05-22 14:53:05 -0400 | [diff] [blame] | 4 | * Copyright (C) 2004-2009 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 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 31 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 32 | #include "lpfc_hw.h" |
| 33 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 34 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 35 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 36 | #include "lpfc_disc.h" |
| 37 | #include "lpfc_scsi.h" |
| 38 | #include "lpfc.h" |
| 39 | #include "lpfc_logmsg.h" |
| 40 | #include "lpfc_crtn.h" |
| 41 | #include "lpfc_compat.h" |
| 42 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 43 | /** |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 44 | * lpfc_dump_static_vport - Dump HBA's static vport information. |
| 45 | * @phba: pointer to lpfc hba data structure. |
| 46 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 47 | * @offset: offset for dumping vport info. |
| 48 | * |
| 49 | * The dump mailbox command provides a method for the device driver to obtain |
| 50 | * various types of information from the HBA device. |
| 51 | * |
| 52 | * This routine prepares the mailbox command for dumping list of static |
| 53 | * vports to be created. |
| 54 | **/ |
| 55 | void |
| 56 | lpfc_dump_static_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, |
| 57 | uint16_t offset) |
| 58 | { |
| 59 | MAILBOX_t *mb; |
| 60 | void *ctx; |
| 61 | |
| 62 | mb = &pmb->u.mb; |
| 63 | ctx = pmb->context2; |
| 64 | |
| 65 | /* Setup to dump vport info region */ |
| 66 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
| 67 | mb->mbxCommand = MBX_DUMP_MEMORY; |
| 68 | mb->un.varDmp.cv = 1; |
| 69 | mb->un.varDmp.type = DMP_NV_PARAMS; |
| 70 | mb->un.varDmp.entry_index = offset; |
| 71 | mb->un.varDmp.region_id = DMP_REGION_VPORT; |
| 72 | mb->un.varDmp.word_cnt = DMP_RSP_SIZE/sizeof(uint32_t); |
| 73 | mb->un.varDmp.co = 0; |
| 74 | mb->un.varDmp.resp_offset = 0; |
| 75 | pmb->context2 = ctx; |
| 76 | mb->mbxOwner = OWN_HOST; |
| 77 | |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | /** |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame^] | 82 | * lpfc_down_link - Bring down HBAs link. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 83 | * @phba: pointer to lpfc hba data structure. |
| 84 | * @pmb: pointer to the driver internal queue element for mailbox command. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame^] | 85 | * |
| 86 | * This routine prepares a mailbox command to bring down HBA link. |
| 87 | **/ |
| 88 | void |
| 89 | lpfc_down_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 90 | { |
| 91 | MAILBOX_t *mb; |
| 92 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
| 93 | mb = &pmb->u.mb; |
| 94 | mb->mbxCommand = MBX_DOWN_LINK; |
| 95 | mb->mbxOwner = OWN_HOST; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * lpfc_dump_mem - Prepare a mailbox command for reading a region. |
| 100 | * @phba: pointer to lpfc hba data structure. |
| 101 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 102 | * @offset: offset into the region. |
| 103 | * @region_id: config region id. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 104 | * |
| 105 | * The dump mailbox command provides a method for the device driver to obtain |
| 106 | * various types of information from the HBA device. |
| 107 | * |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame^] | 108 | * This routine prepares the mailbox command for dumping HBA's config region. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 109 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 110 | void |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame^] | 111 | lpfc_dump_mem(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, uint16_t offset, |
| 112 | uint16_t region_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 113 | { |
| 114 | MAILBOX_t *mb; |
| 115 | void *ctx; |
| 116 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 117 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 118 | ctx = pmb->context2; |
| 119 | |
| 120 | /* Setup to dump VPD region */ |
| 121 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 122 | mb->mbxCommand = MBX_DUMP_MEMORY; |
| 123 | mb->un.varDmp.cv = 1; |
| 124 | mb->un.varDmp.type = DMP_NV_PARAMS; |
| 125 | mb->un.varDmp.entry_index = offset; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame^] | 126 | mb->un.varDmp.region_id = region_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 127 | mb->un.varDmp.word_cnt = (DMP_RSP_SIZE / sizeof (uint32_t)); |
| 128 | mb->un.varDmp.co = 0; |
| 129 | mb->un.varDmp.resp_offset = 0; |
| 130 | pmb->context2 = ctx; |
| 131 | mb->mbxOwner = OWN_HOST; |
| 132 | return; |
| 133 | } |
| 134 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 135 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 136 | * lpfc_dump_wakeup_param - Prepare mailbox command for retrieving wakeup params |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 137 | * @phba: pointer to lpfc hba data structure. |
| 138 | * @pmb: pointer to the driver internal queue element for mailbox command. |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 139 | * |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 140 | * This function create a dump memory mailbox command to dump wake up |
| 141 | * parameters. |
| 142 | */ |
| 143 | void |
| 144 | lpfc_dump_wakeup_param(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 145 | { |
| 146 | MAILBOX_t *mb; |
| 147 | void *ctx; |
| 148 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 149 | mb = &pmb->u.mb; |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 150 | /* Save context so that we can restore after memset */ |
| 151 | ctx = pmb->context2; |
| 152 | |
| 153 | /* Setup to dump VPD region */ |
| 154 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
| 155 | mb->mbxCommand = MBX_DUMP_MEMORY; |
| 156 | mb->mbxOwner = OWN_HOST; |
| 157 | mb->un.varDmp.cv = 1; |
| 158 | mb->un.varDmp.type = DMP_NV_PARAMS; |
| 159 | mb->un.varDmp.entry_index = 0; |
| 160 | mb->un.varDmp.region_id = WAKE_UP_PARMS_REGION_ID; |
| 161 | mb->un.varDmp.word_cnt = WAKE_UP_PARMS_WORD_SIZE; |
| 162 | mb->un.varDmp.co = 0; |
| 163 | mb->un.varDmp.resp_offset = 0; |
| 164 | pmb->context2 = ctx; |
| 165 | return; |
| 166 | } |
| 167 | |
| 168 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 169 | * lpfc_read_nv - Prepare a mailbox command for reading HBA's NVRAM param |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 170 | * @phba: pointer to lpfc hba data structure. |
| 171 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 172 | * |
| 173 | * The read NVRAM mailbox command returns the HBA's non-volatile parameters |
| 174 | * that are used as defaults when the Fibre Channel link is brought on-line. |
| 175 | * |
| 176 | * This routine prepares the mailbox command for reading information stored |
| 177 | * in the HBA's NVRAM. Specifically, the HBA's WWNN and WWPN. |
| 178 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 179 | void |
| 180 | lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 181 | { |
| 182 | MAILBOX_t *mb; |
| 183 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 184 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 185 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 186 | mb->mbxCommand = MBX_READ_NV; |
| 187 | mb->mbxOwner = OWN_HOST; |
| 188 | return; |
| 189 | } |
| 190 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 191 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 192 | * lpfc_config_async - Prepare a mailbox command for enabling HBA async event |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 193 | * @phba: pointer to lpfc hba data structure. |
| 194 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 195 | * @ring: ring number for the asynchronous event to be configured. |
| 196 | * |
| 197 | * The asynchronous event enable mailbox command is used to enable the |
| 198 | * asynchronous event posting via the ASYNC_STATUS_CN IOCB response and |
| 199 | * specifies the default ring to which events are posted. |
| 200 | * |
| 201 | * This routine prepares the mailbox command for enabling HBA asynchronous |
| 202 | * event support on a IOCB ring. |
| 203 | **/ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 204 | void |
| 205 | lpfc_config_async(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, |
| 206 | uint32_t ring) |
| 207 | { |
| 208 | MAILBOX_t *mb; |
| 209 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 210 | mb = &pmb->u.mb; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 211 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 212 | mb->mbxCommand = MBX_ASYNCEVT_ENABLE; |
| 213 | mb->un.varCfgAsyncEvent.ring = ring; |
| 214 | mb->mbxOwner = OWN_HOST; |
| 215 | return; |
| 216 | } |
| 217 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 218 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 219 | * lpfc_heart_beat - Prepare a mailbox command for heart beat |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 220 | * @phba: pointer to lpfc hba data structure. |
| 221 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 222 | * |
| 223 | * The heart beat mailbox command is used to detect an unresponsive HBA, which |
| 224 | * is defined as any device where no error attention is sent and both mailbox |
| 225 | * and rings are not processed. |
| 226 | * |
| 227 | * This routine prepares the mailbox command for issuing a heart beat in the |
| 228 | * form of mailbox command to the HBA. The timely completion of the heart |
| 229 | * beat mailbox command indicates the health of the HBA. |
| 230 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 231 | void |
| 232 | lpfc_heart_beat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 233 | { |
| 234 | MAILBOX_t *mb; |
| 235 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 236 | mb = &pmb->u.mb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 237 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 238 | mb->mbxCommand = MBX_HEARTBEAT; |
| 239 | mb->mbxOwner = OWN_HOST; |
| 240 | return; |
| 241 | } |
| 242 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 243 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 244 | * lpfc_read_la - Prepare a mailbox command for reading HBA link attention |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 245 | * @phba: pointer to lpfc hba data structure. |
| 246 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 247 | * @mp: DMA buffer memory for reading the link attention information into. |
| 248 | * |
| 249 | * The read link attention mailbox command is issued to read the Link Event |
| 250 | * Attention information indicated by the HBA port when the Link Event bit |
| 251 | * of the Host Attention (HSTATT) register is set to 1. A Link Event |
| 252 | * Attention occurs based on an exception detected at the Fibre Channel link |
| 253 | * interface. |
| 254 | * |
| 255 | * This routine prepares the mailbox command for reading HBA link attention |
| 256 | * information. A DMA memory has been set aside and address passed to the |
| 257 | * HBA through @mp for the HBA to DMA link attention information into the |
| 258 | * memory as part of the execution of the mailbox command. |
| 259 | * |
| 260 | * Return codes |
| 261 | * 0 - Success (currently always return 0) |
| 262 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 263 | int |
| 264 | lpfc_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, struct lpfc_dmabuf *mp) |
| 265 | { |
| 266 | MAILBOX_t *mb; |
| 267 | struct lpfc_sli *psli; |
| 268 | |
| 269 | psli = &phba->sli; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 270 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 271 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 272 | |
| 273 | INIT_LIST_HEAD(&mp->list); |
| 274 | mb->mbxCommand = MBX_READ_LA64; |
| 275 | mb->un.varReadLA.un.lilpBde64.tus.f.bdeSize = 128; |
| 276 | mb->un.varReadLA.un.lilpBde64.addrHigh = putPaddrHigh(mp->phys); |
| 277 | mb->un.varReadLA.un.lilpBde64.addrLow = putPaddrLow(mp->phys); |
| 278 | |
| 279 | /* Save address for later completion and set the owner to host so that |
| 280 | * the FW knows this mailbox is available for processing. |
| 281 | */ |
| 282 | pmb->context1 = (uint8_t *) mp; |
| 283 | mb->mbxOwner = OWN_HOST; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 284 | return (0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 285 | } |
| 286 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 287 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 288 | * lpfc_clear_la - Prepare a mailbox command for clearing HBA link attention |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 289 | * @phba: pointer to lpfc hba data structure. |
| 290 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 291 | * |
| 292 | * The clear link attention mailbox command is issued to clear the link event |
| 293 | * attention condition indicated by the Link Event bit of the Host Attention |
| 294 | * (HSTATT) register. The link event attention condition is cleared only if |
| 295 | * the event tag specified matches that of the current link event counter. |
| 296 | * The current event tag is read using the read link attention event mailbox |
| 297 | * command. |
| 298 | * |
| 299 | * This routine prepares the mailbox command for clearing HBA link attention |
| 300 | * information. |
| 301 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 302 | void |
| 303 | lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 304 | { |
| 305 | MAILBOX_t *mb; |
| 306 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 307 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 308 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 309 | |
| 310 | mb->un.varClearLA.eventTag = phba->fc_eventTag; |
| 311 | mb->mbxCommand = MBX_CLEAR_LA; |
| 312 | mb->mbxOwner = OWN_HOST; |
| 313 | return; |
| 314 | } |
| 315 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 316 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 317 | * lpfc_config_link - Prepare a mailbox command for configuring link on a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 318 | * @phba: pointer to lpfc hba data structure. |
| 319 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 320 | * |
| 321 | * The configure link mailbox command is used before the initialize link |
| 322 | * mailbox command to override default value and to configure link-oriented |
| 323 | * parameters such as DID address and various timers. Typically, this |
| 324 | * command would be used after an F_Port login to set the returned DID address |
| 325 | * and the fabric timeout values. This command is not valid before a configure |
| 326 | * port command has configured the HBA port. |
| 327 | * |
| 328 | * This routine prepares the mailbox command for configuring link on a HBA. |
| 329 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 330 | void |
| 331 | lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 332 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 333 | struct lpfc_vport *vport = phba->pport; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 334 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 335 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 336 | |
| 337 | /* NEW_FEATURE |
| 338 | * SLI-2, Coalescing Response Feature. |
| 339 | */ |
| 340 | if (phba->cfg_cr_delay) { |
| 341 | mb->un.varCfgLnk.cr = 1; |
| 342 | mb->un.varCfgLnk.ci = 1; |
| 343 | mb->un.varCfgLnk.cr_delay = phba->cfg_cr_delay; |
| 344 | mb->un.varCfgLnk.cr_count = phba->cfg_cr_count; |
| 345 | } |
| 346 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 347 | mb->un.varCfgLnk.myId = vport->fc_myDID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 348 | mb->un.varCfgLnk.edtov = phba->fc_edtov; |
| 349 | mb->un.varCfgLnk.arbtov = phba->fc_arbtov; |
| 350 | mb->un.varCfgLnk.ratov = phba->fc_ratov; |
| 351 | mb->un.varCfgLnk.rttov = phba->fc_rttov; |
| 352 | mb->un.varCfgLnk.altov = phba->fc_altov; |
| 353 | mb->un.varCfgLnk.crtov = phba->fc_crtov; |
| 354 | mb->un.varCfgLnk.citov = phba->fc_citov; |
| 355 | |
| 356 | if (phba->cfg_ack0) |
| 357 | mb->un.varCfgLnk.ack0_enable = 1; |
| 358 | |
| 359 | mb->mbxCommand = MBX_CONFIG_LINK; |
| 360 | mb->mbxOwner = OWN_HOST; |
| 361 | return; |
| 362 | } |
| 363 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 364 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 365 | * lpfc_config_msi - Prepare a mailbox command for configuring msi-x |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 366 | * @phba: pointer to lpfc hba data structure. |
| 367 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 368 | * |
| 369 | * The configure MSI-X mailbox command is used to configure the HBA's SLI-3 |
| 370 | * MSI-X multi-message interrupt vector association to interrupt attention |
| 371 | * conditions. |
| 372 | * |
| 373 | * Return codes |
| 374 | * 0 - Success |
| 375 | * -EINVAL - Failure |
| 376 | **/ |
| 377 | int |
| 378 | lpfc_config_msi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 379 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 380 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 381 | uint32_t attentionConditions[2]; |
| 382 | |
| 383 | /* Sanity check */ |
| 384 | if (phba->cfg_use_msi != 2) { |
| 385 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 386 | "0475 Not configured for supporting MSI-X " |
| 387 | "cfg_use_msi: 0x%x\n", phba->cfg_use_msi); |
| 388 | return -EINVAL; |
| 389 | } |
| 390 | |
| 391 | if (phba->sli_rev < 3) { |
| 392 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 393 | "0476 HBA not supporting SLI-3 or later " |
| 394 | "SLI Revision: 0x%x\n", phba->sli_rev); |
| 395 | return -EINVAL; |
| 396 | } |
| 397 | |
| 398 | /* Clear mailbox command fields */ |
| 399 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
| 400 | |
| 401 | /* |
| 402 | * SLI-3, Message Signaled Interrupt Fearure. |
| 403 | */ |
| 404 | |
| 405 | /* Multi-message attention configuration */ |
| 406 | attentionConditions[0] = (HA_R0ATT | HA_R1ATT | HA_R2ATT | HA_ERATT | |
| 407 | HA_LATT | HA_MBATT); |
| 408 | attentionConditions[1] = 0; |
| 409 | |
| 410 | mb->un.varCfgMSI.attentionConditions[0] = attentionConditions[0]; |
| 411 | mb->un.varCfgMSI.attentionConditions[1] = attentionConditions[1]; |
| 412 | |
| 413 | /* |
| 414 | * Set up message number to HA bit association |
| 415 | */ |
| 416 | #ifdef __BIG_ENDIAN_BITFIELD |
| 417 | /* RA0 (FCP Ring) */ |
| 418 | mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS] = 1; |
| 419 | /* RA1 (Other Protocol Extra Ring) */ |
| 420 | mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS] = 1; |
| 421 | #else /* __LITTLE_ENDIAN_BITFIELD */ |
| 422 | /* RA0 (FCP Ring) */ |
| 423 | mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS^3] = 1; |
| 424 | /* RA1 (Other Protocol Extra Ring) */ |
| 425 | mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS^3] = 1; |
| 426 | #endif |
| 427 | /* Multi-message interrupt autoclear configuration*/ |
| 428 | mb->un.varCfgMSI.autoClearHA[0] = attentionConditions[0]; |
| 429 | mb->un.varCfgMSI.autoClearHA[1] = attentionConditions[1]; |
| 430 | |
| 431 | /* For now, HBA autoclear does not work reliably, disable it */ |
| 432 | mb->un.varCfgMSI.autoClearHA[0] = 0; |
| 433 | mb->un.varCfgMSI.autoClearHA[1] = 0; |
| 434 | |
| 435 | /* Set command and owner bit */ |
| 436 | mb->mbxCommand = MBX_CONFIG_MSI; |
| 437 | mb->mbxOwner = OWN_HOST; |
| 438 | |
| 439 | return 0; |
| 440 | } |
| 441 | |
| 442 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 443 | * lpfc_init_link - Prepare a mailbox command for initialize link on a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 444 | * @phba: pointer to lpfc hba data structure. |
| 445 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 446 | * @topology: the link topology for the link to be initialized to. |
| 447 | * @linkspeed: the link speed for the link to be initialized to. |
| 448 | * |
| 449 | * The initialize link mailbox command is used to initialize the Fibre |
| 450 | * Channel link. This command must follow a configure port command that |
| 451 | * establishes the mode of operation. |
| 452 | * |
| 453 | * This routine prepares the mailbox command for initializing link on a HBA |
| 454 | * with the specified link topology and speed. |
| 455 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 456 | void |
| 457 | lpfc_init_link(struct lpfc_hba * phba, |
| 458 | LPFC_MBOXQ_t * pmb, uint32_t topology, uint32_t linkspeed) |
| 459 | { |
| 460 | lpfc_vpd_t *vpd; |
| 461 | struct lpfc_sli *psli; |
| 462 | MAILBOX_t *mb; |
| 463 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 464 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 465 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 466 | |
| 467 | psli = &phba->sli; |
| 468 | switch (topology) { |
| 469 | case FLAGS_TOPOLOGY_MODE_LOOP_PT: |
| 470 | mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP; |
| 471 | mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER; |
| 472 | break; |
| 473 | case FLAGS_TOPOLOGY_MODE_PT_PT: |
| 474 | mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT; |
| 475 | break; |
| 476 | case FLAGS_TOPOLOGY_MODE_LOOP: |
| 477 | mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP; |
| 478 | break; |
| 479 | case FLAGS_TOPOLOGY_MODE_PT_LOOP: |
| 480 | mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT; |
| 481 | mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER; |
| 482 | break; |
Jamie Wellnitz | 367c271 | 2006-02-28 19:25:32 -0500 | [diff] [blame] | 483 | case FLAGS_LOCAL_LB: |
| 484 | mb->un.varInitLnk.link_flags = FLAGS_LOCAL_LB; |
| 485 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 486 | } |
| 487 | |
James Smart | 4b0b91d | 2006-04-15 11:53:00 -0400 | [diff] [blame] | 488 | /* Enable asynchronous ABTS responses from firmware */ |
| 489 | mb->un.varInitLnk.link_flags |= FLAGS_IMED_ABORT; |
| 490 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 491 | /* NEW_FEATURE |
| 492 | * Setting up the link speed |
| 493 | */ |
| 494 | vpd = &phba->vpd; |
| 495 | if (vpd->rev.feaLevelHigh >= 0x02){ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 496 | switch(linkspeed){ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 497 | case LINK_SPEED_1G: |
| 498 | case LINK_SPEED_2G: |
| 499 | case LINK_SPEED_4G: |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 500 | case LINK_SPEED_8G: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 501 | mb->un.varInitLnk.link_flags |= |
| 502 | FLAGS_LINK_SPEED; |
| 503 | mb->un.varInitLnk.link_speed = linkspeed; |
| 504 | break; |
| 505 | case LINK_SPEED_AUTO: |
| 506 | default: |
| 507 | mb->un.varInitLnk.link_speed = |
| 508 | LINK_SPEED_AUTO; |
| 509 | break; |
| 510 | } |
| 511 | |
| 512 | } |
| 513 | else |
| 514 | mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO; |
| 515 | |
| 516 | mb->mbxCommand = (volatile uint8_t)MBX_INIT_LINK; |
| 517 | mb->mbxOwner = OWN_HOST; |
| 518 | mb->un.varInitLnk.fabric_AL_PA = phba->fc_pref_ALPA; |
| 519 | return; |
| 520 | } |
| 521 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 522 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 523 | * lpfc_read_sparam - Prepare a mailbox command for reading HBA parameters |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 524 | * @phba: pointer to lpfc hba data structure. |
| 525 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 526 | * @vpi: virtual N_Port identifier. |
| 527 | * |
| 528 | * The read service parameter mailbox command is used to read the HBA port |
| 529 | * service parameters. The service parameters are read into the buffer |
| 530 | * specified directly by a BDE in the mailbox command. These service |
| 531 | * parameters may then be used to build the payload of an N_Port/F_POrt |
| 532 | * login request and reply (LOGI/ACC). |
| 533 | * |
| 534 | * This routine prepares the mailbox command for reading HBA port service |
| 535 | * parameters. The DMA memory is allocated in this function and the addresses |
| 536 | * are populated into the mailbox command for the HBA to DMA the service |
| 537 | * parameters into. |
| 538 | * |
| 539 | * Return codes |
| 540 | * 0 - Success |
| 541 | * 1 - DMA memory allocation failed |
| 542 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 543 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 544 | lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 545 | { |
| 546 | struct lpfc_dmabuf *mp; |
| 547 | MAILBOX_t *mb; |
| 548 | struct lpfc_sli *psli; |
| 549 | |
| 550 | psli = &phba->sli; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 551 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 552 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 553 | |
| 554 | mb->mbxOwner = OWN_HOST; |
| 555 | |
| 556 | /* Get a buffer to hold the HBAs Service Parameters */ |
| 557 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 558 | mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 559 | if (mp) |
| 560 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 561 | if (!mp || !mp->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 562 | kfree(mp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 563 | mb->mbxCommand = MBX_READ_SPARM64; |
| 564 | /* READ_SPARAM: no buffers */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 565 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
| 566 | "0301 READ_SPARAM: no buffers\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 567 | return (1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 568 | } |
| 569 | INIT_LIST_HEAD(&mp->list); |
| 570 | mb->mbxCommand = MBX_READ_SPARM64; |
| 571 | mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm); |
| 572 | mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys); |
| 573 | mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 574 | mb->un.varRdSparm.vpi = vpi + phba->vpi_base; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 575 | |
| 576 | /* save address for completion */ |
| 577 | pmb->context1 = mp; |
| 578 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 579 | return (0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 580 | } |
| 581 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 582 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 583 | * lpfc_unreg_did - Prepare a mailbox command for unregistering DID |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 584 | * @phba: pointer to lpfc hba data structure. |
| 585 | * @vpi: virtual N_Port identifier. |
| 586 | * @did: remote port identifier. |
| 587 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 588 | * |
| 589 | * The unregister DID mailbox command is used to unregister an N_Port/F_Port |
| 590 | * login for an unknown RPI by specifying the DID of a remote port. This |
| 591 | * command frees an RPI context in the HBA port. This has the effect of |
| 592 | * performing an implicit N_Port/F_Port logout. |
| 593 | * |
| 594 | * This routine prepares the mailbox command for unregistering a remote |
| 595 | * N_Port/F_Port (DID) login. |
| 596 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 597 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 598 | lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did, |
| 599 | LPFC_MBOXQ_t * pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 600 | { |
| 601 | MAILBOX_t *mb; |
| 602 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 603 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 604 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 605 | |
| 606 | mb->un.varUnregDID.did = did; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 607 | if (vpi != 0xffff) |
| 608 | vpi += phba->vpi_base; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 609 | mb->un.varUnregDID.vpi = vpi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 610 | |
| 611 | mb->mbxCommand = MBX_UNREG_D_ID; |
| 612 | mb->mbxOwner = OWN_HOST; |
| 613 | return; |
| 614 | } |
| 615 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 616 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 617 | * lpfc_read_config - Prepare a mailbox command for reading HBA configuration |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 618 | * @phba: pointer to lpfc hba data structure. |
| 619 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 620 | * |
| 621 | * The read configuration mailbox command is used to read the HBA port |
| 622 | * configuration parameters. This mailbox command provides a method for |
| 623 | * seeing any parameters that may have changed via various configuration |
| 624 | * mailbox commands. |
| 625 | * |
| 626 | * This routine prepares the mailbox command for reading out HBA configuration |
| 627 | * parameters. |
| 628 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 629 | void |
| 630 | lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 631 | { |
| 632 | MAILBOX_t *mb; |
| 633 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 634 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 635 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 636 | |
| 637 | mb->mbxCommand = MBX_READ_CONFIG; |
| 638 | mb->mbxOwner = OWN_HOST; |
| 639 | return; |
| 640 | } |
| 641 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 642 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 643 | * lpfc_read_lnk_stat - Prepare a mailbox command for reading HBA link stats |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 644 | * @phba: pointer to lpfc hba data structure. |
| 645 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 646 | * |
| 647 | * The read link status mailbox command is used to read the link status from |
| 648 | * the HBA. Link status includes all link-related error counters. These |
| 649 | * counters are maintained by the HBA and originated in the link hardware |
| 650 | * unit. Note that all of these counters wrap. |
| 651 | * |
| 652 | * This routine prepares the mailbox command for reading out HBA link status. |
| 653 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 654 | void |
| 655 | lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 656 | { |
| 657 | MAILBOX_t *mb; |
| 658 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 659 | mb = &pmb->u.mb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 660 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 661 | |
| 662 | mb->mbxCommand = MBX_READ_LNK_STAT; |
| 663 | mb->mbxOwner = OWN_HOST; |
| 664 | return; |
| 665 | } |
| 666 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 667 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 668 | * lpfc_reg_rpi - Prepare a mailbox command for registering remote login |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 669 | * @phba: pointer to lpfc hba data structure. |
| 670 | * @vpi: virtual N_Port identifier. |
| 671 | * @did: remote port identifier. |
| 672 | * @param: pointer to memory holding the server parameters. |
| 673 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 674 | * @flag: action flag to be passed back for the complete function. |
| 675 | * |
| 676 | * The registration login mailbox command is used to register an N_Port or |
| 677 | * F_Port login. This registration allows the HBA to cache the remote N_Port |
| 678 | * service parameters internally and thereby make the appropriate FC-2 |
| 679 | * decisions. The remote port service parameters are handed off by the driver |
| 680 | * to the HBA using a descriptor entry that directly identifies a buffer in |
| 681 | * host memory. In exchange, the HBA returns an RPI identifier. |
| 682 | * |
| 683 | * This routine prepares the mailbox command for registering remote port login. |
| 684 | * The function allocates DMA buffer for passing the service parameters to the |
| 685 | * HBA with the mailbox command. |
| 686 | * |
| 687 | * Return codes |
| 688 | * 0 - Success |
| 689 | * 1 - DMA memory allocation failed |
| 690 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 691 | int |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 692 | lpfc_reg_rpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t did, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 693 | uint8_t *param, LPFC_MBOXQ_t *pmb, uint32_t flag) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 694 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 695 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 696 | uint8_t *sparam; |
| 697 | struct lpfc_dmabuf *mp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 698 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 699 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 700 | |
| 701 | mb->un.varRegLogin.rpi = 0; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 702 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 703 | mb->un.varRegLogin.rpi = lpfc_sli4_alloc_rpi(phba); |
| 704 | if (mb->un.varRegLogin.rpi == LPFC_RPI_ALLOC_ERROR) |
| 705 | return 1; |
| 706 | } |
| 707 | |
| 708 | mb->un.varRegLogin.vpi = vpi + phba->vpi_base; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 709 | mb->un.varRegLogin.did = did; |
| 710 | mb->un.varWords[30] = flag; /* Set flag to issue action on cmpl */ |
| 711 | |
| 712 | mb->mbxOwner = OWN_HOST; |
| 713 | |
| 714 | /* Get a buffer to hold NPorts Service Parameters */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 715 | mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 716 | if (mp) |
| 717 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 718 | if (!mp || !mp->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 719 | kfree(mp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 720 | mb->mbxCommand = MBX_REG_LOGIN64; |
| 721 | /* REG_LOGIN: no buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 722 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 723 | "0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, " |
| 724 | "flag x%x\n", vpi, did, flag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 725 | return (1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 726 | } |
| 727 | INIT_LIST_HEAD(&mp->list); |
| 728 | sparam = mp->virt; |
| 729 | |
| 730 | /* Copy param's into a new buffer */ |
| 731 | memcpy(sparam, param, sizeof (struct serv_parm)); |
| 732 | |
| 733 | /* save address for completion */ |
| 734 | pmb->context1 = (uint8_t *) mp; |
| 735 | |
| 736 | mb->mbxCommand = MBX_REG_LOGIN64; |
| 737 | mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm); |
| 738 | mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys); |
| 739 | mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys); |
| 740 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 741 | return (0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 742 | } |
| 743 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 744 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 745 | * lpfc_unreg_login - Prepare a mailbox command for unregistering remote login |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 746 | * @phba: pointer to lpfc hba data structure. |
| 747 | * @vpi: virtual N_Port identifier. |
| 748 | * @rpi: remote port identifier |
| 749 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 750 | * |
| 751 | * The unregistration login mailbox command is used to unregister an N_Port |
| 752 | * or F_Port login. This command frees an RPI context in the HBA. It has the |
| 753 | * effect of performing an implicit N_Port/F_Port logout. |
| 754 | * |
| 755 | * This routine prepares the mailbox command for unregistering remote port |
| 756 | * login. |
| 757 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 758 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 759 | lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi, |
| 760 | LPFC_MBOXQ_t * pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 761 | { |
| 762 | MAILBOX_t *mb; |
| 763 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 764 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 765 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 766 | |
| 767 | mb->un.varUnregLogin.rpi = (uint16_t) rpi; |
| 768 | mb->un.varUnregLogin.rsvd1 = 0; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 769 | mb->un.varUnregLogin.vpi = vpi + phba->vpi_base; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 770 | |
| 771 | mb->mbxCommand = MBX_UNREG_LOGIN; |
| 772 | mb->mbxOwner = OWN_HOST; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 773 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 774 | return; |
| 775 | } |
| 776 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 777 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 778 | * lpfc_reg_vpi - Prepare a mailbox command for registering vport identifier |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 779 | * @phba: pointer to lpfc hba data structure. |
| 780 | * @vpi: virtual N_Port identifier. |
| 781 | * @sid: Fibre Channel S_ID (N_Port_ID assigned to a virtual N_Port). |
| 782 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 783 | * |
| 784 | * The registration vport identifier mailbox command is used to activate a |
| 785 | * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the |
| 786 | * N_Port_ID against the information in the selected virtual N_Port context |
| 787 | * block and marks it active to allow normal processing of IOCB commands and |
| 788 | * received unsolicited exchanges. |
| 789 | * |
| 790 | * This routine prepares the mailbox command for registering a virtual N_Port. |
| 791 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 792 | void |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 793 | lpfc_reg_vpi(struct lpfc_vport *vport, LPFC_MBOXQ_t *pmb) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 794 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 795 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 796 | |
| 797 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 798 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 799 | mb->un.varRegVpi.vpi = vport->vpi + vport->phba->vpi_base; |
| 800 | mb->un.varRegVpi.sid = vport->fc_myDID; |
| 801 | mb->un.varRegVpi.vfi = vport->vfi + vport->phba->vfi_base; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 802 | |
| 803 | mb->mbxCommand = MBX_REG_VPI; |
| 804 | mb->mbxOwner = OWN_HOST; |
| 805 | return; |
| 806 | |
| 807 | } |
| 808 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 809 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 810 | * lpfc_unreg_vpi - Prepare a mailbox command for unregistering vport id |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 811 | * @phba: pointer to lpfc hba data structure. |
| 812 | * @vpi: virtual N_Port identifier. |
| 813 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 814 | * |
| 815 | * The unregistration vport identifier mailbox command is used to inactivate |
| 816 | * a virtual N_Port. The driver must have logged out and unregistered all |
| 817 | * remote N_Ports to abort any activity on the virtual N_Port. The HBA will |
| 818 | * unregisters any default RPIs associated with the specified vpi, aborting |
| 819 | * any active exchanges. The HBA will post the mailbox response after making |
| 820 | * the virtual N_Port inactive. |
| 821 | * |
| 822 | * This routine prepares the mailbox command for unregistering a virtual |
| 823 | * N_Port. |
| 824 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 825 | void |
| 826 | lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb) |
| 827 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 828 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 829 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 830 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 831 | mb->un.varUnregVpi.vpi = vpi + phba->vpi_base; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 832 | |
| 833 | mb->mbxCommand = MBX_UNREG_VPI; |
| 834 | mb->mbxOwner = OWN_HOST; |
| 835 | return; |
| 836 | |
| 837 | } |
| 838 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 839 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 840 | * lpfc_config_pcb_setup - Set up IOCB rings in the Port Control Block (PCB) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 841 | * @phba: pointer to lpfc hba data structure. |
| 842 | * |
| 843 | * This routine sets up and initializes the IOCB rings in the Port Control |
| 844 | * Block (PCB). |
| 845 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 846 | static void |
| 847 | lpfc_config_pcb_setup(struct lpfc_hba * phba) |
| 848 | { |
| 849 | struct lpfc_sli *psli = &phba->sli; |
| 850 | struct lpfc_sli_ring *pring; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 851 | PCB_t *pcbp = phba->pcb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 852 | dma_addr_t pdma_addr; |
| 853 | uint32_t offset; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 854 | uint32_t iocbCnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 855 | int i; |
| 856 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 857 | pcbp->maxRing = (psli->num_rings - 1); |
| 858 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 859 | for (i = 0; i < psli->num_rings; i++) { |
| 860 | pring = &psli->ring[i]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 861 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 862 | pring->sizeCiocb = phba->sli_rev == 3 ? SLI3_IOCB_CMD_SIZE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 863 | SLI2_IOCB_CMD_SIZE; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 864 | pring->sizeRiocb = phba->sli_rev == 3 ? SLI3_IOCB_RSP_SIZE: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 865 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 866 | /* A ring MUST have both cmd and rsp entries defined to be |
| 867 | valid */ |
| 868 | if ((pring->numCiocb == 0) || (pring->numRiocb == 0)) { |
| 869 | pcbp->rdsc[i].cmdEntries = 0; |
| 870 | pcbp->rdsc[i].rspEntries = 0; |
| 871 | pcbp->rdsc[i].cmdAddrHigh = 0; |
| 872 | pcbp->rdsc[i].rspAddrHigh = 0; |
| 873 | pcbp->rdsc[i].cmdAddrLow = 0; |
| 874 | pcbp->rdsc[i].rspAddrLow = 0; |
| 875 | pring->cmdringaddr = NULL; |
| 876 | pring->rspringaddr = NULL; |
| 877 | continue; |
| 878 | } |
| 879 | /* Command ring setup for ring */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 880 | pring->cmdringaddr = (void *)&phba->IOCBs[iocbCnt]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 881 | pcbp->rdsc[i].cmdEntries = pring->numCiocb; |
| 882 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 883 | offset = (uint8_t *) &phba->IOCBs[iocbCnt] - |
| 884 | (uint8_t *) phba->slim2p.virt; |
| 885 | pdma_addr = phba->slim2p.phys + offset; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 886 | pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr); |
| 887 | pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr); |
| 888 | iocbCnt += pring->numCiocb; |
| 889 | |
| 890 | /* Response ring setup for ring */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 891 | pring->rspringaddr = (void *) &phba->IOCBs[iocbCnt]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 892 | |
| 893 | pcbp->rdsc[i].rspEntries = pring->numRiocb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 894 | offset = (uint8_t *)&phba->IOCBs[iocbCnt] - |
| 895 | (uint8_t *)phba->slim2p.virt; |
| 896 | pdma_addr = phba->slim2p.phys + offset; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 897 | pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr); |
| 898 | pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr); |
| 899 | iocbCnt += pring->numRiocb; |
| 900 | } |
| 901 | } |
| 902 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 903 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 904 | * lpfc_read_rev - Prepare a mailbox command for reading HBA revision |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 905 | * @phba: pointer to lpfc hba data structure. |
| 906 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 907 | * |
| 908 | * The read revision mailbox command is used to read the revision levels of |
| 909 | * the HBA components. These components include hardware units, resident |
| 910 | * firmware, and available firmware. HBAs that supports SLI-3 mode of |
| 911 | * operation provide different response information depending on the version |
| 912 | * requested by the driver. |
| 913 | * |
| 914 | * This routine prepares the mailbox command for reading HBA revision |
| 915 | * information. |
| 916 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 917 | void |
| 918 | lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 919 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 920 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 921 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 922 | mb->un.varRdRev.cv = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 923 | mb->un.varRdRev.v3req = 1; /* Request SLI3 info */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 924 | mb->mbxCommand = MBX_READ_REV; |
| 925 | mb->mbxOwner = OWN_HOST; |
| 926 | return; |
| 927 | } |
| 928 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 929 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 930 | * lpfc_build_hbq_profile2 - Set up the HBQ Selection Profile 2 |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 931 | * @hbqmb: pointer to the HBQ configuration data structure in mailbox command. |
| 932 | * @hbq_desc: pointer to the HBQ selection profile descriptor. |
| 933 | * |
| 934 | * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA |
| 935 | * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs |
| 936 | * the Sequence Length Test using the fields in the Selection Profile 2 |
| 937 | * extension in words 20:31. |
| 938 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 939 | static void |
| 940 | lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb, |
| 941 | struct lpfc_hbq_init *hbq_desc) |
| 942 | { |
| 943 | hbqmb->profiles.profile2.seqlenbcnt = hbq_desc->seqlenbcnt; |
| 944 | hbqmb->profiles.profile2.maxlen = hbq_desc->maxlen; |
| 945 | hbqmb->profiles.profile2.seqlenoff = hbq_desc->seqlenoff; |
| 946 | } |
| 947 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 948 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 949 | * lpfc_build_hbq_profile3 - Set up the HBQ Selection Profile 3 |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 950 | * @hbqmb: pointer to the HBQ configuration data structure in mailbox command. |
| 951 | * @hbq_desc: pointer to the HBQ selection profile descriptor. |
| 952 | * |
| 953 | * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA |
| 954 | * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs |
| 955 | * the Sequence Length Test and Byte Field Test using the fields in the |
| 956 | * Selection Profile 3 extension in words 20:31. |
| 957 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 958 | static void |
| 959 | lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb, |
| 960 | struct lpfc_hbq_init *hbq_desc) |
| 961 | { |
| 962 | hbqmb->profiles.profile3.seqlenbcnt = hbq_desc->seqlenbcnt; |
| 963 | hbqmb->profiles.profile3.maxlen = hbq_desc->maxlen; |
| 964 | hbqmb->profiles.profile3.cmdcodeoff = hbq_desc->cmdcodeoff; |
| 965 | hbqmb->profiles.profile3.seqlenoff = hbq_desc->seqlenoff; |
| 966 | memcpy(&hbqmb->profiles.profile3.cmdmatch, hbq_desc->cmdmatch, |
| 967 | sizeof(hbqmb->profiles.profile3.cmdmatch)); |
| 968 | } |
| 969 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 970 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 971 | * lpfc_build_hbq_profile5 - Set up the HBQ Selection Profile 5 |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 972 | * @hbqmb: pointer to the HBQ configuration data structure in mailbox command. |
| 973 | * @hbq_desc: pointer to the HBQ selection profile descriptor. |
| 974 | * |
| 975 | * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The |
| 976 | * HBA tests the initial frame of an incoming sequence using the frame's |
| 977 | * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test |
| 978 | * and Byte Field Test using the fields in the Selection Profile 5 extension |
| 979 | * words 20:31. |
| 980 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 981 | static void |
| 982 | lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb, |
| 983 | struct lpfc_hbq_init *hbq_desc) |
| 984 | { |
| 985 | hbqmb->profiles.profile5.seqlenbcnt = hbq_desc->seqlenbcnt; |
| 986 | hbqmb->profiles.profile5.maxlen = hbq_desc->maxlen; |
| 987 | hbqmb->profiles.profile5.cmdcodeoff = hbq_desc->cmdcodeoff; |
| 988 | hbqmb->profiles.profile5.seqlenoff = hbq_desc->seqlenoff; |
| 989 | memcpy(&hbqmb->profiles.profile5.cmdmatch, hbq_desc->cmdmatch, |
| 990 | sizeof(hbqmb->profiles.profile5.cmdmatch)); |
| 991 | } |
| 992 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 993 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 994 | * lpfc_config_hbq - Prepare a mailbox command for configuring an HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 995 | * @phba: pointer to lpfc hba data structure. |
| 996 | * @id: HBQ identifier. |
| 997 | * @hbq_desc: pointer to the HBA descriptor data structure. |
| 998 | * @hbq_entry_index: index of the HBQ entry data structures. |
| 999 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 1000 | * |
| 1001 | * The configure HBQ (Host Buffer Queue) mailbox command is used to configure |
| 1002 | * an HBQ. The configuration binds events that require buffers to a particular |
| 1003 | * ring and HBQ based on a selection profile. |
| 1004 | * |
| 1005 | * This routine prepares the mailbox command for configuring an HBQ. |
| 1006 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1007 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1008 | lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id, |
| 1009 | struct lpfc_hbq_init *hbq_desc, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1010 | uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb) |
| 1011 | { |
| 1012 | int i; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1013 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1014 | struct config_hbq_var *hbqmb = &mb->un.varCfgHbq; |
| 1015 | |
| 1016 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1017 | hbqmb->hbqId = id; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1018 | hbqmb->entry_count = hbq_desc->entry_count; /* # entries in HBQ */ |
| 1019 | hbqmb->recvNotify = hbq_desc->rn; /* Receive |
| 1020 | * Notification */ |
| 1021 | hbqmb->numMask = hbq_desc->mask_count; /* # R_CTL/TYPE masks |
| 1022 | * # in words 0-19 */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1023 | hbqmb->profile = hbq_desc->profile; /* Selection profile: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1024 | * 0 = all, |
| 1025 | * 7 = logentry */ |
| 1026 | hbqmb->ringMask = hbq_desc->ring_mask; /* Binds HBQ to a ring |
| 1027 | * e.g. Ring0=b0001, |
| 1028 | * ring2=b0100 */ |
| 1029 | hbqmb->headerLen = hbq_desc->headerLen; /* 0 if not profile 4 |
| 1030 | * or 5 */ |
| 1031 | hbqmb->logEntry = hbq_desc->logEntry; /* Set to 1 if this |
| 1032 | * HBQ will be used |
| 1033 | * for LogEntry |
| 1034 | * buffers */ |
| 1035 | hbqmb->hbqaddrLow = putPaddrLow(phba->hbqslimp.phys) + |
| 1036 | hbq_entry_index * sizeof(struct lpfc_hbq_entry); |
| 1037 | hbqmb->hbqaddrHigh = putPaddrHigh(phba->hbqslimp.phys); |
| 1038 | |
| 1039 | mb->mbxCommand = MBX_CONFIG_HBQ; |
| 1040 | mb->mbxOwner = OWN_HOST; |
| 1041 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1042 | /* Copy info for profiles 2,3,5. Other |
| 1043 | * profiles this area is reserved |
| 1044 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1045 | if (hbq_desc->profile == 2) |
| 1046 | lpfc_build_hbq_profile2(hbqmb, hbq_desc); |
| 1047 | else if (hbq_desc->profile == 3) |
| 1048 | lpfc_build_hbq_profile3(hbqmb, hbq_desc); |
| 1049 | else if (hbq_desc->profile == 5) |
| 1050 | lpfc_build_hbq_profile5(hbqmb, hbq_desc); |
| 1051 | |
| 1052 | /* Return if no rctl / type masks for this HBQ */ |
| 1053 | if (!hbq_desc->mask_count) |
| 1054 | return; |
| 1055 | |
| 1056 | /* Otherwise we setup specific rctl / type masks for this HBQ */ |
| 1057 | for (i = 0; i < hbq_desc->mask_count; i++) { |
| 1058 | hbqmb->hbqMasks[i].tmatch = hbq_desc->hbqMasks[i].tmatch; |
| 1059 | hbqmb->hbqMasks[i].tmask = hbq_desc->hbqMasks[i].tmask; |
| 1060 | hbqmb->hbqMasks[i].rctlmatch = hbq_desc->hbqMasks[i].rctlmatch; |
| 1061 | hbqmb->hbqMasks[i].rctlmask = hbq_desc->hbqMasks[i].rctlmask; |
| 1062 | } |
| 1063 | |
| 1064 | return; |
| 1065 | } |
| 1066 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1067 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1068 | * lpfc_config_ring - Prepare a mailbox command for configuring an IOCB ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1069 | * @phba: pointer to lpfc hba data structure. |
| 1070 | * @ring: |
| 1071 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 1072 | * |
| 1073 | * The configure ring mailbox command is used to configure an IOCB ring. This |
| 1074 | * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the |
| 1075 | * ring. This is used to map incoming sequences to a particular ring whose |
| 1076 | * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not |
| 1077 | * attempt to configure a ring whose number is greater than the number |
| 1078 | * specified in the Port Control Block (PCB). It is an error to issue the |
| 1079 | * configure ring command more than once with the same ring number. The HBA |
| 1080 | * returns an error if the driver attempts this. |
| 1081 | * |
| 1082 | * This routine prepares the mailbox command for configuring IOCB ring. |
| 1083 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1084 | void |
| 1085 | lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb) |
| 1086 | { |
| 1087 | int i; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1088 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1089 | struct lpfc_sli *psli; |
| 1090 | struct lpfc_sli_ring *pring; |
| 1091 | |
| 1092 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 1093 | |
| 1094 | mb->un.varCfgRing.ring = ring; |
| 1095 | mb->un.varCfgRing.maxOrigXchg = 0; |
| 1096 | mb->un.varCfgRing.maxRespXchg = 0; |
| 1097 | mb->un.varCfgRing.recvNotify = 1; |
| 1098 | |
| 1099 | psli = &phba->sli; |
| 1100 | pring = &psli->ring[ring]; |
| 1101 | mb->un.varCfgRing.numMask = pring->num_mask; |
| 1102 | mb->mbxCommand = MBX_CONFIG_RING; |
| 1103 | mb->mbxOwner = OWN_HOST; |
| 1104 | |
| 1105 | /* Is this ring configured for a specific profile */ |
| 1106 | if (pring->prt[0].profile) { |
| 1107 | mb->un.varCfgRing.profile = pring->prt[0].profile; |
| 1108 | return; |
| 1109 | } |
| 1110 | |
| 1111 | /* Otherwise we setup specific rctl / type masks for this ring */ |
| 1112 | for (i = 0; i < pring->num_mask; i++) { |
| 1113 | mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl; |
| 1114 | if (mb->un.varCfgRing.rrRegs[i].rval != FC_ELS_REQ) |
| 1115 | mb->un.varCfgRing.rrRegs[i].rmask = 0xff; |
| 1116 | else |
| 1117 | mb->un.varCfgRing.rrRegs[i].rmask = 0xfe; |
| 1118 | mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type; |
| 1119 | mb->un.varCfgRing.rrRegs[i].tmask = 0xff; |
| 1120 | } |
| 1121 | |
| 1122 | return; |
| 1123 | } |
| 1124 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1125 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1126 | * lpfc_config_port - Prepare a mailbox command for configuring port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1127 | * @phba: pointer to lpfc hba data structure. |
| 1128 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 1129 | * |
| 1130 | * The configure port mailbox command is used to identify the Port Control |
| 1131 | * Block (PCB) in the driver memory. After this command is issued, the |
| 1132 | * driver must not access the mailbox in the HBA without first resetting |
| 1133 | * the HBA. The HBA may copy the PCB information to internal storage for |
| 1134 | * subsequent use; the driver can not change the PCB information unless it |
| 1135 | * resets the HBA. |
| 1136 | * |
| 1137 | * This routine prepares the mailbox command for configuring port. |
| 1138 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1139 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1140 | lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1141 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1142 | MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1143 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1144 | dma_addr_t pdma_addr; |
| 1145 | uint32_t bar_low, bar_high; |
| 1146 | size_t offset; |
James.Smart@Emulex.Com | 4cc2da1 | 2005-06-25 10:34:00 -0400 | [diff] [blame] | 1147 | struct lpfc_hgp hgp; |
James.Smart@Emulex.Com | f91b392 | 2005-10-28 20:29:28 -0400 | [diff] [blame] | 1148 | int i; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1149 | uint32_t pgp_offset; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1150 | |
| 1151 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
| 1152 | mb->mbxCommand = MBX_CONFIG_PORT; |
| 1153 | mb->mbxOwner = OWN_HOST; |
| 1154 | |
| 1155 | mb->un.varCfgPort.pcbLen = sizeof(PCB_t); |
| 1156 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1157 | offset = (uint8_t *)phba->pcb - (uint8_t *)phba->slim2p.virt; |
| 1158 | pdma_addr = phba->slim2p.phys + offset; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1159 | mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr); |
| 1160 | mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr); |
| 1161 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 1162 | /* Always Host Group Pointer is in SLIM */ |
| 1163 | mb->un.varCfgPort.hps = 1; |
| 1164 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1165 | /* If HBA supports SLI=3 ask for it */ |
| 1166 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1167 | if (phba->sli_rev == LPFC_SLI_REV3 && phba->vpd.sli3Feat.cerbm) { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1168 | if (phba->cfg_enable_bg) |
| 1169 | mb->un.varCfgPort.cbg = 1; /* configure BlockGuard */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1170 | mb->un.varCfgPort.cdss = 1; /* Configure Security */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1171 | mb->un.varCfgPort.cerbm = 1; /* Request HBQs */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1172 | mb->un.varCfgPort.ccrp = 1; /* Command Ring Polling */ |
| 1173 | mb->un.varCfgPort.cinb = 1; /* Interrupt Notification Block */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1174 | mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count(); |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 1175 | if (phba->max_vpi && phba->cfg_enable_npiv && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1176 | phba->vpd.sli3Feat.cmv) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1177 | mb->un.varCfgPort.max_vpi = LPFC_MAX_VPI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1178 | mb->un.varCfgPort.cmv = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1179 | } else |
| 1180 | mb->un.varCfgPort.max_vpi = phba->max_vpi = 0; |
| 1181 | } else |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1182 | phba->sli_rev = LPFC_SLI_REV2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1183 | mb->un.varCfgPort.sli_mode = phba->sli_rev; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1184 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1185 | /* Now setup pcb */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1186 | phba->pcb->type = TYPE_NATIVE_SLI2; |
| 1187 | phba->pcb->feature = FEATURE_INITIAL_SLI2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1188 | |
| 1189 | /* Setup Mailbox pointers */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1190 | phba->pcb->mailBoxSize = sizeof(MAILBOX_t); |
| 1191 | offset = (uint8_t *)phba->mbox - (uint8_t *)phba->slim2p.virt; |
| 1192 | pdma_addr = phba->slim2p.phys + offset; |
| 1193 | phba->pcb->mbAddrHigh = putPaddrHigh(pdma_addr); |
| 1194 | phba->pcb->mbAddrLow = putPaddrLow(pdma_addr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1195 | |
| 1196 | /* |
| 1197 | * Setup Host Group ring pointer. |
| 1198 | * |
| 1199 | * For efficiency reasons, the ring get/put pointers can be |
| 1200 | * placed in adapter memory (SLIM) rather than in host memory. |
| 1201 | * This allows firmware to avoid PCI reads/writes when updating |
| 1202 | * and checking pointers. |
| 1203 | * |
| 1204 | * The firmware recognizes the use of SLIM memory by comparing |
| 1205 | * the address of the get/put pointers structure with that of |
| 1206 | * the SLIM BAR (BAR0). |
| 1207 | * |
| 1208 | * Caution: be sure to use the PCI config space value of BAR0/BAR1 |
| 1209 | * (the hardware's view of the base address), not the OS's |
| 1210 | * value of pci_resource_start() as the OS value may be a cookie |
| 1211 | * for ioremap/iomap. |
| 1212 | */ |
| 1213 | |
| 1214 | |
| 1215 | pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low); |
| 1216 | pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high); |
| 1217 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1218 | /* |
| 1219 | * Set up HGP - Port Memory |
| 1220 | * |
| 1221 | * The port expects the host get/put pointers to reside in memory |
| 1222 | * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes) |
| 1223 | * area of SLIM. In SLI-2 mode, there's an additional 16 reserved |
| 1224 | * words (0x40 bytes). This area is not reserved if HBQs are |
| 1225 | * configured in SLI-3. |
| 1226 | * |
| 1227 | * CR0Put - SLI2(no HBQs) = 0xc0, With HBQs = 0x80 |
| 1228 | * RR0Get 0xc4 0x84 |
| 1229 | * CR1Put 0xc8 0x88 |
| 1230 | * RR1Get 0xcc 0x8c |
| 1231 | * CR2Put 0xd0 0x90 |
| 1232 | * RR2Get 0xd4 0x94 |
| 1233 | * CR3Put 0xd8 0x98 |
| 1234 | * RR3Get 0xdc 0x9c |
| 1235 | * |
| 1236 | * Reserved 0xa0-0xbf |
| 1237 | * If HBQs configured: |
| 1238 | * HBQ 0 Put ptr 0xc0 |
| 1239 | * HBQ 1 Put ptr 0xc4 |
| 1240 | * HBQ 2 Put ptr 0xc8 |
| 1241 | * ...... |
| 1242 | * HBQ(M-1)Put Pointer 0xc0+(M-1)*4 |
| 1243 | * |
| 1244 | */ |
| 1245 | |
| 1246 | if (phba->sli_rev == 3) { |
| 1247 | phba->host_gp = &mb_slim->us.s3.host[0]; |
| 1248 | phba->hbq_put = &mb_slim->us.s3.hbq_put[0]; |
| 1249 | } else { |
| 1250 | phba->host_gp = &mb_slim->us.s2.host[0]; |
| 1251 | phba->hbq_put = NULL; |
| 1252 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1253 | |
| 1254 | /* mask off BAR0's flag bits 0 - 3 */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1255 | phba->pcb->hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) + |
| 1256 | (void __iomem *)phba->host_gp - |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1257 | (void __iomem *)phba->MBslimaddr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1258 | if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1259 | phba->pcb->hgpAddrHigh = bar_high; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1260 | else |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1261 | phba->pcb->hgpAddrHigh = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1262 | /* write HGP data to SLIM at the required longword offset */ |
James.Smart@Emulex.Com | 4cc2da1 | 2005-06-25 10:34:00 -0400 | [diff] [blame] | 1263 | memset(&hgp, 0, sizeof(struct lpfc_hgp)); |
James.Smart@Emulex.Com | f91b392 | 2005-10-28 20:29:28 -0400 | [diff] [blame] | 1264 | |
| 1265 | for (i=0; i < phba->sli.num_rings; i++) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1266 | lpfc_memcpy_to_slim(phba->host_gp + i, &hgp, |
| 1267 | sizeof(*phba->host_gp)); |
James.Smart@Emulex.Com | f91b392 | 2005-10-28 20:29:28 -0400 | [diff] [blame] | 1268 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1269 | |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 1270 | /* Setup Port Group offset */ |
| 1271 | if (phba->sli_rev == 3) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1272 | pgp_offset = offsetof(struct lpfc_sli2_slim, |
| 1273 | mbx.us.s3_pgp.port); |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 1274 | else |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1275 | pgp_offset = offsetof(struct lpfc_sli2_slim, mbx.us.s2.port); |
| 1276 | pdma_addr = phba->slim2p.phys + pgp_offset; |
| 1277 | phba->pcb->pgpAddrHigh = putPaddrHigh(pdma_addr); |
| 1278 | phba->pcb->pgpAddrLow = putPaddrLow(pdma_addr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1279 | |
| 1280 | /* Use callback routine to setp rings in the pcb */ |
| 1281 | lpfc_config_pcb_setup(phba); |
| 1282 | |
| 1283 | /* special handling for LC HBAs */ |
| 1284 | if (lpfc_is_LC_HBA(phba->pcidev->device)) { |
| 1285 | uint32_t hbainit[5]; |
| 1286 | |
| 1287 | lpfc_hba_init(phba, hbainit); |
| 1288 | |
| 1289 | memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20); |
| 1290 | } |
| 1291 | |
| 1292 | /* Swap PCB if needed */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1293 | lpfc_sli_pcimem_bcopy(phba->pcb, phba->pcb, sizeof(PCB_t)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1294 | } |
| 1295 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1296 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1297 | * lpfc_kill_board - Prepare a mailbox command for killing board |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1298 | * @phba: pointer to lpfc hba data structure. |
| 1299 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 1300 | * |
| 1301 | * The kill board mailbox command is used to tell firmware to perform a |
| 1302 | * graceful shutdown of a channel on a specified board to prepare for reset. |
| 1303 | * When the kill board mailbox command is received, the ER3 bit is set to 1 |
| 1304 | * in the Host Status register and the ER Attention bit is set to 1 in the |
| 1305 | * Host Attention register of the HBA function that received the kill board |
| 1306 | * command. |
| 1307 | * |
| 1308 | * This routine prepares the mailbox command for killing the board in |
| 1309 | * preparation for a graceful shutdown. |
| 1310 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1311 | void |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1312 | lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 1313 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1314 | MAILBOX_t *mb = &pmb->u.mb; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1315 | |
| 1316 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
| 1317 | mb->mbxCommand = MBX_KILL_BOARD; |
| 1318 | mb->mbxOwner = OWN_HOST; |
| 1319 | return; |
| 1320 | } |
| 1321 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1322 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1323 | * lpfc_mbox_put - Put a mailbox cmd into the tail of driver's mailbox queue |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1324 | * @phba: pointer to lpfc hba data structure. |
| 1325 | * @mbq: pointer to the driver internal queue element for mailbox command. |
| 1326 | * |
| 1327 | * Driver maintains a internal mailbox command queue implemented as a linked |
| 1328 | * list. When a mailbox command is issued, it shall be put into the mailbox |
| 1329 | * command queue such that they shall be processed orderly as HBA can process |
| 1330 | * one mailbox command at a time. |
| 1331 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1332 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1333 | lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq) |
| 1334 | { |
| 1335 | struct lpfc_sli *psli; |
| 1336 | |
| 1337 | psli = &phba->sli; |
| 1338 | |
| 1339 | list_add_tail(&mbq->list, &psli->mboxq); |
| 1340 | |
| 1341 | psli->mboxq_cnt++; |
| 1342 | |
| 1343 | return; |
| 1344 | } |
| 1345 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1346 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1347 | * lpfc_mbox_get - Remove a mailbox cmd from the head of driver's mailbox queue |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1348 | * @phba: pointer to lpfc hba data structure. |
| 1349 | * |
| 1350 | * Driver maintains a internal mailbox command queue implemented as a linked |
| 1351 | * list. When a mailbox command is issued, it shall be put into the mailbox |
| 1352 | * command queue such that they shall be processed orderly as HBA can process |
| 1353 | * one mailbox command at a time. After HBA finished processing a mailbox |
| 1354 | * command, the driver will remove a pending mailbox command from the head of |
| 1355 | * the mailbox command queue and send to the HBA for processing. |
| 1356 | * |
| 1357 | * Return codes |
| 1358 | * pointer to the driver internal queue element for mailbox command. |
| 1359 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1360 | LPFC_MBOXQ_t * |
| 1361 | lpfc_mbox_get(struct lpfc_hba * phba) |
| 1362 | { |
| 1363 | LPFC_MBOXQ_t *mbq = NULL; |
| 1364 | struct lpfc_sli *psli = &phba->sli; |
| 1365 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1366 | list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t, list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1367 | if (mbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1368 | psli->mboxq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1369 | |
| 1370 | return mbq; |
| 1371 | } |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 1372 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1373 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1374 | * __lpfc_mbox_cmpl_put - Put mailbox cmd into mailbox cmd complete list |
| 1375 | * @phba: pointer to lpfc hba data structure. |
| 1376 | * @mbq: pointer to the driver internal queue element for mailbox command. |
| 1377 | * |
| 1378 | * This routine put the completed mailbox command into the mailbox command |
| 1379 | * complete list. This is the unlocked version of the routine. The mailbox |
| 1380 | * complete list is used by the driver worker thread to process mailbox |
| 1381 | * complete callback functions outside the driver interrupt handler. |
| 1382 | **/ |
| 1383 | void |
| 1384 | __lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq) |
| 1385 | { |
| 1386 | list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl); |
| 1387 | } |
| 1388 | |
| 1389 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1390 | * lpfc_mbox_cmpl_put - Put mailbox command into mailbox command complete list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1391 | * @phba: pointer to lpfc hba data structure. |
| 1392 | * @mbq: pointer to the driver internal queue element for mailbox command. |
| 1393 | * |
| 1394 | * This routine put the completed mailbox command into the mailbox command |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1395 | * complete list. This is the locked version of the routine. The mailbox |
| 1396 | * complete list is used by the driver worker thread to process mailbox |
| 1397 | * complete callback functions outside the driver interrupt handler. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1398 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1399 | void |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1400 | lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1401 | { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 1402 | unsigned long iflag; |
| 1403 | |
Joe Perches | b1c1181 | 2008-02-03 17:28:22 +0200 | [diff] [blame] | 1404 | /* This function expects to be called from interrupt context */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 1405 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1406 | __lpfc_mbox_cmpl_put(phba, mbq); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 1407 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1408 | return; |
| 1409 | } |
| 1410 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1411 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1412 | * lpfc_mbox_cmd_check - Check the validality of a mailbox command |
| 1413 | * @phba: pointer to lpfc hba data structure. |
| 1414 | * @mboxq: pointer to the driver internal queue element for mailbox command. |
| 1415 | * |
| 1416 | * This routine is to check whether a mailbox command is valid to be issued. |
| 1417 | * This check will be performed by both the mailbox issue API when a client |
| 1418 | * is to issue a mailbox command to the mailbox transport. |
| 1419 | * |
| 1420 | * Return 0 - pass the check, -ENODEV - fail the check |
| 1421 | **/ |
| 1422 | int |
| 1423 | lpfc_mbox_cmd_check(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 1424 | { |
| 1425 | /* Mailbox command that have a completion handler must also have a |
| 1426 | * vport specified. |
| 1427 | */ |
| 1428 | if (mboxq->mbox_cmpl && mboxq->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
| 1429 | mboxq->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
| 1430 | if (!mboxq->vport) { |
| 1431 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 1432 | "1814 Mbox x%x failed, no vport\n", |
| 1433 | mboxq->u.mb.mbxCommand); |
| 1434 | dump_stack(); |
| 1435 | return -ENODEV; |
| 1436 | } |
| 1437 | } |
| 1438 | return 0; |
| 1439 | } |
| 1440 | |
| 1441 | /** |
| 1442 | * lpfc_mbox_dev_check - Check the device state for issuing a mailbox command |
| 1443 | * @phba: pointer to lpfc hba data structure. |
| 1444 | * |
| 1445 | * This routine is to check whether the HBA device is ready for posting a |
| 1446 | * mailbox command. It is used by the mailbox transport API at the time the |
| 1447 | * to post a mailbox command to the device. |
| 1448 | * |
| 1449 | * Return 0 - pass the check, -ENODEV - fail the check |
| 1450 | **/ |
| 1451 | int |
| 1452 | lpfc_mbox_dev_check(struct lpfc_hba *phba) |
| 1453 | { |
| 1454 | /* If the PCI channel is in offline state, do not issue mbox */ |
| 1455 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 1456 | return -ENODEV; |
| 1457 | |
| 1458 | /* If the HBA is in error state, do not issue mbox */ |
| 1459 | if (phba->link_state == LPFC_HBA_ERROR) |
| 1460 | return -ENODEV; |
| 1461 | |
| 1462 | return 0; |
| 1463 | } |
| 1464 | |
| 1465 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1466 | * lpfc_mbox_tmo_val - Retrieve mailbox command timeout value |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1467 | * @phba: pointer to lpfc hba data structure. |
| 1468 | * @cmd: mailbox command code. |
| 1469 | * |
| 1470 | * This routine retrieves the proper timeout value according to the mailbox |
| 1471 | * command code. |
| 1472 | * |
| 1473 | * Return codes |
| 1474 | * Timeout value to be used for the given mailbox command |
| 1475 | **/ |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 1476 | int |
| 1477 | lpfc_mbox_tmo_val(struct lpfc_hba *phba, int cmd) |
| 1478 | { |
| 1479 | switch (cmd) { |
| 1480 | case MBX_WRITE_NV: /* 0x03 */ |
| 1481 | case MBX_UPDATE_CFG: /* 0x1B */ |
| 1482 | case MBX_DOWN_LOAD: /* 0x1C */ |
| 1483 | case MBX_DEL_LD_ENTRY: /* 0x1D */ |
| 1484 | case MBX_LOAD_AREA: /* 0x81 */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1485 | case MBX_WRITE_WWN: /* 0x98 */ |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 1486 | case MBX_LOAD_EXP_ROM: /* 0x9C */ |
| 1487 | return LPFC_MBOX_TMO_FLASH_CMD; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1488 | case MBX_SLI4_CONFIG: /* 0x9b */ |
| 1489 | return LPFC_MBOX_SLI4_CONFIG_TMO; |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 1490 | } |
| 1491 | return LPFC_MBOX_TMO; |
| 1492 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1493 | |
| 1494 | /** |
| 1495 | * lpfc_sli4_mbx_sge_set - Set a sge entry in non-embedded mailbox command |
| 1496 | * @mbox: pointer to lpfc mbox command. |
| 1497 | * @sgentry: sge entry index. |
| 1498 | * @phyaddr: physical address for the sge |
| 1499 | * @length: Length of the sge. |
| 1500 | * |
| 1501 | * This routine sets up an entry in the non-embedded mailbox command at the sge |
| 1502 | * index location. |
| 1503 | **/ |
| 1504 | void |
| 1505 | lpfc_sli4_mbx_sge_set(struct lpfcMboxq *mbox, uint32_t sgentry, |
| 1506 | dma_addr_t phyaddr, uint32_t length) |
| 1507 | { |
| 1508 | struct lpfc_mbx_nembed_cmd *nembed_sge; |
| 1509 | |
| 1510 | nembed_sge = (struct lpfc_mbx_nembed_cmd *) |
| 1511 | &mbox->u.mqe.un.nembed_cmd; |
| 1512 | nembed_sge->sge[sgentry].pa_lo = putPaddrLow(phyaddr); |
| 1513 | nembed_sge->sge[sgentry].pa_hi = putPaddrHigh(phyaddr); |
| 1514 | nembed_sge->sge[sgentry].length = length; |
| 1515 | } |
| 1516 | |
| 1517 | /** |
| 1518 | * lpfc_sli4_mbx_sge_get - Get a sge entry from non-embedded mailbox command |
| 1519 | * @mbox: pointer to lpfc mbox command. |
| 1520 | * @sgentry: sge entry index. |
| 1521 | * |
| 1522 | * This routine gets an entry from the non-embedded mailbox command at the sge |
| 1523 | * index location. |
| 1524 | **/ |
| 1525 | void |
| 1526 | lpfc_sli4_mbx_sge_get(struct lpfcMboxq *mbox, uint32_t sgentry, |
| 1527 | struct lpfc_mbx_sge *sge) |
| 1528 | { |
| 1529 | struct lpfc_mbx_nembed_cmd *nembed_sge; |
| 1530 | |
| 1531 | nembed_sge = (struct lpfc_mbx_nembed_cmd *) |
| 1532 | &mbox->u.mqe.un.nembed_cmd; |
| 1533 | sge->pa_lo = nembed_sge->sge[sgentry].pa_lo; |
| 1534 | sge->pa_hi = nembed_sge->sge[sgentry].pa_hi; |
| 1535 | sge->length = nembed_sge->sge[sgentry].length; |
| 1536 | } |
| 1537 | |
| 1538 | /** |
| 1539 | * lpfc_sli4_mbox_cmd_free - Free a sli4 mailbox command |
| 1540 | * @phba: pointer to lpfc hba data structure. |
| 1541 | * @mbox: pointer to lpfc mbox command. |
| 1542 | * |
| 1543 | * This routine frees SLI4 specific mailbox command for sending IOCTL command. |
| 1544 | **/ |
| 1545 | void |
| 1546 | lpfc_sli4_mbox_cmd_free(struct lpfc_hba *phba, struct lpfcMboxq *mbox) |
| 1547 | { |
| 1548 | struct lpfc_mbx_sli4_config *sli4_cfg; |
| 1549 | struct lpfc_mbx_sge sge; |
| 1550 | dma_addr_t phyaddr; |
| 1551 | uint32_t sgecount, sgentry; |
| 1552 | |
| 1553 | sli4_cfg = &mbox->u.mqe.un.sli4_config; |
| 1554 | |
| 1555 | /* For embedded mbox command, just free the mbox command */ |
| 1556 | if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) { |
| 1557 | mempool_free(mbox, phba->mbox_mem_pool); |
| 1558 | return; |
| 1559 | } |
| 1560 | |
| 1561 | /* For non-embedded mbox command, we need to free the pages first */ |
| 1562 | sgecount = bf_get(lpfc_mbox_hdr_sge_cnt, &sli4_cfg->header.cfg_mhdr); |
| 1563 | /* There is nothing we can do if there is no sge address array */ |
| 1564 | if (unlikely(!mbox->sge_array)) { |
| 1565 | mempool_free(mbox, phba->mbox_mem_pool); |
| 1566 | return; |
| 1567 | } |
| 1568 | /* Each non-embedded DMA memory was allocated in the length of a page */ |
| 1569 | for (sgentry = 0; sgentry < sgecount; sgentry++) { |
| 1570 | lpfc_sli4_mbx_sge_get(mbox, sgentry, &sge); |
| 1571 | phyaddr = getPaddr(sge.pa_hi, sge.pa_lo); |
| 1572 | dma_free_coherent(&phba->pcidev->dev, PAGE_SIZE, |
| 1573 | mbox->sge_array->addr[sgentry], phyaddr); |
| 1574 | } |
| 1575 | /* Free the sge address array memory */ |
| 1576 | kfree(mbox->sge_array); |
| 1577 | /* Finally, free the mailbox command itself */ |
| 1578 | mempool_free(mbox, phba->mbox_mem_pool); |
| 1579 | } |
| 1580 | |
| 1581 | /** |
| 1582 | * lpfc_sli4_config - Initialize the SLI4 Config Mailbox command |
| 1583 | * @phba: pointer to lpfc hba data structure. |
| 1584 | * @mbox: pointer to lpfc mbox command. |
| 1585 | * @subsystem: The sli4 config sub mailbox subsystem. |
| 1586 | * @opcode: The sli4 config sub mailbox command opcode. |
| 1587 | * @length: Length of the sli4 config mailbox command. |
| 1588 | * |
| 1589 | * This routine sets up the header fields of SLI4 specific mailbox command |
| 1590 | * for sending IOCTL command. |
| 1591 | * |
| 1592 | * Return: the actual length of the mbox command allocated (mostly useful |
| 1593 | * for none embedded mailbox command). |
| 1594 | **/ |
| 1595 | int |
| 1596 | lpfc_sli4_config(struct lpfc_hba *phba, struct lpfcMboxq *mbox, |
| 1597 | uint8_t subsystem, uint8_t opcode, uint32_t length, bool emb) |
| 1598 | { |
| 1599 | struct lpfc_mbx_sli4_config *sli4_config; |
| 1600 | union lpfc_sli4_cfg_shdr *cfg_shdr = NULL; |
| 1601 | uint32_t alloc_len; |
| 1602 | uint32_t resid_len; |
| 1603 | uint32_t pagen, pcount; |
| 1604 | void *viraddr; |
| 1605 | dma_addr_t phyaddr; |
| 1606 | |
| 1607 | /* Set up SLI4 mailbox command header fields */ |
| 1608 | memset(mbox, 0, sizeof(*mbox)); |
| 1609 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_SLI4_CONFIG); |
| 1610 | |
| 1611 | /* Set up SLI4 ioctl command header fields */ |
| 1612 | sli4_config = &mbox->u.mqe.un.sli4_config; |
| 1613 | |
| 1614 | /* Setup for the embedded mbox command */ |
| 1615 | if (emb) { |
| 1616 | /* Set up main header fields */ |
| 1617 | bf_set(lpfc_mbox_hdr_emb, &sli4_config->header.cfg_mhdr, 1); |
| 1618 | sli4_config->header.cfg_mhdr.payload_length = |
| 1619 | LPFC_MBX_CMD_HDR_LENGTH + length; |
| 1620 | /* Set up sub-header fields following main header */ |
| 1621 | bf_set(lpfc_mbox_hdr_opcode, |
| 1622 | &sli4_config->header.cfg_shdr.request, opcode); |
| 1623 | bf_set(lpfc_mbox_hdr_subsystem, |
| 1624 | &sli4_config->header.cfg_shdr.request, subsystem); |
| 1625 | sli4_config->header.cfg_shdr.request.request_length = length; |
| 1626 | return length; |
| 1627 | } |
| 1628 | |
| 1629 | /* Setup for the none-embedded mbox command */ |
| 1630 | pcount = (PAGE_ALIGN(length))/PAGE_SIZE; |
| 1631 | pcount = (pcount > LPFC_SLI4_MBX_SGE_MAX_PAGES) ? |
| 1632 | LPFC_SLI4_MBX_SGE_MAX_PAGES : pcount; |
| 1633 | /* Allocate record for keeping SGE virtual addresses */ |
| 1634 | mbox->sge_array = kmalloc(sizeof(struct lpfc_mbx_nembed_sge_virt), |
| 1635 | GFP_KERNEL); |
| 1636 | if (!mbox->sge_array) |
| 1637 | return 0; |
| 1638 | |
| 1639 | for (pagen = 0, alloc_len = 0; pagen < pcount; pagen++) { |
| 1640 | /* The DMA memory is always allocated in the length of a |
| 1641 | * page even though the last SGE might not fill up to a |
| 1642 | * page, this is used as a priori size of PAGE_SIZE for |
| 1643 | * the later DMA memory free. |
| 1644 | */ |
| 1645 | viraddr = dma_alloc_coherent(&phba->pcidev->dev, PAGE_SIZE, |
| 1646 | &phyaddr, GFP_KERNEL); |
| 1647 | /* In case of malloc fails, proceed with whatever we have */ |
| 1648 | if (!viraddr) |
| 1649 | break; |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 1650 | memset(viraddr, 0, PAGE_SIZE); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1651 | mbox->sge_array->addr[pagen] = viraddr; |
| 1652 | /* Keep the first page for later sub-header construction */ |
| 1653 | if (pagen == 0) |
| 1654 | cfg_shdr = (union lpfc_sli4_cfg_shdr *)viraddr; |
| 1655 | resid_len = length - alloc_len; |
| 1656 | if (resid_len > PAGE_SIZE) { |
| 1657 | lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr, |
| 1658 | PAGE_SIZE); |
| 1659 | alloc_len += PAGE_SIZE; |
| 1660 | } else { |
| 1661 | lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr, |
| 1662 | resid_len); |
| 1663 | alloc_len = length; |
| 1664 | } |
| 1665 | } |
| 1666 | |
| 1667 | /* Set up main header fields in mailbox command */ |
| 1668 | sli4_config->header.cfg_mhdr.payload_length = alloc_len; |
| 1669 | bf_set(lpfc_mbox_hdr_sge_cnt, &sli4_config->header.cfg_mhdr, pagen); |
| 1670 | |
| 1671 | /* Set up sub-header fields into the first page */ |
| 1672 | if (pagen > 0) { |
| 1673 | bf_set(lpfc_mbox_hdr_opcode, &cfg_shdr->request, opcode); |
| 1674 | bf_set(lpfc_mbox_hdr_subsystem, &cfg_shdr->request, subsystem); |
| 1675 | cfg_shdr->request.request_length = |
| 1676 | alloc_len - sizeof(union lpfc_sli4_cfg_shdr); |
| 1677 | } |
| 1678 | /* The sub-header is in DMA memory, which needs endian converstion */ |
| 1679 | lpfc_sli_pcimem_bcopy(cfg_shdr, cfg_shdr, |
| 1680 | sizeof(union lpfc_sli4_cfg_shdr)); |
| 1681 | |
| 1682 | return alloc_len; |
| 1683 | } |
| 1684 | |
| 1685 | /** |
| 1686 | * lpfc_sli4_mbox_opcode_get - Get the opcode from a sli4 mailbox command |
| 1687 | * @phba: pointer to lpfc hba data structure. |
| 1688 | * @mbox: pointer to lpfc mbox command. |
| 1689 | * |
| 1690 | * This routine gets the opcode from a SLI4 specific mailbox command for |
| 1691 | * sending IOCTL command. If the mailbox command is not MBX_SLI4_CONFIG |
| 1692 | * (0x9B) or if the IOCTL sub-header is not present, opcode 0x0 shall be |
| 1693 | * returned. |
| 1694 | **/ |
| 1695 | uint8_t |
| 1696 | lpfc_sli4_mbox_opcode_get(struct lpfc_hba *phba, struct lpfcMboxq *mbox) |
| 1697 | { |
| 1698 | struct lpfc_mbx_sli4_config *sli4_cfg; |
| 1699 | union lpfc_sli4_cfg_shdr *cfg_shdr; |
| 1700 | |
| 1701 | if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG) |
| 1702 | return 0; |
| 1703 | sli4_cfg = &mbox->u.mqe.un.sli4_config; |
| 1704 | |
| 1705 | /* For embedded mbox command, get opcode from embedded sub-header*/ |
| 1706 | if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) { |
| 1707 | cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr; |
| 1708 | return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request); |
| 1709 | } |
| 1710 | |
| 1711 | /* For non-embedded mbox command, get opcode from first dma page */ |
| 1712 | if (unlikely(!mbox->sge_array)) |
| 1713 | return 0; |
| 1714 | cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0]; |
| 1715 | return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request); |
| 1716 | } |
| 1717 | |
| 1718 | /** |
| 1719 | * lpfc_request_features: Configure SLI4 REQUEST_FEATURES mailbox |
| 1720 | * @mboxq: pointer to lpfc mbox command. |
| 1721 | * |
| 1722 | * This routine sets up the mailbox for an SLI4 REQUEST_FEATURES |
| 1723 | * mailbox command. |
| 1724 | **/ |
| 1725 | void |
| 1726 | lpfc_request_features(struct lpfc_hba *phba, struct lpfcMboxq *mboxq) |
| 1727 | { |
| 1728 | /* Set up SLI4 mailbox command header fields */ |
| 1729 | memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); |
| 1730 | bf_set(lpfc_mqe_command, &mboxq->u.mqe, MBX_SLI4_REQ_FTRS); |
| 1731 | |
| 1732 | /* Set up host requested features. */ |
| 1733 | bf_set(lpfc_mbx_rq_ftr_rq_fcpi, &mboxq->u.mqe.un.req_ftrs, 1); |
| 1734 | |
James Smart | 0c28758 | 2009-06-10 17:22:56 -0400 | [diff] [blame] | 1735 | if (phba->cfg_enable_fip) |
| 1736 | bf_set(lpfc_mbx_rq_ftr_rq_ifip, &mboxq->u.mqe.un.req_ftrs, 0); |
| 1737 | else |
| 1738 | bf_set(lpfc_mbx_rq_ftr_rq_ifip, &mboxq->u.mqe.un.req_ftrs, 1); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1739 | |
| 1740 | /* Enable DIF (block guard) only if configured to do so. */ |
| 1741 | if (phba->cfg_enable_bg) |
| 1742 | bf_set(lpfc_mbx_rq_ftr_rq_dif, &mboxq->u.mqe.un.req_ftrs, 1); |
| 1743 | |
| 1744 | /* Enable NPIV only if configured to do so. */ |
| 1745 | if (phba->max_vpi && phba->cfg_enable_npiv) |
| 1746 | bf_set(lpfc_mbx_rq_ftr_rq_npiv, &mboxq->u.mqe.un.req_ftrs, 1); |
| 1747 | |
| 1748 | return; |
| 1749 | } |
| 1750 | |
| 1751 | /** |
| 1752 | * lpfc_init_vfi - Initialize the INIT_VFI mailbox command |
| 1753 | * @mbox: pointer to lpfc mbox command to initialize. |
| 1754 | * @vport: Vport associated with the VF. |
| 1755 | * |
| 1756 | * This routine initializes @mbox to all zeros and then fills in the mailbox |
| 1757 | * fields from @vport. INIT_VFI configures virtual fabrics identified by VFI |
| 1758 | * in the context of an FCF. The driver issues this command to setup a VFI |
| 1759 | * before issuing a FLOGI to login to the VSAN. The driver should also issue a |
| 1760 | * REG_VFI after a successful VSAN login. |
| 1761 | **/ |
| 1762 | void |
| 1763 | lpfc_init_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport) |
| 1764 | { |
| 1765 | struct lpfc_mbx_init_vfi *init_vfi; |
| 1766 | |
| 1767 | memset(mbox, 0, sizeof(*mbox)); |
| 1768 | init_vfi = &mbox->u.mqe.un.init_vfi; |
| 1769 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VFI); |
| 1770 | bf_set(lpfc_init_vfi_vr, init_vfi, 1); |
| 1771 | bf_set(lpfc_init_vfi_vt, init_vfi, 1); |
| 1772 | bf_set(lpfc_init_vfi_vfi, init_vfi, vport->vfi + vport->phba->vfi_base); |
| 1773 | bf_set(lpfc_init_vfi_fcfi, init_vfi, vport->phba->fcf.fcfi); |
| 1774 | } |
| 1775 | |
| 1776 | /** |
| 1777 | * lpfc_reg_vfi - Initialize the REG_VFI mailbox command |
| 1778 | * @mbox: pointer to lpfc mbox command to initialize. |
| 1779 | * @vport: vport associated with the VF. |
| 1780 | * @phys: BDE DMA bus address used to send the service parameters to the HBA. |
| 1781 | * |
| 1782 | * This routine initializes @mbox to all zeros and then fills in the mailbox |
| 1783 | * fields from @vport, and uses @buf as a DMAable buffer to send the vport's |
| 1784 | * fc service parameters to the HBA for this VFI. REG_VFI configures virtual |
| 1785 | * fabrics identified by VFI in the context of an FCF. |
| 1786 | **/ |
| 1787 | void |
| 1788 | lpfc_reg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport, dma_addr_t phys) |
| 1789 | { |
| 1790 | struct lpfc_mbx_reg_vfi *reg_vfi; |
| 1791 | |
| 1792 | memset(mbox, 0, sizeof(*mbox)); |
| 1793 | reg_vfi = &mbox->u.mqe.un.reg_vfi; |
| 1794 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_VFI); |
| 1795 | bf_set(lpfc_reg_vfi_vp, reg_vfi, 1); |
| 1796 | bf_set(lpfc_reg_vfi_vfi, reg_vfi, vport->vfi + vport->phba->vfi_base); |
| 1797 | bf_set(lpfc_reg_vfi_fcfi, reg_vfi, vport->phba->fcf.fcfi); |
| 1798 | bf_set(lpfc_reg_vfi_vpi, reg_vfi, vport->vpi + vport->phba->vpi_base); |
| 1799 | reg_vfi->bde.addrHigh = putPaddrHigh(phys); |
| 1800 | reg_vfi->bde.addrLow = putPaddrLow(phys); |
| 1801 | reg_vfi->bde.tus.f.bdeSize = sizeof(vport->fc_sparam); |
| 1802 | reg_vfi->bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 1803 | bf_set(lpfc_reg_vfi_nport_id, reg_vfi, vport->fc_myDID); |
| 1804 | } |
| 1805 | |
| 1806 | /** |
| 1807 | * lpfc_init_vpi - Initialize the INIT_VPI mailbox command |
| 1808 | * @mbox: pointer to lpfc mbox command to initialize. |
| 1809 | * @vpi: VPI to be initialized. |
| 1810 | * |
| 1811 | * The INIT_VPI mailbox command supports virtual N_Ports. The driver uses the |
| 1812 | * command to activate a virtual N_Port. The HBA assigns a MAC address to use |
| 1813 | * with the virtual N Port. The SLI Host issues this command before issuing a |
| 1814 | * FDISC to connect to the Fabric. The SLI Host should issue a REG_VPI after a |
| 1815 | * successful virtual NPort login. |
| 1816 | **/ |
| 1817 | void |
| 1818 | lpfc_init_vpi(struct lpfcMboxq *mbox, uint16_t vpi) |
| 1819 | { |
| 1820 | memset(mbox, 0, sizeof(*mbox)); |
| 1821 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VPI); |
| 1822 | bf_set(lpfc_init_vpi_vpi, &mbox->u.mqe.un.init_vpi, vpi); |
| 1823 | } |
| 1824 | |
| 1825 | /** |
| 1826 | * lpfc_unreg_vfi - Initialize the UNREG_VFI mailbox command |
| 1827 | * @mbox: pointer to lpfc mbox command to initialize. |
| 1828 | * @vfi: VFI to be unregistered. |
| 1829 | * |
| 1830 | * The UNREG_VFI mailbox command causes the SLI Host to put a virtual fabric |
| 1831 | * (logical NPort) into the inactive state. The SLI Host must have logged out |
| 1832 | * and unregistered all remote N_Ports to abort any activity on the virtual |
| 1833 | * fabric. The SLI Port posts the mailbox response after marking the virtual |
| 1834 | * fabric inactive. |
| 1835 | **/ |
| 1836 | void |
| 1837 | lpfc_unreg_vfi(struct lpfcMboxq *mbox, uint16_t vfi) |
| 1838 | { |
| 1839 | memset(mbox, 0, sizeof(*mbox)); |
| 1840 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_VFI); |
| 1841 | bf_set(lpfc_unreg_vfi_vfi, &mbox->u.mqe.un.unreg_vfi, vfi); |
| 1842 | } |
| 1843 | |
| 1844 | /** |
| 1845 | * lpfc_dump_fcoe_param - Dump config region 23 to get FCoe parameters. |
| 1846 | * @phba: pointer to the hba structure containing. |
| 1847 | * @mbox: pointer to lpfc mbox command to initialize. |
| 1848 | * |
| 1849 | * This function create a SLI4 dump mailbox command to dump FCoE |
| 1850 | * parameters stored in region 23. |
| 1851 | **/ |
| 1852 | int |
| 1853 | lpfc_dump_fcoe_param(struct lpfc_hba *phba, |
| 1854 | struct lpfcMboxq *mbox) |
| 1855 | { |
| 1856 | struct lpfc_dmabuf *mp = NULL; |
| 1857 | MAILBOX_t *mb; |
| 1858 | |
| 1859 | memset(mbox, 0, sizeof(*mbox)); |
| 1860 | mb = &mbox->u.mb; |
| 1861 | |
| 1862 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 1863 | if (mp) |
| 1864 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 1865 | |
| 1866 | if (!mp || !mp->virt) { |
| 1867 | kfree(mp); |
| 1868 | /* dump_fcoe_param failed to allocate memory */ |
| 1869 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
| 1870 | "2569 lpfc_dump_fcoe_param: memory" |
| 1871 | " allocation failed \n"); |
| 1872 | return 1; |
| 1873 | } |
| 1874 | |
| 1875 | memset(mp->virt, 0, LPFC_BPL_SIZE); |
| 1876 | INIT_LIST_HEAD(&mp->list); |
| 1877 | |
| 1878 | /* save address for completion */ |
| 1879 | mbox->context1 = (uint8_t *) mp; |
| 1880 | |
| 1881 | mb->mbxCommand = MBX_DUMP_MEMORY; |
| 1882 | mb->un.varDmp.type = DMP_NV_PARAMS; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame^] | 1883 | mb->un.varDmp.region_id = DMP_REGION_23; |
| 1884 | mb->un.varDmp.sli4_length = DMP_RGN23_SIZE; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1885 | mb->un.varWords[3] = putPaddrLow(mp->phys); |
| 1886 | mb->un.varWords[4] = putPaddrHigh(mp->phys); |
| 1887 | return 0; |
| 1888 | } |
| 1889 | |
| 1890 | /** |
| 1891 | * lpfc_reg_fcfi - Initialize the REG_FCFI mailbox command |
| 1892 | * @phba: pointer to the hba structure containing the FCF index and RQ ID. |
| 1893 | * @mbox: pointer to lpfc mbox command to initialize. |
| 1894 | * |
| 1895 | * The REG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). The |
| 1896 | * SLI Host uses the command to activate an FCF after it has acquired FCF |
| 1897 | * information via a READ_FCF mailbox command. This mailbox command also is used |
| 1898 | * to indicate where received unsolicited frames from this FCF will be sent. By |
| 1899 | * default this routine will set up the FCF to forward all unsolicited frames |
| 1900 | * the the RQ ID passed in the @phba. This can be overridden by the caller for |
| 1901 | * more complicated setups. |
| 1902 | **/ |
| 1903 | void |
| 1904 | lpfc_reg_fcfi(struct lpfc_hba *phba, struct lpfcMboxq *mbox) |
| 1905 | { |
| 1906 | struct lpfc_mbx_reg_fcfi *reg_fcfi; |
| 1907 | |
| 1908 | memset(mbox, 0, sizeof(*mbox)); |
| 1909 | reg_fcfi = &mbox->u.mqe.un.reg_fcfi; |
| 1910 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_FCFI); |
| 1911 | bf_set(lpfc_reg_fcfi_rq_id0, reg_fcfi, phba->sli4_hba.hdr_rq->queue_id); |
| 1912 | bf_set(lpfc_reg_fcfi_rq_id1, reg_fcfi, REG_FCF_INVALID_QID); |
| 1913 | bf_set(lpfc_reg_fcfi_rq_id2, reg_fcfi, REG_FCF_INVALID_QID); |
| 1914 | bf_set(lpfc_reg_fcfi_rq_id3, reg_fcfi, REG_FCF_INVALID_QID); |
| 1915 | bf_set(lpfc_reg_fcfi_info_index, reg_fcfi, phba->fcf.fcf_indx); |
| 1916 | /* reg_fcf addr mode is bit wise inverted value of fcf addr_mode */ |
| 1917 | bf_set(lpfc_reg_fcfi_mam, reg_fcfi, |
| 1918 | (~phba->fcf.addr_mode) & 0x3); |
| 1919 | if (phba->fcf.fcf_flag & FCF_VALID_VLAN) { |
| 1920 | bf_set(lpfc_reg_fcfi_vv, reg_fcfi, 1); |
| 1921 | bf_set(lpfc_reg_fcfi_vlan_tag, reg_fcfi, phba->fcf.vlan_id); |
| 1922 | } |
| 1923 | } |
| 1924 | |
| 1925 | /** |
| 1926 | * lpfc_unreg_fcfi - Initialize the UNREG_FCFI mailbox command |
| 1927 | * @mbox: pointer to lpfc mbox command to initialize. |
| 1928 | * @fcfi: FCFI to be unregistered. |
| 1929 | * |
| 1930 | * The UNREG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). |
| 1931 | * The SLI Host uses the command to inactivate an FCFI. |
| 1932 | **/ |
| 1933 | void |
| 1934 | lpfc_unreg_fcfi(struct lpfcMboxq *mbox, uint16_t fcfi) |
| 1935 | { |
| 1936 | memset(mbox, 0, sizeof(*mbox)); |
| 1937 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_FCFI); |
| 1938 | bf_set(lpfc_unreg_fcfi, &mbox->u.mqe.un.unreg_fcfi, fcfi); |
| 1939 | } |
| 1940 | |
| 1941 | /** |
| 1942 | * lpfc_resume_rpi - Initialize the RESUME_RPI mailbox command |
| 1943 | * @mbox: pointer to lpfc mbox command to initialize. |
| 1944 | * @ndlp: The nodelist structure that describes the RPI to resume. |
| 1945 | * |
| 1946 | * The RESUME_RPI mailbox command is used to restart I/O to an RPI after a |
| 1947 | * link event. |
| 1948 | **/ |
| 1949 | void |
| 1950 | lpfc_resume_rpi(struct lpfcMboxq *mbox, struct lpfc_nodelist *ndlp) |
| 1951 | { |
| 1952 | struct lpfc_mbx_resume_rpi *resume_rpi; |
| 1953 | |
| 1954 | memset(mbox, 0, sizeof(*mbox)); |
| 1955 | resume_rpi = &mbox->u.mqe.un.resume_rpi; |
| 1956 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_RESUME_RPI); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 1957 | bf_set(lpfc_resume_rpi_index, resume_rpi, ndlp->nlp_rpi); |
| 1958 | bf_set(lpfc_resume_rpi_ii, resume_rpi, RESUME_INDEX_RPI); |
| 1959 | resume_rpi->event_tag = ndlp->phba->fc_eventTag; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1960 | } |