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