]>
Commit | Line | Data |
---|---|---|
dea3101e JB |
1 | /******************************************************************* |
2 | * This file is part of the Emulex Linux Device Driver for * | |
c44ce173 | 3 | * Fibre Channel Host Bus Adapters. * |
50611577 | 4 | * Copyright (C) 2004-2016 Emulex. All rights reserved. * |
c44ce173 | 5 | * EMULEX and SLI are trademarks of Emulex. * |
dea3101e | 6 | * www.emulex.com * |
c44ce173 | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
dea3101e JB |
8 | * * |
9 | * This program is free software; you can redistribute it and/or * | |
c44ce173 JSEC |
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. * | |
dea3101e JB |
20 | *******************************************************************/ |
21 | ||
dea3101e | 22 | #include <linux/ctype.h> |
46fa311e | 23 | #include <linux/delay.h> |
dea3101e JB |
24 | #include <linux/pci.h> |
25 | #include <linux/interrupt.h> | |
acf3368f | 26 | #include <linux/module.h> |
0d878419 | 27 | #include <linux/aer.h> |
5a0e3ad6 | 28 | #include <linux/gfp.h> |
ecc30990 | 29 | #include <linux/kernel.h> |
dea3101e | 30 | |
91886523 | 31 | #include <scsi/scsi.h> |
dea3101e JB |
32 | #include <scsi/scsi_device.h> |
33 | #include <scsi/scsi_host.h> | |
34 | #include <scsi/scsi_tcq.h> | |
35 | #include <scsi/scsi_transport_fc.h> | |
6a9c52cf | 36 | #include <scsi/fc/fc_fs.h> |
dea3101e | 37 | |
895427bd JS |
38 | #include <linux/nvme-fc-driver.h> |
39 | ||
da0436e9 | 40 | #include "lpfc_hw4.h" |
dea3101e JB |
41 | #include "lpfc_hw.h" |
42 | #include "lpfc_sli.h" | |
da0436e9 | 43 | #include "lpfc_sli4.h" |
ea2151b4 | 44 | #include "lpfc_nl.h" |
dea3101e | 45 | #include "lpfc_disc.h" |
dea3101e | 46 | #include "lpfc.h" |
895427bd JS |
47 | #include "lpfc_scsi.h" |
48 | #include "lpfc_nvme.h" | |
f358dd0c | 49 | #include "lpfc_nvmet.h" |
dea3101e JB |
50 | #include "lpfc_logmsg.h" |
51 | #include "lpfc_version.h" | |
52 | #include "lpfc_compat.h" | |
53 | #include "lpfc_crtn.h" | |
92d7f7b0 | 54 | #include "lpfc_vport.h" |
93dd1911 | 55 | #include "lpfc_attr.h" |
dea3101e | 56 | |
2ea259ee JS |
57 | #define LPFC_DEF_DEVLOSS_TMO 30 |
58 | #define LPFC_MIN_DEVLOSS_TMO 1 | |
59 | #define LPFC_MAX_DEVLOSS_TMO 255 | |
dea3101e | 60 | |
f7a919b4 JS |
61 | /* |
62 | * Write key size should be multiple of 4. If write key is changed | |
63 | * make sure that library write key is also changed. | |
64 | */ | |
65 | #define LPFC_REG_WRITE_KEY_SIZE 4 | |
66 | #define LPFC_REG_WRITE_KEY "EMLX" | |
67 | ||
e59058c4 | 68 | /** |
3621a710 | 69 | * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules |
e59058c4 JS |
70 | * @incr: integer to convert. |
71 | * @hdw: ascii string holding converted integer plus a string terminator. | |
72 | * | |
73 | * Description: | |
74 | * JEDEC Joint Electron Device Engineering Council. | |
75 | * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii | |
76 | * character string. The string is then terminated with a NULL in byte 9. | |
77 | * Hex 0-9 becomes ascii '0' to '9'. | |
78 | * Hex a-f becomes ascii '=' to 'B' capital B. | |
79 | * | |
80 | * Notes: | |
81 | * Coded for 32 bit integers only. | |
82 | **/ | |
dea3101e JB |
83 | static void |
84 | lpfc_jedec_to_ascii(int incr, char hdw[]) | |
85 | { | |
86 | int i, j; | |
87 | for (i = 0; i < 8; i++) { | |
88 | j = (incr & 0xf); | |
89 | if (j <= 9) | |
90 | hdw[7 - i] = 0x30 + j; | |
91 | else | |
92 | hdw[7 - i] = 0x61 + j - 10; | |
93 | incr = (incr >> 4); | |
94 | } | |
95 | hdw[8] = 0; | |
96 | return; | |
97 | } | |
98 | ||
e59058c4 | 99 | /** |
3621a710 | 100 | * lpfc_drvr_version_show - Return the Emulex driver string with version number |
e59058c4 JS |
101 | * @dev: class unused variable. |
102 | * @attr: device attribute, not used. | |
103 | * @buf: on return contains the module description text. | |
104 | * | |
105 | * Returns: size of formatted string. | |
106 | **/ | |
dea3101e | 107 | static ssize_t |
ee959b00 TJ |
108 | lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr, |
109 | char *buf) | |
dea3101e JB |
110 | { |
111 | return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n"); | |
112 | } | |
113 | ||
45ed1190 JS |
114 | /** |
115 | * lpfc_enable_fip_show - Return the fip mode of the HBA | |
116 | * @dev: class unused variable. | |
117 | * @attr: device attribute, not used. | |
118 | * @buf: on return contains the module description text. | |
119 | * | |
120 | * Returns: size of formatted string. | |
121 | **/ | |
122 | static ssize_t | |
123 | lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr, | |
124 | char *buf) | |
125 | { | |
126 | struct Scsi_Host *shost = class_to_shost(dev); | |
127 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
128 | struct lpfc_hba *phba = vport->phba; | |
129 | ||
130 | if (phba->hba_flag & HBA_FIP_SUPPORT) | |
131 | return snprintf(buf, PAGE_SIZE, "1\n"); | |
132 | else | |
133 | return snprintf(buf, PAGE_SIZE, "0\n"); | |
134 | } | |
135 | ||
895427bd JS |
136 | static ssize_t |
137 | lpfc_nvme_info_show(struct device *dev, struct device_attribute *attr, | |
138 | char *buf) | |
139 | { | |
140 | struct Scsi_Host *shost = class_to_shost(dev); | |
141 | struct lpfc_vport *vport = shost_priv(shost); | |
142 | struct lpfc_hba *phba = vport->phba; | |
f358dd0c | 143 | struct lpfc_nvmet_tgtport *tgtp; |
895427bd JS |
144 | struct nvme_fc_local_port *localport; |
145 | struct lpfc_nvme_lport *lport; | |
146 | struct lpfc_nvme_rport *rport; | |
147 | struct nvme_fc_remote_port *nrport; | |
148 | char *statep; | |
149 | int len = 0; | |
150 | ||
151 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) { | |
152 | len += snprintf(buf, PAGE_SIZE, "NVME Disabled\n"); | |
153 | return len; | |
154 | } | |
f358dd0c JS |
155 | if (phba->nvmet_support) { |
156 | if (!phba->targetport) { | |
157 | len = snprintf(buf, PAGE_SIZE, | |
158 | "NVME Target: x%llx is not allocated\n", | |
159 | wwn_to_u64(vport->fc_portname.u.wwn)); | |
160 | return len; | |
161 | } | |
162 | /* Port state is only one of two values for now. */ | |
163 | if (phba->targetport->port_id) | |
164 | statep = "REGISTERED"; | |
165 | else | |
166 | statep = "INIT"; | |
167 | len += snprintf(buf + len, PAGE_SIZE - len, | |
168 | "NVME Target: Enabled State %s\n", | |
169 | statep); | |
170 | len += snprintf(buf + len, PAGE_SIZE - len, | |
171 | "%s%d WWPN x%llx WWNN x%llx DID x%06x\n", | |
172 | "NVME Target: lpfc", | |
173 | phba->brd_no, | |
174 | wwn_to_u64(vport->fc_portname.u.wwn), | |
175 | wwn_to_u64(vport->fc_nodename.u.wwn), | |
176 | phba->targetport->port_id); | |
177 | ||
178 | len += snprintf(buf + len, PAGE_SIZE, | |
179 | "\nNVME Target: Statistics\n"); | |
180 | tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; | |
181 | len += snprintf(buf+len, PAGE_SIZE-len, | |
182 | "LS: Rcv %08x Drop %08x Abort %08x\n", | |
183 | atomic_read(&tgtp->rcv_ls_req_in), | |
184 | atomic_read(&tgtp->rcv_ls_req_drop), | |
185 | atomic_read(&tgtp->xmt_ls_abort)); | |
186 | if (atomic_read(&tgtp->rcv_ls_req_in) != | |
187 | atomic_read(&tgtp->rcv_ls_req_out)) { | |
188 | len += snprintf(buf+len, PAGE_SIZE-len, | |
189 | "Rcv LS: in %08x != out %08x\n", | |
190 | atomic_read(&tgtp->rcv_ls_req_in), | |
191 | atomic_read(&tgtp->rcv_ls_req_out)); | |
192 | } | |
193 | ||
194 | len += snprintf(buf+len, PAGE_SIZE-len, | |
195 | "LS: Xmt %08x Drop %08x Cmpl %08x Err %08x\n", | |
196 | atomic_read(&tgtp->xmt_ls_rsp), | |
197 | atomic_read(&tgtp->xmt_ls_drop), | |
198 | atomic_read(&tgtp->xmt_ls_rsp_cmpl), | |
199 | atomic_read(&tgtp->xmt_ls_rsp_error)); | |
200 | ||
201 | len += snprintf(buf+len, PAGE_SIZE-len, | |
202 | "FCP: Rcv %08x Drop %08x\n", | |
203 | atomic_read(&tgtp->rcv_fcp_cmd_in), | |
204 | atomic_read(&tgtp->rcv_fcp_cmd_drop)); | |
205 | ||
206 | if (atomic_read(&tgtp->rcv_fcp_cmd_in) != | |
207 | atomic_read(&tgtp->rcv_fcp_cmd_out)) { | |
208 | len += snprintf(buf+len, PAGE_SIZE-len, | |
209 | "Rcv FCP: in %08x != out %08x\n", | |
210 | atomic_read(&tgtp->rcv_fcp_cmd_in), | |
211 | atomic_read(&tgtp->rcv_fcp_cmd_out)); | |
212 | } | |
213 | ||
214 | len += snprintf(buf+len, PAGE_SIZE-len, | |
215 | "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x\n", | |
216 | atomic_read(&tgtp->xmt_fcp_read), | |
217 | atomic_read(&tgtp->xmt_fcp_read_rsp), | |
218 | atomic_read(&tgtp->xmt_fcp_write), | |
219 | atomic_read(&tgtp->xmt_fcp_rsp)); | |
220 | ||
221 | len += snprintf(buf+len, PAGE_SIZE-len, | |
222 | "FCP Rsp: abort %08x drop %08x\n", | |
223 | atomic_read(&tgtp->xmt_fcp_abort), | |
224 | atomic_read(&tgtp->xmt_fcp_drop)); | |
225 | ||
226 | len += snprintf(buf+len, PAGE_SIZE-len, | |
227 | "FCP Rsp Cmpl: %08x err %08x drop %08x\n", | |
228 | atomic_read(&tgtp->xmt_fcp_rsp_cmpl), | |
229 | atomic_read(&tgtp->xmt_fcp_rsp_error), | |
230 | atomic_read(&tgtp->xmt_fcp_rsp_drop)); | |
231 | ||
232 | len += snprintf(buf+len, PAGE_SIZE-len, | |
233 | "ABORT: Xmt %08x Err %08x Cmpl %08x", | |
234 | atomic_read(&tgtp->xmt_abort_rsp), | |
235 | atomic_read(&tgtp->xmt_abort_rsp_error), | |
236 | atomic_read(&tgtp->xmt_abort_cmpl)); | |
237 | ||
238 | len += snprintf(buf+len, PAGE_SIZE-len, "\n"); | |
239 | return len; | |
240 | } | |
895427bd JS |
241 | |
242 | localport = vport->localport; | |
243 | if (!localport) { | |
244 | len = snprintf(buf, PAGE_SIZE, | |
245 | "NVME Initiator x%llx is not allocated\n", | |
246 | wwn_to_u64(vport->fc_portname.u.wwn)); | |
247 | return len; | |
248 | } | |
249 | len = snprintf(buf, PAGE_SIZE, "NVME Initiator Enabled\n"); | |
250 | ||
251 | spin_lock_irq(shost->host_lock); | |
252 | lport = (struct lpfc_nvme_lport *)localport->private; | |
253 | ||
254 | /* Port state is only one of two values for now. */ | |
255 | if (localport->port_id) | |
256 | statep = "ONLINE"; | |
257 | else | |
258 | statep = "UNKNOWN "; | |
259 | ||
260 | len += snprintf(buf + len, PAGE_SIZE - len, | |
261 | "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n", | |
262 | "NVME LPORT lpfc", | |
263 | phba->brd_no, | |
264 | wwn_to_u64(vport->fc_portname.u.wwn), | |
265 | wwn_to_u64(vport->fc_nodename.u.wwn), | |
266 | localport->port_id, statep); | |
267 | ||
268 | list_for_each_entry(rport, &lport->rport_list, list) { | |
269 | /* local short-hand pointer. */ | |
270 | nrport = rport->remoteport; | |
271 | ||
272 | /* Port state is only one of two values for now. */ | |
273 | switch (nrport->port_state) { | |
274 | case FC_OBJSTATE_ONLINE: | |
275 | statep = "ONLINE"; | |
276 | break; | |
277 | case FC_OBJSTATE_UNKNOWN: | |
278 | statep = "UNKNOWN "; | |
279 | break; | |
280 | default: | |
281 | statep = "UNSUPPORTED"; | |
282 | break; | |
283 | } | |
284 | ||
285 | /* Tab in to show lport ownership. */ | |
286 | len += snprintf(buf + len, PAGE_SIZE - len, | |
287 | "NVME RPORT "); | |
288 | if (phba->brd_no >= 10) | |
289 | len += snprintf(buf + len, PAGE_SIZE - len, " "); | |
290 | ||
291 | len += snprintf(buf + len, PAGE_SIZE - len, "WWPN x%llx ", | |
292 | nrport->port_name); | |
293 | len += snprintf(buf + len, PAGE_SIZE - len, "WWNN x%llx ", | |
294 | nrport->node_name); | |
295 | len += snprintf(buf + len, PAGE_SIZE - len, "DID x%06x ", | |
296 | nrport->port_id); | |
297 | ||
298 | switch (nrport->port_role) { | |
299 | case FC_PORT_ROLE_NVME_INITIATOR: | |
300 | len += snprintf(buf + len, PAGE_SIZE - len, | |
301 | "INITIATOR "); | |
302 | break; | |
303 | case FC_PORT_ROLE_NVME_TARGET: | |
304 | len += snprintf(buf + len, PAGE_SIZE - len, | |
305 | "TARGET "); | |
306 | break; | |
307 | case FC_PORT_ROLE_NVME_DISCOVERY: | |
308 | len += snprintf(buf + len, PAGE_SIZE - len, | |
309 | "DISCOVERY "); | |
310 | break; | |
311 | default: | |
312 | len += snprintf(buf + len, PAGE_SIZE - len, | |
313 | "UNKNOWN_ROLE x%x", | |
314 | nrport->port_role); | |
315 | break; | |
316 | } | |
317 | len += snprintf(buf + len, PAGE_SIZE - len, "%s ", statep); | |
318 | /* Terminate the string. */ | |
319 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); | |
320 | } | |
321 | spin_unlock_irq(shost->host_lock); | |
322 | ||
323 | len += snprintf(buf + len, PAGE_SIZE, "\nNVME Statistics\n"); | |
324 | len += snprintf(buf+len, PAGE_SIZE-len, | |
325 | "LS: Xmt %016llx Cmpl %016llx\n", | |
326 | phba->fc4NvmeLsRequests, | |
327 | phba->fc4NvmeLsCmpls); | |
328 | ||
329 | len += snprintf(buf+len, PAGE_SIZE-len, | |
330 | "FCP: Rd %016llx Wr %016llx IO %016llx\n", | |
331 | phba->fc4NvmeInputRequests, | |
332 | phba->fc4NvmeOutputRequests, | |
333 | phba->fc4NvmeControlRequests); | |
334 | ||
335 | len += snprintf(buf+len, PAGE_SIZE-len, | |
336 | " Cmpl %016llx\n", phba->fc4NvmeIoCmpls); | |
337 | ||
338 | return len; | |
339 | } | |
340 | ||
81301a9b JS |
341 | static ssize_t |
342 | lpfc_bg_info_show(struct device *dev, struct device_attribute *attr, | |
343 | char *buf) | |
344 | { | |
345 | struct Scsi_Host *shost = class_to_shost(dev); | |
346 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
347 | struct lpfc_hba *phba = vport->phba; | |
348 | ||
349 | if (phba->cfg_enable_bg) | |
350 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) | |
351 | return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n"); | |
352 | else | |
353 | return snprintf(buf, PAGE_SIZE, | |
354 | "BlockGuard Not Supported\n"); | |
355 | else | |
356 | return snprintf(buf, PAGE_SIZE, | |
357 | "BlockGuard Disabled\n"); | |
358 | } | |
359 | ||
360 | static ssize_t | |
361 | lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr, | |
362 | char *buf) | |
363 | { | |
364 | struct Scsi_Host *shost = class_to_shost(dev); | |
365 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
366 | struct lpfc_hba *phba = vport->phba; | |
367 | ||
87b5c328 JS |
368 | return snprintf(buf, PAGE_SIZE, "%llu\n", |
369 | (unsigned long long)phba->bg_guard_err_cnt); | |
81301a9b JS |
370 | } |
371 | ||
372 | static ssize_t | |
373 | lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr, | |
374 | char *buf) | |
375 | { | |
376 | struct Scsi_Host *shost = class_to_shost(dev); | |
377 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
378 | struct lpfc_hba *phba = vport->phba; | |
379 | ||
87b5c328 JS |
380 | return snprintf(buf, PAGE_SIZE, "%llu\n", |
381 | (unsigned long long)phba->bg_apptag_err_cnt); | |
81301a9b JS |
382 | } |
383 | ||
384 | static ssize_t | |
385 | lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr, | |
386 | char *buf) | |
387 | { | |
388 | struct Scsi_Host *shost = class_to_shost(dev); | |
389 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
390 | struct lpfc_hba *phba = vport->phba; | |
391 | ||
87b5c328 JS |
392 | return snprintf(buf, PAGE_SIZE, "%llu\n", |
393 | (unsigned long long)phba->bg_reftag_err_cnt); | |
81301a9b JS |
394 | } |
395 | ||
e59058c4 | 396 | /** |
3621a710 | 397 | * lpfc_info_show - Return some pci info about the host in ascii |
e59058c4 JS |
398 | * @dev: class converted to a Scsi_host structure. |
399 | * @attr: device attribute, not used. | |
400 | * @buf: on return contains the formatted text from lpfc_info(). | |
401 | * | |
402 | * Returns: size of formatted string. | |
403 | **/ | |
dea3101e | 404 | static ssize_t |
ee959b00 TJ |
405 | lpfc_info_show(struct device *dev, struct device_attribute *attr, |
406 | char *buf) | |
dea3101e | 407 | { |
ee959b00 | 408 | struct Scsi_Host *host = class_to_shost(dev); |
2e0fef85 | 409 | |
dea3101e JB |
410 | return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host)); |
411 | } | |
412 | ||
e59058c4 | 413 | /** |
3621a710 | 414 | * lpfc_serialnum_show - Return the hba serial number in ascii |
e59058c4 JS |
415 | * @dev: class converted to a Scsi_host structure. |
416 | * @attr: device attribute, not used. | |
417 | * @buf: on return contains the formatted text serial number. | |
418 | * | |
419 | * Returns: size of formatted string. | |
420 | **/ | |
dea3101e | 421 | static ssize_t |
ee959b00 TJ |
422 | lpfc_serialnum_show(struct device *dev, struct device_attribute *attr, |
423 | char *buf) | |
dea3101e | 424 | { |
ee959b00 | 425 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
426 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
427 | struct lpfc_hba *phba = vport->phba; | |
428 | ||
dea3101e JB |
429 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber); |
430 | } | |
431 | ||
e59058c4 | 432 | /** |
3621a710 | 433 | * lpfc_temp_sensor_show - Return the temperature sensor level |
e59058c4 JS |
434 | * @dev: class converted to a Scsi_host structure. |
435 | * @attr: device attribute, not used. | |
436 | * @buf: on return contains the formatted support level. | |
437 | * | |
438 | * Description: | |
439 | * Returns a number indicating the temperature sensor level currently | |
440 | * supported, zero or one in ascii. | |
441 | * | |
442 | * Returns: size of formatted string. | |
443 | **/ | |
57127f15 | 444 | static ssize_t |
ee959b00 TJ |
445 | lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr, |
446 | char *buf) | |
57127f15 | 447 | { |
ee959b00 | 448 | struct Scsi_Host *shost = class_to_shost(dev); |
57127f15 JS |
449 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
450 | struct lpfc_hba *phba = vport->phba; | |
451 | return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support); | |
452 | } | |
453 | ||
e59058c4 | 454 | /** |
3621a710 | 455 | * lpfc_modeldesc_show - Return the model description of the hba |
e59058c4 JS |
456 | * @dev: class converted to a Scsi_host structure. |
457 | * @attr: device attribute, not used. | |
458 | * @buf: on return contains the scsi vpd model description. | |
459 | * | |
460 | * Returns: size of formatted string. | |
461 | **/ | |
dea3101e | 462 | static ssize_t |
ee959b00 TJ |
463 | lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr, |
464 | char *buf) | |
dea3101e | 465 | { |
ee959b00 | 466 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
467 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
468 | struct lpfc_hba *phba = vport->phba; | |
469 | ||
dea3101e JB |
470 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc); |
471 | } | |
472 | ||
e59058c4 | 473 | /** |
3621a710 | 474 | * lpfc_modelname_show - Return the model name of the hba |
e59058c4 JS |
475 | * @dev: class converted to a Scsi_host structure. |
476 | * @attr: device attribute, not used. | |
477 | * @buf: on return contains the scsi vpd model name. | |
478 | * | |
479 | * Returns: size of formatted string. | |
480 | **/ | |
dea3101e | 481 | static ssize_t |
ee959b00 TJ |
482 | lpfc_modelname_show(struct device *dev, struct device_attribute *attr, |
483 | char *buf) | |
dea3101e | 484 | { |
ee959b00 | 485 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
486 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
487 | struct lpfc_hba *phba = vport->phba; | |
488 | ||
dea3101e JB |
489 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName); |
490 | } | |
491 | ||
e59058c4 | 492 | /** |
3621a710 | 493 | * lpfc_programtype_show - Return the program type of the hba |
e59058c4 JS |
494 | * @dev: class converted to a Scsi_host structure. |
495 | * @attr: device attribute, not used. | |
496 | * @buf: on return contains the scsi vpd program type. | |
497 | * | |
498 | * Returns: size of formatted string. | |
499 | **/ | |
dea3101e | 500 | static ssize_t |
ee959b00 TJ |
501 | lpfc_programtype_show(struct device *dev, struct device_attribute *attr, |
502 | char *buf) | |
dea3101e | 503 | { |
ee959b00 | 504 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
505 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
506 | struct lpfc_hba *phba = vport->phba; | |
507 | ||
dea3101e JB |
508 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType); |
509 | } | |
510 | ||
84774a4d | 511 | /** |
3621a710 | 512 | * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag |
84774a4d JS |
513 | * @dev: class converted to a Scsi_host structure. |
514 | * @attr: device attribute, not used. | |
515 | * @buf: on return contains the Menlo Maintenance sli flag. | |
516 | * | |
517 | * Returns: size of formatted string. | |
518 | **/ | |
519 | static ssize_t | |
520 | lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf) | |
521 | { | |
522 | struct Scsi_Host *shost = class_to_shost(dev); | |
523 | struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; | |
524 | struct lpfc_hba *phba = vport->phba; | |
525 | ||
526 | return snprintf(buf, PAGE_SIZE, "%d\n", | |
527 | (phba->sli.sli_flag & LPFC_MENLO_MAINT)); | |
528 | } | |
529 | ||
e59058c4 | 530 | /** |
3621a710 | 531 | * lpfc_vportnum_show - Return the port number in ascii of the hba |
e59058c4 JS |
532 | * @dev: class converted to a Scsi_host structure. |
533 | * @attr: device attribute, not used. | |
534 | * @buf: on return contains scsi vpd program type. | |
535 | * | |
536 | * Returns: size of formatted string. | |
537 | **/ | |
dea3101e | 538 | static ssize_t |
ee959b00 TJ |
539 | lpfc_vportnum_show(struct device *dev, struct device_attribute *attr, |
540 | char *buf) | |
dea3101e | 541 | { |
ee959b00 | 542 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
543 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
544 | struct lpfc_hba *phba = vport->phba; | |
545 | ||
dea3101e JB |
546 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port); |
547 | } | |
548 | ||
e59058c4 | 549 | /** |
3621a710 | 550 | * lpfc_fwrev_show - Return the firmware rev running in the hba |
e59058c4 JS |
551 | * @dev: class converted to a Scsi_host structure. |
552 | * @attr: device attribute, not used. | |
553 | * @buf: on return contains the scsi vpd program type. | |
554 | * | |
555 | * Returns: size of formatted string. | |
556 | **/ | |
dea3101e | 557 | static ssize_t |
ee959b00 TJ |
558 | lpfc_fwrev_show(struct device *dev, struct device_attribute *attr, |
559 | char *buf) | |
dea3101e | 560 | { |
ee959b00 | 561 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
562 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
563 | struct lpfc_hba *phba = vport->phba; | |
026abb87 JS |
564 | uint32_t if_type; |
565 | uint8_t sli_family; | |
6b5151fd | 566 | char fwrev[FW_REV_STR_SIZE]; |
026abb87 | 567 | int len; |
2e0fef85 | 568 | |
dea3101e | 569 | lpfc_decode_firmware_rev(phba, fwrev, 1); |
026abb87 JS |
570 | if_type = phba->sli4_hba.pc_sli4_params.if_type; |
571 | sli_family = phba->sli4_hba.pc_sli4_params.sli_family; | |
572 | ||
573 | if (phba->sli_rev < LPFC_SLI_REV4) | |
574 | len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", | |
575 | fwrev, phba->sli_rev); | |
576 | else | |
577 | len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n", | |
578 | fwrev, phba->sli_rev, if_type, sli_family); | |
579 | ||
580 | return len; | |
dea3101e JB |
581 | } |
582 | ||
e59058c4 | 583 | /** |
3621a710 | 584 | * lpfc_hdw_show - Return the jedec information about the hba |
e59058c4 JS |
585 | * @dev: class converted to a Scsi_host structure. |
586 | * @attr: device attribute, not used. | |
587 | * @buf: on return contains the scsi vpd program type. | |
588 | * | |
589 | * Returns: size of formatted string. | |
590 | **/ | |
dea3101e | 591 | static ssize_t |
ee959b00 | 592 | lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf) |
dea3101e JB |
593 | { |
594 | char hdw[9]; | |
ee959b00 | 595 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
596 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
597 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 598 | lpfc_vpd_t *vp = &phba->vpd; |
2e0fef85 | 599 | |
dea3101e JB |
600 | lpfc_jedec_to_ascii(vp->rev.biuRev, hdw); |
601 | return snprintf(buf, PAGE_SIZE, "%s\n", hdw); | |
602 | } | |
e59058c4 JS |
603 | |
604 | /** | |
3621a710 | 605 | * lpfc_option_rom_version_show - Return the adapter ROM FCode version |
e59058c4 JS |
606 | * @dev: class converted to a Scsi_host structure. |
607 | * @attr: device attribute, not used. | |
608 | * @buf: on return contains the ROM and FCode ascii strings. | |
609 | * | |
610 | * Returns: size of formatted string. | |
611 | **/ | |
dea3101e | 612 | static ssize_t |
ee959b00 TJ |
613 | lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr, |
614 | char *buf) | |
dea3101e | 615 | { |
ee959b00 | 616 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
617 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
618 | struct lpfc_hba *phba = vport->phba; | |
a0683bf6 JS |
619 | char fwrev[FW_REV_STR_SIZE]; |
620 | ||
621 | if (phba->sli_rev < LPFC_SLI_REV4) | |
622 | return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion); | |
2e0fef85 | 623 | |
a0683bf6 JS |
624 | lpfc_decode_firmware_rev(phba, fwrev, 1); |
625 | return snprintf(buf, PAGE_SIZE, "%s\n", fwrev); | |
dea3101e | 626 | } |
e59058c4 JS |
627 | |
628 | /** | |
3621a710 | 629 | * lpfc_state_show - Return the link state of the port |
e59058c4 JS |
630 | * @dev: class converted to a Scsi_host structure. |
631 | * @attr: device attribute, not used. | |
632 | * @buf: on return contains text describing the state of the link. | |
633 | * | |
634 | * Notes: | |
635 | * The switch statement has no default so zero will be returned. | |
636 | * | |
637 | * Returns: size of formatted string. | |
638 | **/ | |
dea3101e | 639 | static ssize_t |
bbd1ae41 HR |
640 | lpfc_link_state_show(struct device *dev, struct device_attribute *attr, |
641 | char *buf) | |
dea3101e | 642 | { |
ee959b00 | 643 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
644 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
645 | struct lpfc_hba *phba = vport->phba; | |
646 | int len = 0; | |
647 | ||
648 | switch (phba->link_state) { | |
649 | case LPFC_LINK_UNKNOWN: | |
41415862 | 650 | case LPFC_WARM_START: |
dea3101e JB |
651 | case LPFC_INIT_START: |
652 | case LPFC_INIT_MBX_CMDS: | |
653 | case LPFC_LINK_DOWN: | |
2e0fef85 | 654 | case LPFC_HBA_ERROR: |
a0c87cbd JS |
655 | if (phba->hba_flag & LINK_DISABLED) |
656 | len += snprintf(buf + len, PAGE_SIZE-len, | |
657 | "Link Down - User disabled\n"); | |
658 | else | |
659 | len += snprintf(buf + len, PAGE_SIZE-len, | |
660 | "Link Down\n"); | |
dea3101e JB |
661 | break; |
662 | case LPFC_LINK_UP: | |
dea3101e | 663 | case LPFC_CLEAR_LA: |
dea3101e | 664 | case LPFC_HBA_READY: |
a8adb832 | 665 | len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - "); |
2e0fef85 JS |
666 | |
667 | switch (vport->port_state) { | |
2e0fef85 JS |
668 | case LPFC_LOCAL_CFG_LINK: |
669 | len += snprintf(buf + len, PAGE_SIZE-len, | |
92d7f7b0 | 670 | "Configuring Link\n"); |
2e0fef85 | 671 | break; |
92d7f7b0 | 672 | case LPFC_FDISC: |
2e0fef85 JS |
673 | case LPFC_FLOGI: |
674 | case LPFC_FABRIC_CFG_LINK: | |
675 | case LPFC_NS_REG: | |
676 | case LPFC_NS_QRY: | |
677 | case LPFC_BUILD_DISC_LIST: | |
678 | case LPFC_DISC_AUTH: | |
679 | len += snprintf(buf + len, PAGE_SIZE - len, | |
680 | "Discovery\n"); | |
681 | break; | |
682 | case LPFC_VPORT_READY: | |
683 | len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n"); | |
684 | break; | |
685 | ||
92d7f7b0 JS |
686 | case LPFC_VPORT_FAILED: |
687 | len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n"); | |
688 | break; | |
689 | ||
690 | case LPFC_VPORT_UNKNOWN: | |
2e0fef85 JS |
691 | len += snprintf(buf + len, PAGE_SIZE - len, |
692 | "Unknown\n"); | |
693 | break; | |
694 | } | |
84774a4d JS |
695 | if (phba->sli.sli_flag & LPFC_MENLO_MAINT) |
696 | len += snprintf(buf + len, PAGE_SIZE-len, | |
697 | " Menlo Maint Mode\n"); | |
76a95d75 | 698 | else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
2e0fef85 | 699 | if (vport->fc_flag & FC_PUBLIC_LOOP) |
dea3101e JB |
700 | len += snprintf(buf + len, PAGE_SIZE-len, |
701 | " Public Loop\n"); | |
702 | else | |
703 | len += snprintf(buf + len, PAGE_SIZE-len, | |
704 | " Private Loop\n"); | |
705 | } else { | |
2e0fef85 | 706 | if (vport->fc_flag & FC_FABRIC) |
dea3101e JB |
707 | len += snprintf(buf + len, PAGE_SIZE-len, |
708 | " Fabric\n"); | |
709 | else | |
710 | len += snprintf(buf + len, PAGE_SIZE-len, | |
711 | " Point-2-Point\n"); | |
712 | } | |
713 | } | |
2e0fef85 | 714 | |
dea3101e JB |
715 | return len; |
716 | } | |
717 | ||
026abb87 JS |
718 | /** |
719 | * lpfc_sli4_protocol_show - Return the fip mode of the HBA | |
720 | * @dev: class unused variable. | |
721 | * @attr: device attribute, not used. | |
722 | * @buf: on return contains the module description text. | |
723 | * | |
724 | * Returns: size of formatted string. | |
725 | **/ | |
726 | static ssize_t | |
727 | lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr, | |
728 | char *buf) | |
729 | { | |
730 | struct Scsi_Host *shost = class_to_shost(dev); | |
731 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
732 | struct lpfc_hba *phba = vport->phba; | |
733 | ||
734 | if (phba->sli_rev < LPFC_SLI_REV4) | |
735 | return snprintf(buf, PAGE_SIZE, "fc\n"); | |
736 | ||
737 | if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) { | |
738 | if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE) | |
739 | return snprintf(buf, PAGE_SIZE, "fcoe\n"); | |
740 | if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC) | |
741 | return snprintf(buf, PAGE_SIZE, "fc\n"); | |
742 | } | |
743 | return snprintf(buf, PAGE_SIZE, "unknown\n"); | |
744 | } | |
745 | ||
1ba981fd JS |
746 | /** |
747 | * lpfc_oas_supported_show - Return whether or not Optimized Access Storage | |
748 | * (OAS) is supported. | |
749 | * @dev: class unused variable. | |
750 | * @attr: device attribute, not used. | |
751 | * @buf: on return contains the module description text. | |
752 | * | |
753 | * Returns: size of formatted string. | |
754 | **/ | |
755 | static ssize_t | |
756 | lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr, | |
757 | char *buf) | |
758 | { | |
759 | struct Scsi_Host *shost = class_to_shost(dev); | |
760 | struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; | |
761 | struct lpfc_hba *phba = vport->phba; | |
762 | ||
763 | return snprintf(buf, PAGE_SIZE, "%d\n", | |
764 | phba->sli4_hba.pc_sli4_params.oas_supported); | |
765 | } | |
766 | ||
84d1b006 JS |
767 | /** |
768 | * lpfc_link_state_store - Transition the link_state on an HBA port | |
769 | * @dev: class device that is converted into a Scsi_host. | |
770 | * @attr: device attribute, not used. | |
771 | * @buf: one or more lpfc_polling_flags values. | |
772 | * @count: not used. | |
773 | * | |
774 | * Returns: | |
775 | * -EINVAL if the buffer is not "up" or "down" | |
776 | * return from link state change function if non-zero | |
777 | * length of the buf on success | |
778 | **/ | |
779 | static ssize_t | |
780 | lpfc_link_state_store(struct device *dev, struct device_attribute *attr, | |
781 | const char *buf, size_t count) | |
782 | { | |
783 | struct Scsi_Host *shost = class_to_shost(dev); | |
784 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
785 | struct lpfc_hba *phba = vport->phba; | |
786 | ||
787 | int status = -EINVAL; | |
788 | ||
789 | if ((strncmp(buf, "up", sizeof("up") - 1) == 0) && | |
790 | (phba->link_state == LPFC_LINK_DOWN)) | |
6e7288d9 | 791 | status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
84d1b006 JS |
792 | else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) && |
793 | (phba->link_state >= LPFC_LINK_UP)) | |
6e7288d9 | 794 | status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT); |
84d1b006 JS |
795 | |
796 | if (status == 0) | |
797 | return strlen(buf); | |
798 | else | |
799 | return status; | |
800 | } | |
801 | ||
e59058c4 | 802 | /** |
3621a710 | 803 | * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports |
e59058c4 JS |
804 | * @dev: class device that is converted into a Scsi_host. |
805 | * @attr: device attribute, not used. | |
806 | * @buf: on return contains the sum of fc mapped and unmapped. | |
807 | * | |
808 | * Description: | |
809 | * Returns the ascii text number of the sum of the fc mapped and unmapped | |
810 | * vport counts. | |
811 | * | |
812 | * Returns: size of formatted string. | |
813 | **/ | |
dea3101e | 814 | static ssize_t |
ee959b00 TJ |
815 | lpfc_num_discovered_ports_show(struct device *dev, |
816 | struct device_attribute *attr, char *buf) | |
dea3101e | 817 | { |
ee959b00 | 818 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
819 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
820 | ||
821 | return snprintf(buf, PAGE_SIZE, "%d\n", | |
822 | vport->fc_map_cnt + vport->fc_unmap_cnt); | |
dea3101e JB |
823 | } |
824 | ||
e59058c4 | 825 | /** |
3621a710 | 826 | * lpfc_issue_lip - Misnomer, name carried over from long ago |
e59058c4 JS |
827 | * @shost: Scsi_Host pointer. |
828 | * | |
829 | * Description: | |
830 | * Bring the link down gracefully then re-init the link. The firmware will | |
831 | * re-init the fiber channel interface as required. Does not issue a LIP. | |
832 | * | |
833 | * Returns: | |
834 | * -EPERM port offline or management commands are being blocked | |
835 | * -ENOMEM cannot allocate memory for the mailbox command | |
836 | * -EIO error sending the mailbox command | |
837 | * zero for success | |
838 | **/ | |
91ca7b01 | 839 | static int |
2e0fef85 | 840 | lpfc_issue_lip(struct Scsi_Host *shost) |
dea3101e | 841 | { |
2e0fef85 JS |
842 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
843 | struct lpfc_hba *phba = vport->phba; | |
dea3101e JB |
844 | LPFC_MBOXQ_t *pmboxq; |
845 | int mbxstatus = MBXERR_ERROR; | |
846 | ||
2e0fef85 | 847 | if ((vport->fc_flag & FC_OFFLINE_MODE) || |
83108bd3 | 848 | (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)) |
dea3101e JB |
849 | return -EPERM; |
850 | ||
851 | pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL); | |
852 | ||
853 | if (!pmboxq) | |
854 | return -ENOMEM; | |
855 | ||
856 | memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t)); | |
04c68496 JS |
857 | pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK; |
858 | pmboxq->u.mb.mbxOwner = OWN_HOST; | |
4db621e0 | 859 | |
33ccf8d1 | 860 | mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2); |
dea3101e | 861 | |
04c68496 JS |
862 | if ((mbxstatus == MBX_SUCCESS) && |
863 | (pmboxq->u.mb.mbxStatus == 0 || | |
864 | pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) { | |
4db621e0 JS |
865 | memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t)); |
866 | lpfc_init_link(phba, pmboxq, phba->cfg_topology, | |
867 | phba->cfg_link_speed); | |
868 | mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, | |
869 | phba->fc_ratov * 2); | |
dcf2a4e0 JS |
870 | if ((mbxstatus == MBX_SUCCESS) && |
871 | (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) | |
872 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
873 | "2859 SLI authentication is required " | |
874 | "for INIT_LINK but has not done yet\n"); | |
4db621e0 JS |
875 | } |
876 | ||
5b8bd0c9 | 877 | lpfc_set_loopback_flag(phba); |
858c9f6c | 878 | if (mbxstatus != MBX_TIMEOUT) |
433c3579 | 879 | mempool_free(pmboxq, phba->mbox_mem_pool); |
dea3101e JB |
880 | |
881 | if (mbxstatus == MBXERR_ERROR) | |
882 | return -EIO; | |
883 | ||
91ca7b01 | 884 | return 0; |
dea3101e JB |
885 | } |
886 | ||
895427bd JS |
887 | int |
888 | lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock) | |
889 | { | |
890 | int cnt = 0; | |
891 | ||
892 | spin_lock_irq(lock); | |
893 | while (!list_empty(q)) { | |
894 | spin_unlock_irq(lock); | |
895 | msleep(20); | |
896 | if (cnt++ > 250) { /* 5 secs */ | |
897 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
898 | "0466 %s %s\n", | |
899 | "Outstanding IO when ", | |
900 | "bringing Adapter offline\n"); | |
901 | return 0; | |
902 | } | |
903 | spin_lock_irq(lock); | |
904 | } | |
905 | spin_unlock_irq(lock); | |
906 | return 1; | |
907 | } | |
908 | ||
e59058c4 | 909 | /** |
3621a710 | 910 | * lpfc_do_offline - Issues a mailbox command to bring the link down |
e59058c4 JS |
911 | * @phba: lpfc_hba pointer. |
912 | * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL. | |
913 | * | |
914 | * Notes: | |
915 | * Assumes any error from lpfc_do_offline() will be negative. | |
916 | * Can wait up to 5 seconds for the port ring buffers count | |
917 | * to reach zero, prints a warning if it is not zero and continues. | |
3621a710 | 918 | * lpfc_workq_post_event() returns a non-zero return code if call fails. |
e59058c4 JS |
919 | * |
920 | * Returns: | |
921 | * -EIO error posting the event | |
922 | * zero for success | |
923 | **/ | |
40496f07 | 924 | static int |
46fa311e | 925 | lpfc_do_offline(struct lpfc_hba *phba, uint32_t type) |
40496f07 JS |
926 | { |
927 | struct completion online_compl; | |
895427bd | 928 | struct lpfc_queue *qp = NULL; |
46fa311e JS |
929 | struct lpfc_sli_ring *pring; |
930 | struct lpfc_sli *psli; | |
40496f07 | 931 | int status = 0; |
46fa311e | 932 | int i; |
fedd3b7b | 933 | int rc; |
40496f07 JS |
934 | |
935 | init_completion(&online_compl); | |
fedd3b7b | 936 | rc = lpfc_workq_post_event(phba, &status, &online_compl, |
46fa311e | 937 | LPFC_EVT_OFFLINE_PREP); |
fedd3b7b JS |
938 | if (rc == 0) |
939 | return -ENOMEM; | |
940 | ||
46fa311e JS |
941 | wait_for_completion(&online_compl); |
942 | ||
943 | if (status != 0) | |
944 | return -EIO; | |
945 | ||
946 | psli = &phba->sli; | |
947 | ||
09372820 JS |
948 | /* Wait a little for things to settle down, but not |
949 | * long enough for dev loss timeout to expire. | |
950 | */ | |
895427bd JS |
951 | if (phba->sli_rev != LPFC_SLI_REV4) { |
952 | for (i = 0; i < psli->num_rings; i++) { | |
953 | pring = &psli->sli3_ring[i]; | |
954 | if (!lpfc_emptyq_wait(phba, &pring->txcmplq, | |
955 | &phba->hbalock)) | |
956 | goto out; | |
957 | } | |
958 | } else { | |
959 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { | |
960 | pring = qp->pring; | |
961 | if (!pring) | |
962 | continue; | |
963 | if (!lpfc_emptyq_wait(phba, &pring->txcmplq, | |
964 | &pring->ring_lock)) | |
965 | goto out; | |
46fa311e JS |
966 | } |
967 | } | |
895427bd | 968 | out: |
46fa311e | 969 | init_completion(&online_compl); |
fedd3b7b JS |
970 | rc = lpfc_workq_post_event(phba, &status, &online_compl, type); |
971 | if (rc == 0) | |
972 | return -ENOMEM; | |
973 | ||
40496f07 JS |
974 | wait_for_completion(&online_compl); |
975 | ||
976 | if (status != 0) | |
977 | return -EIO; | |
978 | ||
46fa311e JS |
979 | return 0; |
980 | } | |
981 | ||
e59058c4 | 982 | /** |
3621a710 | 983 | * lpfc_selective_reset - Offline then onlines the port |
e59058c4 JS |
984 | * @phba: lpfc_hba pointer. |
985 | * | |
986 | * Description: | |
987 | * If the port is configured to allow a reset then the hba is brought | |
988 | * offline then online. | |
989 | * | |
990 | * Notes: | |
991 | * Assumes any error from lpfc_do_offline() will be negative. | |
ab56dc2e | 992 | * Do not make this function static. |
e59058c4 JS |
993 | * |
994 | * Returns: | |
995 | * lpfc_do_offline() return code if not zero | |
996 | * -EIO reset not configured or error posting the event | |
997 | * zero for success | |
998 | **/ | |
7f86059a | 999 | int |
46fa311e JS |
1000 | lpfc_selective_reset(struct lpfc_hba *phba) |
1001 | { | |
1002 | struct completion online_compl; | |
1003 | int status = 0; | |
fedd3b7b | 1004 | int rc; |
46fa311e | 1005 | |
71157c9e | 1006 | if (!phba->cfg_enable_hba_reset) |
f7a919b4 | 1007 | return -EACCES; |
13815c83 | 1008 | |
71157c9e JS |
1009 | if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) { |
1010 | status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE); | |
46fa311e | 1011 | |
71157c9e JS |
1012 | if (status != 0) |
1013 | return status; | |
1014 | } | |
46fa311e | 1015 | |
40496f07 | 1016 | init_completion(&online_compl); |
fedd3b7b | 1017 | rc = lpfc_workq_post_event(phba, &status, &online_compl, |
40496f07 | 1018 | LPFC_EVT_ONLINE); |
fedd3b7b JS |
1019 | if (rc == 0) |
1020 | return -ENOMEM; | |
1021 | ||
40496f07 JS |
1022 | wait_for_completion(&online_compl); |
1023 | ||
1024 | if (status != 0) | |
1025 | return -EIO; | |
1026 | ||
1027 | return 0; | |
1028 | } | |
1029 | ||
e59058c4 | 1030 | /** |
3621a710 | 1031 | * lpfc_issue_reset - Selectively resets an adapter |
e59058c4 JS |
1032 | * @dev: class device that is converted into a Scsi_host. |
1033 | * @attr: device attribute, not used. | |
1034 | * @buf: containing the string "selective". | |
1035 | * @count: unused variable. | |
1036 | * | |
1037 | * Description: | |
1038 | * If the buf contains the string "selective" then lpfc_selective_reset() | |
1039 | * is called to perform the reset. | |
1040 | * | |
1041 | * Notes: | |
1042 | * Assumes any error from lpfc_selective_reset() will be negative. | |
1043 | * If lpfc_selective_reset() returns zero then the length of the buffer | |
af901ca1 | 1044 | * is returned which indicates success |
e59058c4 JS |
1045 | * |
1046 | * Returns: | |
1047 | * -EINVAL if the buffer does not contain the string "selective" | |
1048 | * length of buf if lpfc-selective_reset() if the call succeeds | |
1049 | * return value of lpfc_selective_reset() if the call fails | |
1050 | **/ | |
40496f07 | 1051 | static ssize_t |
ee959b00 TJ |
1052 | lpfc_issue_reset(struct device *dev, struct device_attribute *attr, |
1053 | const char *buf, size_t count) | |
40496f07 | 1054 | { |
ee959b00 | 1055 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
1056 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1057 | struct lpfc_hba *phba = vport->phba; | |
40496f07 JS |
1058 | int status = -EINVAL; |
1059 | ||
73d91e50 JS |
1060 | if (!phba->cfg_enable_hba_reset) |
1061 | return -EACCES; | |
1062 | ||
40496f07 | 1063 | if (strncmp(buf, "selective", sizeof("selective") - 1) == 0) |
7f86059a | 1064 | status = phba->lpfc_selective_reset(phba); |
40496f07 JS |
1065 | |
1066 | if (status == 0) | |
1067 | return strlen(buf); | |
1068 | else | |
1069 | return status; | |
1070 | } | |
1071 | ||
88a2cfbb JS |
1072 | /** |
1073 | * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness | |
1074 | * @phba: lpfc_hba pointer. | |
1075 | * | |
1076 | * Description: | |
1077 | * SLI4 interface type-2 device to wait on the sliport status register for | |
1078 | * the readyness after performing a firmware reset. | |
1079 | * | |
1080 | * Returns: | |
0b1587b1 | 1081 | * zero for success, -EPERM when port does not have privilege to perform the |
026abb87 JS |
1082 | * reset, -EIO when port timeout from recovering from the reset. |
1083 | * | |
1084 | * Note: | |
1085 | * As the caller will interpret the return code by value, be careful in making | |
1086 | * change or addition to return codes. | |
88a2cfbb | 1087 | **/ |
73d91e50 | 1088 | int |
88a2cfbb JS |
1089 | lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba) |
1090 | { | |
f7a919b4 | 1091 | struct lpfc_register portstat_reg = {0}; |
88a2cfbb JS |
1092 | int i; |
1093 | ||
f7a919b4 | 1094 | msleep(100); |
88a2cfbb JS |
1095 | lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
1096 | &portstat_reg.word0); | |
1097 | ||
0b1587b1 | 1098 | /* verify if privileged for the request operation */ |
f7a919b4 JS |
1099 | if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) && |
1100 | !bf_get(lpfc_sliport_status_err, &portstat_reg)) | |
1101 | return -EPERM; | |
1102 | ||
88a2cfbb JS |
1103 | /* wait for the SLI port firmware ready after firmware reset */ |
1104 | for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) { | |
1105 | msleep(10); | |
1106 | lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, | |
1107 | &portstat_reg.word0); | |
1108 | if (!bf_get(lpfc_sliport_status_err, &portstat_reg)) | |
1109 | continue; | |
1110 | if (!bf_get(lpfc_sliport_status_rn, &portstat_reg)) | |
1111 | continue; | |
1112 | if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg)) | |
1113 | continue; | |
1114 | break; | |
1115 | } | |
1116 | ||
1117 | if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT) | |
1118 | return 0; | |
1119 | else | |
1120 | return -EIO; | |
1121 | } | |
1122 | ||
c0c11512 | 1123 | /** |
52d52440 | 1124 | * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc |
c0c11512 JS |
1125 | * @phba: lpfc_hba pointer. |
1126 | * | |
1127 | * Description: | |
52d52440 JS |
1128 | * Request SLI4 interface type-2 device to perform a physical register set |
1129 | * access. | |
c0c11512 JS |
1130 | * |
1131 | * Returns: | |
1132 | * zero for success | |
1133 | **/ | |
1134 | static ssize_t | |
52d52440 | 1135 | lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode) |
c0c11512 JS |
1136 | { |
1137 | struct completion online_compl; | |
b76f2dc9 | 1138 | struct pci_dev *pdev = phba->pcidev; |
026abb87 JS |
1139 | uint32_t before_fc_flag; |
1140 | uint32_t sriov_nr_virtfn; | |
c0c11512 | 1141 | uint32_t reg_val; |
026abb87 JS |
1142 | int status = 0, rc = 0; |
1143 | int job_posted = 1, sriov_err; | |
c0c11512 JS |
1144 | |
1145 | if (!phba->cfg_enable_hba_reset) | |
f7a919b4 | 1146 | return -EACCES; |
c0c11512 | 1147 | |
52d52440 JS |
1148 | if ((phba->sli_rev < LPFC_SLI_REV4) || |
1149 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != | |
1150 | LPFC_SLI_INTF_IF_TYPE_2)) | |
1151 | return -EPERM; | |
1152 | ||
026abb87 JS |
1153 | /* Keep state if we need to restore back */ |
1154 | before_fc_flag = phba->pport->fc_flag; | |
1155 | sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn; | |
1156 | ||
b76f2dc9 JS |
1157 | /* Disable SR-IOV virtual functions if enabled */ |
1158 | if (phba->cfg_sriov_nr_virtfn) { | |
1159 | pci_disable_sriov(pdev); | |
1160 | phba->cfg_sriov_nr_virtfn = 0; | |
1161 | } | |
229adb0e | 1162 | |
0293635e JS |
1163 | if (opcode == LPFC_FW_DUMP) |
1164 | phba->hba_flag |= HBA_FW_DUMP_OP; | |
1165 | ||
c0c11512 JS |
1166 | status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE); |
1167 | ||
0293635e JS |
1168 | if (status != 0) { |
1169 | phba->hba_flag &= ~HBA_FW_DUMP_OP; | |
c0c11512 | 1170 | return status; |
0293635e | 1171 | } |
c0c11512 JS |
1172 | |
1173 | /* wait for the device to be quiesced before firmware reset */ | |
1174 | msleep(100); | |
1175 | ||
1176 | reg_val = readl(phba->sli4_hba.conf_regs_memmap_p + | |
1177 | LPFC_CTL_PDEV_CTL_OFFSET); | |
52d52440 JS |
1178 | |
1179 | if (opcode == LPFC_FW_DUMP) | |
1180 | reg_val |= LPFC_FW_DUMP_REQUEST; | |
1181 | else if (opcode == LPFC_FW_RESET) | |
1182 | reg_val |= LPFC_CTL_PDEV_CTL_FRST; | |
1183 | else if (opcode == LPFC_DV_RESET) | |
1184 | reg_val |= LPFC_CTL_PDEV_CTL_DRST; | |
1185 | ||
c0c11512 JS |
1186 | writel(reg_val, phba->sli4_hba.conf_regs_memmap_p + |
1187 | LPFC_CTL_PDEV_CTL_OFFSET); | |
1188 | /* flush */ | |
1189 | readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET); | |
1190 | ||
1191 | /* delay driver action following IF_TYPE_2 reset */ | |
88a2cfbb JS |
1192 | rc = lpfc_sli4_pdev_status_reg_wait(phba); |
1193 | ||
026abb87 | 1194 | if (rc == -EPERM) { |
0b1587b1 | 1195 | /* no privilege for reset */ |
6b5151fd | 1196 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
0b1587b1 | 1197 | "3150 No privilege to perform the requested " |
6b5151fd | 1198 | "access: x%x\n", reg_val); |
026abb87 JS |
1199 | } else if (rc == -EIO) { |
1200 | /* reset failed, there is nothing more we can do */ | |
6b5151fd JS |
1201 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
1202 | "3153 Fail to perform the requested " | |
1203 | "access: x%x\n", reg_val); | |
f7a919b4 | 1204 | return rc; |
026abb87 JS |
1205 | } |
1206 | ||
1207 | /* keep the original port state */ | |
1208 | if (before_fc_flag & FC_OFFLINE_MODE) | |
1209 | goto out; | |
c0c11512 JS |
1210 | |
1211 | init_completion(&online_compl); | |
026abb87 JS |
1212 | job_posted = lpfc_workq_post_event(phba, &status, &online_compl, |
1213 | LPFC_EVT_ONLINE); | |
1214 | if (!job_posted) | |
1215 | goto out; | |
c0c11512 JS |
1216 | |
1217 | wait_for_completion(&online_compl); | |
1218 | ||
026abb87 JS |
1219 | out: |
1220 | /* in any case, restore the virtual functions enabled as before */ | |
1221 | if (sriov_nr_virtfn) { | |
1222 | sriov_err = | |
1223 | lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn); | |
1224 | if (!sriov_err) | |
1225 | phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn; | |
1226 | } | |
c0c11512 | 1227 | |
026abb87 JS |
1228 | /* return proper error code */ |
1229 | if (!rc) { | |
1230 | if (!job_posted) | |
1231 | rc = -ENOMEM; | |
1232 | else if (status) | |
1233 | rc = -EIO; | |
1234 | } | |
1235 | return rc; | |
c0c11512 JS |
1236 | } |
1237 | ||
e59058c4 | 1238 | /** |
3621a710 | 1239 | * lpfc_nport_evt_cnt_show - Return the number of nport events |
e59058c4 JS |
1240 | * @dev: class device that is converted into a Scsi_host. |
1241 | * @attr: device attribute, not used. | |
1242 | * @buf: on return contains the ascii number of nport events. | |
1243 | * | |
1244 | * Returns: size of formatted string. | |
1245 | **/ | |
dea3101e | 1246 | static ssize_t |
ee959b00 TJ |
1247 | lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr, |
1248 | char *buf) | |
dea3101e | 1249 | { |
ee959b00 | 1250 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
1251 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1252 | struct lpfc_hba *phba = vport->phba; | |
1253 | ||
dea3101e JB |
1254 | return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt); |
1255 | } | |
1256 | ||
e59058c4 | 1257 | /** |
3621a710 | 1258 | * lpfc_board_mode_show - Return the state of the board |
e59058c4 JS |
1259 | * @dev: class device that is converted into a Scsi_host. |
1260 | * @attr: device attribute, not used. | |
1261 | * @buf: on return contains the state of the adapter. | |
1262 | * | |
1263 | * Returns: size of formatted string. | |
1264 | **/ | |
41415862 | 1265 | static ssize_t |
ee959b00 TJ |
1266 | lpfc_board_mode_show(struct device *dev, struct device_attribute *attr, |
1267 | char *buf) | |
41415862 | 1268 | { |
ee959b00 | 1269 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
1270 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1271 | struct lpfc_hba *phba = vport->phba; | |
41415862 JW |
1272 | char * state; |
1273 | ||
2e0fef85 | 1274 | if (phba->link_state == LPFC_HBA_ERROR) |
41415862 | 1275 | state = "error"; |
2e0fef85 | 1276 | else if (phba->link_state == LPFC_WARM_START) |
41415862 | 1277 | state = "warm start"; |
2e0fef85 | 1278 | else if (phba->link_state == LPFC_INIT_START) |
41415862 JW |
1279 | state = "offline"; |
1280 | else | |
1281 | state = "online"; | |
1282 | ||
1283 | return snprintf(buf, PAGE_SIZE, "%s\n", state); | |
1284 | } | |
1285 | ||
e59058c4 | 1286 | /** |
3621a710 | 1287 | * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state |
e59058c4 JS |
1288 | * @dev: class device that is converted into a Scsi_host. |
1289 | * @attr: device attribute, not used. | |
1290 | * @buf: containing one of the strings "online", "offline", "warm" or "error". | |
1291 | * @count: unused variable. | |
1292 | * | |
1293 | * Returns: | |
1294 | * -EACCES if enable hba reset not enabled | |
1295 | * -EINVAL if the buffer does not contain a valid string (see above) | |
1296 | * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails | |
1297 | * buf length greater than zero indicates success | |
1298 | **/ | |
41415862 | 1299 | static ssize_t |
ee959b00 TJ |
1300 | lpfc_board_mode_store(struct device *dev, struct device_attribute *attr, |
1301 | const char *buf, size_t count) | |
41415862 | 1302 | { |
ee959b00 | 1303 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
1304 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1305 | struct lpfc_hba *phba = vport->phba; | |
41415862 | 1306 | struct completion online_compl; |
026abb87 JS |
1307 | char *board_mode_str = NULL; |
1308 | int status = 0; | |
fedd3b7b | 1309 | int rc; |
41415862 | 1310 | |
026abb87 JS |
1311 | if (!phba->cfg_enable_hba_reset) { |
1312 | status = -EACCES; | |
1313 | goto board_mode_out; | |
1314 | } | |
88a2cfbb JS |
1315 | |
1316 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, | |
026abb87 | 1317 | "3050 lpfc_board_mode set to %s\n", buf); |
88a2cfbb | 1318 | |
41415862 JW |
1319 | init_completion(&online_compl); |
1320 | ||
46fa311e | 1321 | if(strncmp(buf, "online", sizeof("online") - 1) == 0) { |
fedd3b7b | 1322 | rc = lpfc_workq_post_event(phba, &status, &online_compl, |
41415862 | 1323 | LPFC_EVT_ONLINE); |
026abb87 JS |
1324 | if (rc == 0) { |
1325 | status = -ENOMEM; | |
1326 | goto board_mode_out; | |
1327 | } | |
46fa311e JS |
1328 | wait_for_completion(&online_compl); |
1329 | } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0) | |
1330 | status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE); | |
41415862 | 1331 | else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0) |
6a9c52cf | 1332 | if (phba->sli_rev == LPFC_SLI_REV4) |
026abb87 | 1333 | status = -EINVAL; |
6a9c52cf JS |
1334 | else |
1335 | status = lpfc_do_offline(phba, LPFC_EVT_WARM_START); | |
46fa311e | 1336 | else if (strncmp(buf, "error", sizeof("error") - 1) == 0) |
6a9c52cf | 1337 | if (phba->sli_rev == LPFC_SLI_REV4) |
026abb87 | 1338 | status = -EINVAL; |
6a9c52cf JS |
1339 | else |
1340 | status = lpfc_do_offline(phba, LPFC_EVT_KILL); | |
c0c11512 | 1341 | else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0) |
52d52440 JS |
1342 | status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP); |
1343 | else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0) | |
1344 | status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET); | |
1345 | else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0) | |
1346 | status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET); | |
41415862 | 1347 | else |
026abb87 | 1348 | status = -EINVAL; |
41415862 | 1349 | |
026abb87 | 1350 | board_mode_out: |
41415862 JW |
1351 | if (!status) |
1352 | return strlen(buf); | |
026abb87 JS |
1353 | else { |
1354 | board_mode_str = strchr(buf, '\n'); | |
1355 | if (board_mode_str) | |
1356 | *board_mode_str = '\0'; | |
1357 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, | |
1358 | "3097 Failed \"%s\", status(%d), " | |
1359 | "fc_flag(x%x)\n", | |
1360 | buf, status, phba->pport->fc_flag); | |
f7a919b4 | 1361 | return status; |
026abb87 | 1362 | } |
41415862 JW |
1363 | } |
1364 | ||
e59058c4 | 1365 | /** |
3621a710 | 1366 | * lpfc_get_hba_info - Return various bits of informaton about the adapter |
e59058c4 | 1367 | * @phba: pointer to the adapter structure. |
3621a710 JS |
1368 | * @mxri: max xri count. |
1369 | * @axri: available xri count. | |
1370 | * @mrpi: max rpi count. | |
1371 | * @arpi: available rpi count. | |
1372 | * @mvpi: max vpi count. | |
1373 | * @avpi: available vpi count. | |
e59058c4 JS |
1374 | * |
1375 | * Description: | |
1376 | * If an integer pointer for an count is not null then the value for the | |
1377 | * count is returned. | |
1378 | * | |
1379 | * Returns: | |
1380 | * zero on error | |
1381 | * one for success | |
1382 | **/ | |
311464ec | 1383 | static int |
858c9f6c JS |
1384 | lpfc_get_hba_info(struct lpfc_hba *phba, |
1385 | uint32_t *mxri, uint32_t *axri, | |
1386 | uint32_t *mrpi, uint32_t *arpi, | |
1387 | uint32_t *mvpi, uint32_t *avpi) | |
92d7f7b0 | 1388 | { |
04c68496 | 1389 | struct lpfc_mbx_read_config *rd_config; |
92d7f7b0 JS |
1390 | LPFC_MBOXQ_t *pmboxq; |
1391 | MAILBOX_t *pmb; | |
1392 | int rc = 0; | |
15672319 | 1393 | uint32_t max_vpi; |
92d7f7b0 JS |
1394 | |
1395 | /* | |
1396 | * prevent udev from issuing mailbox commands until the port is | |
1397 | * configured. | |
1398 | */ | |
1399 | if (phba->link_state < LPFC_LINK_DOWN || | |
1400 | !phba->mbox_mem_pool || | |
f4b4c68f | 1401 | (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0) |
92d7f7b0 JS |
1402 | return 0; |
1403 | ||
1404 | if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) | |
1405 | return 0; | |
1406 | ||
1407 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
1408 | if (!pmboxq) | |
1409 | return 0; | |
1410 | memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t)); | |
1411 | ||
04c68496 | 1412 | pmb = &pmboxq->u.mb; |
92d7f7b0 JS |
1413 | pmb->mbxCommand = MBX_READ_CONFIG; |
1414 | pmb->mbxOwner = OWN_HOST; | |
1415 | pmboxq->context1 = NULL; | |
1416 | ||
75baf696 | 1417 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
92d7f7b0 JS |
1418 | rc = MBX_NOT_FINISHED; |
1419 | else | |
1420 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); | |
1421 | ||
1422 | if (rc != MBX_SUCCESS) { | |
858c9f6c | 1423 | if (rc != MBX_TIMEOUT) |
92d7f7b0 JS |
1424 | mempool_free(pmboxq, phba->mbox_mem_pool); |
1425 | return 0; | |
1426 | } | |
1427 | ||
da0436e9 JS |
1428 | if (phba->sli_rev == LPFC_SLI_REV4) { |
1429 | rd_config = &pmboxq->u.mqe.un.rd_config; | |
1430 | if (mrpi) | |
1431 | *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); | |
1432 | if (arpi) | |
1433 | *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) - | |
1434 | phba->sli4_hba.max_cfg_param.rpi_used; | |
1435 | if (mxri) | |
1436 | *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); | |
1437 | if (axri) | |
1438 | *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) - | |
1439 | phba->sli4_hba.max_cfg_param.xri_used; | |
15672319 JS |
1440 | |
1441 | /* Account for differences with SLI-3. Get vpi count from | |
1442 | * mailbox data and subtract one for max vpi value. | |
1443 | */ | |
1444 | max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ? | |
1445 | (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0; | |
1446 | ||
da0436e9 | 1447 | if (mvpi) |
15672319 | 1448 | *mvpi = max_vpi; |
da0436e9 | 1449 | if (avpi) |
15672319 | 1450 | *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used; |
da0436e9 JS |
1451 | } else { |
1452 | if (mrpi) | |
1453 | *mrpi = pmb->un.varRdConfig.max_rpi; | |
1454 | if (arpi) | |
1455 | *arpi = pmb->un.varRdConfig.avail_rpi; | |
1456 | if (mxri) | |
1457 | *mxri = pmb->un.varRdConfig.max_xri; | |
1458 | if (axri) | |
1459 | *axri = pmb->un.varRdConfig.avail_xri; | |
1460 | if (mvpi) | |
1461 | *mvpi = pmb->un.varRdConfig.max_vpi; | |
1462 | if (avpi) | |
1463 | *avpi = pmb->un.varRdConfig.avail_vpi; | |
1464 | } | |
92d7f7b0 JS |
1465 | |
1466 | mempool_free(pmboxq, phba->mbox_mem_pool); | |
1467 | return 1; | |
1468 | } | |
1469 | ||
e59058c4 | 1470 | /** |
3621a710 | 1471 | * lpfc_max_rpi_show - Return maximum rpi |
e59058c4 JS |
1472 | * @dev: class device that is converted into a Scsi_host. |
1473 | * @attr: device attribute, not used. | |
1474 | * @buf: on return contains the maximum rpi count in decimal or "Unknown". | |
1475 | * | |
1476 | * Description: | |
1477 | * Calls lpfc_get_hba_info() asking for just the mrpi count. | |
1478 | * If lpfc_get_hba_info() returns zero (failure) the buffer text is set | |
1479 | * to "Unknown" and the buffer length is returned, therefore the caller | |
1480 | * must check for "Unknown" in the buffer to detect a failure. | |
1481 | * | |
1482 | * Returns: size of formatted string. | |
1483 | **/ | |
92d7f7b0 | 1484 | static ssize_t |
ee959b00 TJ |
1485 | lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr, |
1486 | char *buf) | |
92d7f7b0 | 1487 | { |
ee959b00 | 1488 | struct Scsi_Host *shost = class_to_shost(dev); |
92d7f7b0 JS |
1489 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1490 | struct lpfc_hba *phba = vport->phba; | |
1491 | uint32_t cnt; | |
1492 | ||
858c9f6c | 1493 | if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL)) |
92d7f7b0 JS |
1494 | return snprintf(buf, PAGE_SIZE, "%d\n", cnt); |
1495 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); | |
1496 | } | |
1497 | ||
e59058c4 | 1498 | /** |
3621a710 | 1499 | * lpfc_used_rpi_show - Return maximum rpi minus available rpi |
e59058c4 JS |
1500 | * @dev: class device that is converted into a Scsi_host. |
1501 | * @attr: device attribute, not used. | |
1502 | * @buf: containing the used rpi count in decimal or "Unknown". | |
1503 | * | |
1504 | * Description: | |
1505 | * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts. | |
1506 | * If lpfc_get_hba_info() returns zero (failure) the buffer text is set | |
1507 | * to "Unknown" and the buffer length is returned, therefore the caller | |
1508 | * must check for "Unknown" in the buffer to detect a failure. | |
1509 | * | |
1510 | * Returns: size of formatted string. | |
1511 | **/ | |
92d7f7b0 | 1512 | static ssize_t |
ee959b00 TJ |
1513 | lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr, |
1514 | char *buf) | |
92d7f7b0 | 1515 | { |
ee959b00 | 1516 | struct Scsi_Host *shost = class_to_shost(dev); |
92d7f7b0 JS |
1517 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1518 | struct lpfc_hba *phba = vport->phba; | |
1519 | uint32_t cnt, acnt; | |
1520 | ||
858c9f6c | 1521 | if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL)) |
92d7f7b0 JS |
1522 | return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt)); |
1523 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); | |
1524 | } | |
1525 | ||
e59058c4 | 1526 | /** |
3621a710 | 1527 | * lpfc_max_xri_show - Return maximum xri |
e59058c4 JS |
1528 | * @dev: class device that is converted into a Scsi_host. |
1529 | * @attr: device attribute, not used. | |
1530 | * @buf: on return contains the maximum xri count in decimal or "Unknown". | |
1531 | * | |
1532 | * Description: | |
1533 | * Calls lpfc_get_hba_info() asking for just the mrpi count. | |
1534 | * If lpfc_get_hba_info() returns zero (failure) the buffer text is set | |
1535 | * to "Unknown" and the buffer length is returned, therefore the caller | |
1536 | * must check for "Unknown" in the buffer to detect a failure. | |
1537 | * | |
1538 | * Returns: size of formatted string. | |
1539 | **/ | |
92d7f7b0 | 1540 | static ssize_t |
ee959b00 TJ |
1541 | lpfc_max_xri_show(struct device *dev, struct device_attribute *attr, |
1542 | char *buf) | |
92d7f7b0 | 1543 | { |
ee959b00 | 1544 | struct Scsi_Host *shost = class_to_shost(dev); |
92d7f7b0 JS |
1545 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1546 | struct lpfc_hba *phba = vport->phba; | |
1547 | uint32_t cnt; | |
1548 | ||
858c9f6c | 1549 | if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL)) |
92d7f7b0 JS |
1550 | return snprintf(buf, PAGE_SIZE, "%d\n", cnt); |
1551 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); | |
1552 | } | |
1553 | ||
e59058c4 | 1554 | /** |
3621a710 | 1555 | * lpfc_used_xri_show - Return maximum xpi minus the available xpi |
e59058c4 JS |
1556 | * @dev: class device that is converted into a Scsi_host. |
1557 | * @attr: device attribute, not used. | |
1558 | * @buf: on return contains the used xri count in decimal or "Unknown". | |
1559 | * | |
1560 | * Description: | |
1561 | * Calls lpfc_get_hba_info() asking for just the mxri and axri counts. | |
1562 | * If lpfc_get_hba_info() returns zero (failure) the buffer text is set | |
1563 | * to "Unknown" and the buffer length is returned, therefore the caller | |
1564 | * must check for "Unknown" in the buffer to detect a failure. | |
1565 | * | |
1566 | * Returns: size of formatted string. | |
1567 | **/ | |
92d7f7b0 | 1568 | static ssize_t |
ee959b00 TJ |
1569 | lpfc_used_xri_show(struct device *dev, struct device_attribute *attr, |
1570 | char *buf) | |
92d7f7b0 | 1571 | { |
ee959b00 | 1572 | struct Scsi_Host *shost = class_to_shost(dev); |
92d7f7b0 JS |
1573 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1574 | struct lpfc_hba *phba = vport->phba; | |
1575 | uint32_t cnt, acnt; | |
1576 | ||
858c9f6c JS |
1577 | if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL)) |
1578 | return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt)); | |
1579 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); | |
1580 | } | |
1581 | ||
e59058c4 | 1582 | /** |
3621a710 | 1583 | * lpfc_max_vpi_show - Return maximum vpi |
e59058c4 JS |
1584 | * @dev: class device that is converted into a Scsi_host. |
1585 | * @attr: device attribute, not used. | |
1586 | * @buf: on return contains the maximum vpi count in decimal or "Unknown". | |
1587 | * | |
1588 | * Description: | |
1589 | * Calls lpfc_get_hba_info() asking for just the mvpi count. | |
1590 | * If lpfc_get_hba_info() returns zero (failure) the buffer text is set | |
1591 | * to "Unknown" and the buffer length is returned, therefore the caller | |
1592 | * must check for "Unknown" in the buffer to detect a failure. | |
1593 | * | |
1594 | * Returns: size of formatted string. | |
1595 | **/ | |
858c9f6c | 1596 | static ssize_t |
ee959b00 TJ |
1597 | lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr, |
1598 | char *buf) | |
858c9f6c | 1599 | { |
ee959b00 | 1600 | struct Scsi_Host *shost = class_to_shost(dev); |
858c9f6c JS |
1601 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1602 | struct lpfc_hba *phba = vport->phba; | |
1603 | uint32_t cnt; | |
1604 | ||
1605 | if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL)) | |
1606 | return snprintf(buf, PAGE_SIZE, "%d\n", cnt); | |
1607 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); | |
1608 | } | |
1609 | ||
e59058c4 | 1610 | /** |
3621a710 | 1611 | * lpfc_used_vpi_show - Return maximum vpi minus the available vpi |
e59058c4 JS |
1612 | * @dev: class device that is converted into a Scsi_host. |
1613 | * @attr: device attribute, not used. | |
1614 | * @buf: on return contains the used vpi count in decimal or "Unknown". | |
1615 | * | |
1616 | * Description: | |
1617 | * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts. | |
1618 | * If lpfc_get_hba_info() returns zero (failure) the buffer text is set | |
1619 | * to "Unknown" and the buffer length is returned, therefore the caller | |
1620 | * must check for "Unknown" in the buffer to detect a failure. | |
1621 | * | |
1622 | * Returns: size of formatted string. | |
1623 | **/ | |
858c9f6c | 1624 | static ssize_t |
ee959b00 TJ |
1625 | lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr, |
1626 | char *buf) | |
858c9f6c | 1627 | { |
ee959b00 | 1628 | struct Scsi_Host *shost = class_to_shost(dev); |
858c9f6c JS |
1629 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1630 | struct lpfc_hba *phba = vport->phba; | |
1631 | uint32_t cnt, acnt; | |
1632 | ||
1633 | if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt)) | |
92d7f7b0 JS |
1634 | return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt)); |
1635 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); | |
1636 | } | |
1637 | ||
e59058c4 | 1638 | /** |
3621a710 | 1639 | * lpfc_npiv_info_show - Return text about NPIV support for the adapter |
e59058c4 JS |
1640 | * @dev: class device that is converted into a Scsi_host. |
1641 | * @attr: device attribute, not used. | |
1642 | * @buf: text that must be interpreted to determine if npiv is supported. | |
1643 | * | |
1644 | * Description: | |
1645 | * Buffer will contain text indicating npiv is not suppoerted on the port, | |
1646 | * the port is an NPIV physical port, or it is an npiv virtual port with | |
1647 | * the id of the vport. | |
1648 | * | |
1649 | * Returns: size of formatted string. | |
1650 | **/ | |
92d7f7b0 | 1651 | static ssize_t |
ee959b00 TJ |
1652 | lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr, |
1653 | char *buf) | |
92d7f7b0 | 1654 | { |
ee959b00 | 1655 | struct Scsi_Host *shost = class_to_shost(dev); |
92d7f7b0 JS |
1656 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1657 | struct lpfc_hba *phba = vport->phba; | |
1658 | ||
1659 | if (!(phba->max_vpi)) | |
1660 | return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n"); | |
1661 | if (vport->port_type == LPFC_PHYSICAL_PORT) | |
1662 | return snprintf(buf, PAGE_SIZE, "NPIV Physical\n"); | |
1663 | return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi); | |
1664 | } | |
1665 | ||
e59058c4 | 1666 | /** |
3621a710 | 1667 | * lpfc_poll_show - Return text about poll support for the adapter |
e59058c4 JS |
1668 | * @dev: class device that is converted into a Scsi_host. |
1669 | * @attr: device attribute, not used. | |
1670 | * @buf: on return contains the cfg_poll in hex. | |
1671 | * | |
1672 | * Notes: | |
1673 | * cfg_poll should be a lpfc_polling_flags type. | |
1674 | * | |
1675 | * Returns: size of formatted string. | |
1676 | **/ | |
875fbdfe | 1677 | static ssize_t |
ee959b00 TJ |
1678 | lpfc_poll_show(struct device *dev, struct device_attribute *attr, |
1679 | char *buf) | |
875fbdfe | 1680 | { |
ee959b00 | 1681 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
1682 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1683 | struct lpfc_hba *phba = vport->phba; | |
875fbdfe JSEC |
1684 | |
1685 | return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll); | |
1686 | } | |
1687 | ||
e59058c4 | 1688 | /** |
3621a710 | 1689 | * lpfc_poll_store - Set the value of cfg_poll for the adapter |
e59058c4 JS |
1690 | * @dev: class device that is converted into a Scsi_host. |
1691 | * @attr: device attribute, not used. | |
1692 | * @buf: one or more lpfc_polling_flags values. | |
1693 | * @count: not used. | |
1694 | * | |
1695 | * Notes: | |
1696 | * buf contents converted to integer and checked for a valid value. | |
1697 | * | |
1698 | * Returns: | |
1699 | * -EINVAL if the buffer connot be converted or is out of range | |
1700 | * length of the buf on success | |
1701 | **/ | |
875fbdfe | 1702 | static ssize_t |
ee959b00 TJ |
1703 | lpfc_poll_store(struct device *dev, struct device_attribute *attr, |
1704 | const char *buf, size_t count) | |
875fbdfe | 1705 | { |
ee959b00 | 1706 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
1707 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1708 | struct lpfc_hba *phba = vport->phba; | |
875fbdfe JSEC |
1709 | uint32_t creg_val; |
1710 | uint32_t old_val; | |
1711 | int val=0; | |
1712 | ||
1713 | if (!isdigit(buf[0])) | |
1714 | return -EINVAL; | |
1715 | ||
1716 | if (sscanf(buf, "%i", &val) != 1) | |
1717 | return -EINVAL; | |
1718 | ||
1719 | if ((val & 0x3) != val) | |
1720 | return -EINVAL; | |
1721 | ||
45ed1190 JS |
1722 | if (phba->sli_rev == LPFC_SLI_REV4) |
1723 | val = 0; | |
1724 | ||
88a2cfbb JS |
1725 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
1726 | "3051 lpfc_poll changed from %d to %d\n", | |
1727 | phba->cfg_poll, val); | |
1728 | ||
2e0fef85 | 1729 | spin_lock_irq(&phba->hbalock); |
875fbdfe JSEC |
1730 | |
1731 | old_val = phba->cfg_poll; | |
1732 | ||
1733 | if (val & ENABLE_FCP_RING_POLLING) { | |
1734 | if ((val & DISABLE_FCP_RING_INT) && | |
1735 | !(old_val & DISABLE_FCP_RING_INT)) { | |
9940b97b JS |
1736 | if (lpfc_readl(phba->HCregaddr, &creg_val)) { |
1737 | spin_unlock_irq(&phba->hbalock); | |
1738 | return -EINVAL; | |
1739 | } | |
875fbdfe JSEC |
1740 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
1741 | writel(creg_val, phba->HCregaddr); | |
1742 | readl(phba->HCregaddr); /* flush */ | |
1743 | ||
1744 | lpfc_poll_start_timer(phba); | |
1745 | } | |
1746 | } else if (val != 0x0) { | |
2e0fef85 | 1747 | spin_unlock_irq(&phba->hbalock); |
875fbdfe JSEC |
1748 | return -EINVAL; |
1749 | } | |
1750 | ||
1751 | if (!(val & DISABLE_FCP_RING_INT) && | |
1752 | (old_val & DISABLE_FCP_RING_INT)) | |
1753 | { | |
2e0fef85 | 1754 | spin_unlock_irq(&phba->hbalock); |
875fbdfe | 1755 | del_timer(&phba->fcp_poll_timer); |
2e0fef85 | 1756 | spin_lock_irq(&phba->hbalock); |
9940b97b JS |
1757 | if (lpfc_readl(phba->HCregaddr, &creg_val)) { |
1758 | spin_unlock_irq(&phba->hbalock); | |
1759 | return -EINVAL; | |
1760 | } | |
875fbdfe JSEC |
1761 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
1762 | writel(creg_val, phba->HCregaddr); | |
1763 | readl(phba->HCregaddr); /* flush */ | |
1764 | } | |
1765 | ||
1766 | phba->cfg_poll = val; | |
1767 | ||
2e0fef85 | 1768 | spin_unlock_irq(&phba->hbalock); |
875fbdfe JSEC |
1769 | |
1770 | return strlen(buf); | |
1771 | } | |
dea3101e | 1772 | |
bc73905a JS |
1773 | /** |
1774 | * lpfc_fips_level_show - Return the current FIPS level for the HBA | |
1775 | * @dev: class unused variable. | |
1776 | * @attr: device attribute, not used. | |
1777 | * @buf: on return contains the module description text. | |
1778 | * | |
1779 | * Returns: size of formatted string. | |
1780 | **/ | |
1781 | static ssize_t | |
1782 | lpfc_fips_level_show(struct device *dev, struct device_attribute *attr, | |
1783 | char *buf) | |
1784 | { | |
1785 | struct Scsi_Host *shost = class_to_shost(dev); | |
1786 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
1787 | struct lpfc_hba *phba = vport->phba; | |
1788 | ||
1789 | return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level); | |
1790 | } | |
1791 | ||
1792 | /** | |
1793 | * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA | |
1794 | * @dev: class unused variable. | |
1795 | * @attr: device attribute, not used. | |
1796 | * @buf: on return contains the module description text. | |
1797 | * | |
1798 | * Returns: size of formatted string. | |
1799 | **/ | |
1800 | static ssize_t | |
1801 | lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr, | |
1802 | char *buf) | |
1803 | { | |
1804 | struct Scsi_Host *shost = class_to_shost(dev); | |
1805 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
1806 | struct lpfc_hba *phba = vport->phba; | |
1807 | ||
1808 | return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev); | |
1809 | } | |
1810 | ||
ab56dc2e JS |
1811 | /** |
1812 | * lpfc_dss_show - Return the current state of dss and the configured state | |
1813 | * @dev: class converted to a Scsi_host structure. | |
1814 | * @attr: device attribute, not used. | |
1815 | * @buf: on return contains the formatted text. | |
1816 | * | |
1817 | * Returns: size of formatted string. | |
1818 | **/ | |
1819 | static ssize_t | |
1820 | lpfc_dss_show(struct device *dev, struct device_attribute *attr, | |
1821 | char *buf) | |
1822 | { | |
1823 | struct Scsi_Host *shost = class_to_shost(dev); | |
1824 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
1825 | struct lpfc_hba *phba = vport->phba; | |
1826 | ||
1827 | return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n", | |
1828 | (phba->cfg_enable_dss) ? "Enabled" : "Disabled", | |
1829 | (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ? | |
1830 | "" : "Not "); | |
1831 | } | |
1832 | ||
912e3acd JS |
1833 | /** |
1834 | * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions | |
1835 | * @dev: class converted to a Scsi_host structure. | |
1836 | * @attr: device attribute, not used. | |
1837 | * @buf: on return contains the formatted support level. | |
1838 | * | |
1839 | * Description: | |
1840 | * Returns the maximum number of virtual functions a physical function can | |
1841 | * support, 0 will be returned if called on virtual function. | |
1842 | * | |
1843 | * Returns: size of formatted string. | |
1844 | **/ | |
1845 | static ssize_t | |
1846 | lpfc_sriov_hw_max_virtfn_show(struct device *dev, | |
1847 | struct device_attribute *attr, | |
1848 | char *buf) | |
1849 | { | |
1850 | struct Scsi_Host *shost = class_to_shost(dev); | |
1851 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
1852 | struct lpfc_hba *phba = vport->phba; | |
0a96e975 | 1853 | uint16_t max_nr_virtfn; |
912e3acd | 1854 | |
0a96e975 JS |
1855 | max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba); |
1856 | return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn); | |
912e3acd JS |
1857 | } |
1858 | ||
de8c36bb AB |
1859 | static inline bool lpfc_rangecheck(uint val, uint min, uint max) |
1860 | { | |
1861 | return val >= min && val <= max; | |
1862 | } | |
1863 | ||
e59058c4 | 1864 | /** |
3621a710 | 1865 | * lpfc_param_show - Return a cfg attribute value in decimal |
e59058c4 JS |
1866 | * |
1867 | * Description: | |
1868 | * Macro that given an attr e.g. hba_queue_depth expands | |
1869 | * into a function with the name lpfc_hba_queue_depth_show. | |
1870 | * | |
1871 | * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field. | |
1872 | * @dev: class device that is converted into a Scsi_host. | |
1873 | * @attr: device attribute, not used. | |
1874 | * @buf: on return contains the attribute value in decimal. | |
1875 | * | |
1876 | * Returns: size of formatted string. | |
1877 | **/ | |
dea3101e JB |
1878 | #define lpfc_param_show(attr) \ |
1879 | static ssize_t \ | |
ee959b00 TJ |
1880 | lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \ |
1881 | char *buf) \ | |
dea3101e | 1882 | { \ |
ee959b00 | 1883 | struct Scsi_Host *shost = class_to_shost(dev);\ |
2e0fef85 JS |
1884 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ |
1885 | struct lpfc_hba *phba = vport->phba;\ | |
7bcbb752 JSEC |
1886 | return snprintf(buf, PAGE_SIZE, "%d\n",\ |
1887 | phba->cfg_##attr);\ | |
1888 | } | |
1889 | ||
e59058c4 | 1890 | /** |
3621a710 | 1891 | * lpfc_param_hex_show - Return a cfg attribute value in hex |
e59058c4 JS |
1892 | * |
1893 | * Description: | |
1894 | * Macro that given an attr e.g. hba_queue_depth expands | |
1895 | * into a function with the name lpfc_hba_queue_depth_show | |
1896 | * | |
1897 | * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field. | |
1898 | * @dev: class device that is converted into a Scsi_host. | |
1899 | * @attr: device attribute, not used. | |
3621a710 | 1900 | * @buf: on return contains the attribute value in hexadecimal. |
e59058c4 JS |
1901 | * |
1902 | * Returns: size of formatted string. | |
1903 | **/ | |
93a20f74 JSEC |
1904 | #define lpfc_param_hex_show(attr) \ |
1905 | static ssize_t \ | |
ee959b00 TJ |
1906 | lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \ |
1907 | char *buf) \ | |
93a20f74 | 1908 | { \ |
ee959b00 | 1909 | struct Scsi_Host *shost = class_to_shost(dev);\ |
2e0fef85 JS |
1910 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ |
1911 | struct lpfc_hba *phba = vport->phba;\ | |
84d1b006 | 1912 | uint val = 0;\ |
93a20f74 JSEC |
1913 | val = phba->cfg_##attr;\ |
1914 | return snprintf(buf, PAGE_SIZE, "%#x\n",\ | |
1915 | phba->cfg_##attr);\ | |
1916 | } | |
1917 | ||
e59058c4 | 1918 | /** |
b595076a | 1919 | * lpfc_param_init - Initializes a cfg attribute |
e59058c4 JS |
1920 | * |
1921 | * Description: | |
1922 | * Macro that given an attr e.g. hba_queue_depth expands | |
1923 | * into a function with the name lpfc_hba_queue_depth_init. The macro also | |
1924 | * takes a default argument, a minimum and maximum argument. | |
1925 | * | |
1926 | * lpfc_##attr##_init: Initializes an attribute. | |
1927 | * @phba: pointer the the adapter structure. | |
1928 | * @val: integer attribute value. | |
1929 | * | |
1930 | * Validates the min and max values then sets the adapter config field | |
1931 | * accordingly, or uses the default if out of range and prints an error message. | |
1932 | * | |
1933 | * Returns: | |
1934 | * zero on success | |
1935 | * -EINVAL if default used | |
1936 | **/ | |
7bcbb752 JSEC |
1937 | #define lpfc_param_init(attr, default, minval, maxval) \ |
1938 | static int \ | |
84d1b006 | 1939 | lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \ |
7bcbb752 | 1940 | { \ |
de8c36bb | 1941 | if (lpfc_rangecheck(val, minval, maxval)) {\ |
7bcbb752 JSEC |
1942 | phba->cfg_##attr = val;\ |
1943 | return 0;\ | |
dea3101e | 1944 | }\ |
7bcbb752 | 1945 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \ |
e8b62011 JS |
1946 | "0449 lpfc_"#attr" attribute cannot be set to %d, "\ |
1947 | "allowed range is ["#minval", "#maxval"]\n", val); \ | |
7bcbb752 JSEC |
1948 | phba->cfg_##attr = default;\ |
1949 | return -EINVAL;\ | |
dea3101e JB |
1950 | } |
1951 | ||
e59058c4 | 1952 | /** |
3621a710 | 1953 | * lpfc_param_set - Set a cfg attribute value |
e59058c4 JS |
1954 | * |
1955 | * Description: | |
1956 | * Macro that given an attr e.g. hba_queue_depth expands | |
1957 | * into a function with the name lpfc_hba_queue_depth_set | |
1958 | * | |
1959 | * lpfc_##attr##_set: Sets an attribute value. | |
1960 | * @phba: pointer the the adapter structure. | |
1961 | * @val: integer attribute value. | |
1962 | * | |
1963 | * Description: | |
1964 | * Validates the min and max values then sets the | |
1965 | * adapter config field if in the valid range. prints error message | |
1966 | * and does not set the parameter if invalid. | |
1967 | * | |
1968 | * Returns: | |
1969 | * zero on success | |
1970 | * -EINVAL if val is invalid | |
1971 | **/ | |
7bcbb752 JSEC |
1972 | #define lpfc_param_set(attr, default, minval, maxval) \ |
1973 | static int \ | |
84d1b006 | 1974 | lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \ |
7bcbb752 | 1975 | { \ |
de8c36bb | 1976 | if (lpfc_rangecheck(val, minval, maxval)) {\ |
88a2cfbb JS |
1977 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \ |
1978 | "3052 lpfc_" #attr " changed from %d to %d\n", \ | |
1979 | phba->cfg_##attr, val); \ | |
7bcbb752 JSEC |
1980 | phba->cfg_##attr = val;\ |
1981 | return 0;\ | |
1982 | }\ | |
1983 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \ | |
e8b62011 JS |
1984 | "0450 lpfc_"#attr" attribute cannot be set to %d, "\ |
1985 | "allowed range is ["#minval", "#maxval"]\n", val); \ | |
7bcbb752 JSEC |
1986 | return -EINVAL;\ |
1987 | } | |
1988 | ||
e59058c4 | 1989 | /** |
3621a710 | 1990 | * lpfc_param_store - Set a vport attribute value |
e59058c4 JS |
1991 | * |
1992 | * Description: | |
1993 | * Macro that given an attr e.g. hba_queue_depth expands | |
1994 | * into a function with the name lpfc_hba_queue_depth_store. | |
1995 | * | |
1996 | * lpfc_##attr##_store: Set an sttribute value. | |
1997 | * @dev: class device that is converted into a Scsi_host. | |
1998 | * @attr: device attribute, not used. | |
1999 | * @buf: contains the attribute value in ascii. | |
2000 | * @count: not used. | |
2001 | * | |
2002 | * Description: | |
2003 | * Convert the ascii text number to an integer, then | |
2004 | * use the lpfc_##attr##_set function to set the value. | |
2005 | * | |
2006 | * Returns: | |
2007 | * -EINVAL if val is invalid or lpfc_##attr##_set() fails | |
2008 | * length of buffer upon success. | |
2009 | **/ | |
7bcbb752 | 2010 | #define lpfc_param_store(attr) \ |
dea3101e | 2011 | static ssize_t \ |
ee959b00 TJ |
2012 | lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \ |
2013 | const char *buf, size_t count) \ | |
dea3101e | 2014 | { \ |
ee959b00 | 2015 | struct Scsi_Host *shost = class_to_shost(dev);\ |
2e0fef85 JS |
2016 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ |
2017 | struct lpfc_hba *phba = vport->phba;\ | |
84d1b006 | 2018 | uint val = 0;\ |
93a20f74 JSEC |
2019 | if (!isdigit(buf[0]))\ |
2020 | return -EINVAL;\ | |
2021 | if (sscanf(buf, "%i", &val) != 1)\ | |
2022 | return -EINVAL;\ | |
7bcbb752 | 2023 | if (lpfc_##attr##_set(phba, val) == 0) \ |
755c0d06 | 2024 | return strlen(buf);\ |
7bcbb752 JSEC |
2025 | else \ |
2026 | return -EINVAL;\ | |
dea3101e JB |
2027 | } |
2028 | ||
e59058c4 | 2029 | /** |
3621a710 | 2030 | * lpfc_vport_param_show - Return decimal formatted cfg attribute value |
e59058c4 JS |
2031 | * |
2032 | * Description: | |
2033 | * Macro that given an attr e.g. hba_queue_depth expands | |
2034 | * into a function with the name lpfc_hba_queue_depth_show | |
2035 | * | |
2036 | * lpfc_##attr##_show: prints the attribute value in decimal. | |
2037 | * @dev: class device that is converted into a Scsi_host. | |
2038 | * @attr: device attribute, not used. | |
2039 | * @buf: on return contains the attribute value in decimal. | |
2040 | * | |
2041 | * Returns: length of formatted string. | |
2042 | **/ | |
3de2a653 JS |
2043 | #define lpfc_vport_param_show(attr) \ |
2044 | static ssize_t \ | |
ee959b00 TJ |
2045 | lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \ |
2046 | char *buf) \ | |
3de2a653 | 2047 | { \ |
ee959b00 | 2048 | struct Scsi_Host *shost = class_to_shost(dev);\ |
3de2a653 | 2049 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ |
3de2a653 JS |
2050 | return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\ |
2051 | } | |
2052 | ||
e59058c4 | 2053 | /** |
3621a710 | 2054 | * lpfc_vport_param_hex_show - Return hex formatted attribute value |
e59058c4 JS |
2055 | * |
2056 | * Description: | |
2057 | * Macro that given an attr e.g. | |
2058 | * hba_queue_depth expands into a function with the name | |
2059 | * lpfc_hba_queue_depth_show | |
2060 | * | |
3621a710 | 2061 | * lpfc_##attr##_show: prints the attribute value in hexadecimal. |
e59058c4 JS |
2062 | * @dev: class device that is converted into a Scsi_host. |
2063 | * @attr: device attribute, not used. | |
3621a710 | 2064 | * @buf: on return contains the attribute value in hexadecimal. |
e59058c4 JS |
2065 | * |
2066 | * Returns: length of formatted string. | |
2067 | **/ | |
3de2a653 JS |
2068 | #define lpfc_vport_param_hex_show(attr) \ |
2069 | static ssize_t \ | |
ee959b00 TJ |
2070 | lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \ |
2071 | char *buf) \ | |
3de2a653 | 2072 | { \ |
ee959b00 | 2073 | struct Scsi_Host *shost = class_to_shost(dev);\ |
3de2a653 | 2074 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ |
3de2a653 JS |
2075 | return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\ |
2076 | } | |
2077 | ||
e59058c4 | 2078 | /** |
3621a710 | 2079 | * lpfc_vport_param_init - Initialize a vport cfg attribute |
e59058c4 JS |
2080 | * |
2081 | * Description: | |
2082 | * Macro that given an attr e.g. hba_queue_depth expands | |
2083 | * into a function with the name lpfc_hba_queue_depth_init. The macro also | |
2084 | * takes a default argument, a minimum and maximum argument. | |
2085 | * | |
2086 | * lpfc_##attr##_init: validates the min and max values then sets the | |
2087 | * adapter config field accordingly, or uses the default if out of range | |
2088 | * and prints an error message. | |
2089 | * @phba: pointer the the adapter structure. | |
2090 | * @val: integer attribute value. | |
2091 | * | |
2092 | * Returns: | |
2093 | * zero on success | |
2094 | * -EINVAL if default used | |
2095 | **/ | |
3de2a653 JS |
2096 | #define lpfc_vport_param_init(attr, default, minval, maxval) \ |
2097 | static int \ | |
84d1b006 | 2098 | lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \ |
3de2a653 | 2099 | { \ |
de8c36bb | 2100 | if (lpfc_rangecheck(val, minval, maxval)) {\ |
3de2a653 JS |
2101 | vport->cfg_##attr = val;\ |
2102 | return 0;\ | |
2103 | }\ | |
e8b62011 | 2104 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \ |
d7c255b2 | 2105 | "0423 lpfc_"#attr" attribute cannot be set to %d, "\ |
e8b62011 | 2106 | "allowed range is ["#minval", "#maxval"]\n", val); \ |
3de2a653 JS |
2107 | vport->cfg_##attr = default;\ |
2108 | return -EINVAL;\ | |
2109 | } | |
2110 | ||
e59058c4 | 2111 | /** |
3621a710 | 2112 | * lpfc_vport_param_set - Set a vport cfg attribute |
e59058c4 JS |
2113 | * |
2114 | * Description: | |
2115 | * Macro that given an attr e.g. hba_queue_depth expands | |
2116 | * into a function with the name lpfc_hba_queue_depth_set | |
2117 | * | |
2118 | * lpfc_##attr##_set: validates the min and max values then sets the | |
2119 | * adapter config field if in the valid range. prints error message | |
2120 | * and does not set the parameter if invalid. | |
2121 | * @phba: pointer the the adapter structure. | |
2122 | * @val: integer attribute value. | |
2123 | * | |
2124 | * Returns: | |
2125 | * zero on success | |
2126 | * -EINVAL if val is invalid | |
2127 | **/ | |
3de2a653 JS |
2128 | #define lpfc_vport_param_set(attr, default, minval, maxval) \ |
2129 | static int \ | |
84d1b006 | 2130 | lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \ |
3de2a653 | 2131 | { \ |
de8c36bb | 2132 | if (lpfc_rangecheck(val, minval, maxval)) {\ |
88a2cfbb | 2133 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \ |
14660f4f JS |
2134 | "3053 lpfc_" #attr \ |
2135 | " changed from %d (x%x) to %d (x%x)\n", \ | |
2136 | vport->cfg_##attr, vport->cfg_##attr, \ | |
2137 | val, val); \ | |
3de2a653 JS |
2138 | vport->cfg_##attr = val;\ |
2139 | return 0;\ | |
2140 | }\ | |
e8b62011 | 2141 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \ |
d7c255b2 | 2142 | "0424 lpfc_"#attr" attribute cannot be set to %d, "\ |
e8b62011 | 2143 | "allowed range is ["#minval", "#maxval"]\n", val); \ |
3de2a653 JS |
2144 | return -EINVAL;\ |
2145 | } | |
2146 | ||
e59058c4 | 2147 | /** |
3621a710 | 2148 | * lpfc_vport_param_store - Set a vport attribute |
e59058c4 JS |
2149 | * |
2150 | * Description: | |
2151 | * Macro that given an attr e.g. hba_queue_depth | |
2152 | * expands into a function with the name lpfc_hba_queue_depth_store | |
2153 | * | |
2154 | * lpfc_##attr##_store: convert the ascii text number to an integer, then | |
2155 | * use the lpfc_##attr##_set function to set the value. | |
2156 | * @cdev: class device that is converted into a Scsi_host. | |
2157 | * @buf: contains the attribute value in decimal. | |
2158 | * @count: not used. | |
2159 | * | |
2160 | * Returns: | |
2161 | * -EINVAL if val is invalid or lpfc_##attr##_set() fails | |
2162 | * length of buffer upon success. | |
2163 | **/ | |
3de2a653 JS |
2164 | #define lpfc_vport_param_store(attr) \ |
2165 | static ssize_t \ | |
ee959b00 TJ |
2166 | lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \ |
2167 | const char *buf, size_t count) \ | |
3de2a653 | 2168 | { \ |
ee959b00 | 2169 | struct Scsi_Host *shost = class_to_shost(dev);\ |
3de2a653 | 2170 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ |
84d1b006 | 2171 | uint val = 0;\ |
3de2a653 JS |
2172 | if (!isdigit(buf[0]))\ |
2173 | return -EINVAL;\ | |
2174 | if (sscanf(buf, "%i", &val) != 1)\ | |
2175 | return -EINVAL;\ | |
2176 | if (lpfc_##attr##_set(vport, val) == 0) \ | |
2177 | return strlen(buf);\ | |
2178 | else \ | |
2179 | return -EINVAL;\ | |
2180 | } | |
2181 | ||
2182 | ||
895427bd | 2183 | static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL); |
81301a9b JS |
2184 | static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL); |
2185 | static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL); | |
2186 | static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL); | |
2187 | static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL); | |
ee959b00 TJ |
2188 | static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL); |
2189 | static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL); | |
2190 | static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL); | |
2191 | static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL); | |
2192 | static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL); | |
2193 | static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL); | |
2194 | static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL); | |
2195 | static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL); | |
84d1b006 JS |
2196 | static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show, |
2197 | lpfc_link_state_store); | |
ee959b00 TJ |
2198 | static DEVICE_ATTR(option_rom_version, S_IRUGO, |
2199 | lpfc_option_rom_version_show, NULL); | |
2200 | static DEVICE_ATTR(num_discovered_ports, S_IRUGO, | |
2201 | lpfc_num_discovered_ports_show, NULL); | |
84774a4d | 2202 | static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL); |
ee959b00 TJ |
2203 | static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL); |
2204 | static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL); | |
45ed1190 | 2205 | static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL); |
ee959b00 TJ |
2206 | static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR, |
2207 | lpfc_board_mode_show, lpfc_board_mode_store); | |
2208 | static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset); | |
2209 | static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL); | |
2210 | static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL); | |
2211 | static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL); | |
2212 | static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL); | |
2213 | static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL); | |
2214 | static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL); | |
2215 | static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL); | |
2216 | static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL); | |
bc73905a JS |
2217 | static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL); |
2218 | static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL); | |
ab56dc2e | 2219 | static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL); |
912e3acd JS |
2220 | static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO, |
2221 | lpfc_sriov_hw_max_virtfn_show, NULL); | |
026abb87 | 2222 | static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL); |
1ba981fd JS |
2223 | static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show, |
2224 | NULL); | |
c3f28afa | 2225 | |
352e5fd1 | 2226 | static char *lpfc_soft_wwn_key = "C99G71SL8032A"; |
1ba981fd JS |
2227 | #define WWN_SZ 8 |
2228 | /** | |
2229 | * lpfc_wwn_set - Convert string to the 8 byte WWN value. | |
2230 | * @buf: WWN string. | |
2231 | * @cnt: Length of string. | |
2232 | * @wwn: Array to receive converted wwn value. | |
2233 | * | |
2234 | * Returns: | |
2235 | * -EINVAL if the buffer does not contain a valid wwn | |
2236 | * 0 success | |
2237 | **/ | |
2238 | static size_t | |
2239 | lpfc_wwn_set(const char *buf, size_t cnt, char wwn[]) | |
2240 | { | |
2241 | unsigned int i, j; | |
2242 | ||
2243 | /* Count may include a LF at end of string */ | |
2244 | if (buf[cnt-1] == '\n') | |
2245 | cnt--; | |
c3f28afa | 2246 | |
1ba981fd JS |
2247 | if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) || |
2248 | ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x')))) | |
2249 | return -EINVAL; | |
2250 | ||
2251 | memset(wwn, 0, WWN_SZ); | |
2252 | ||
2253 | /* Validate and store the new name */ | |
2254 | for (i = 0, j = 0; i < 16; i++) { | |
2255 | if ((*buf >= 'a') && (*buf <= 'f')) | |
2256 | j = ((j << 4) | ((*buf++ - 'a') + 10)); | |
2257 | else if ((*buf >= 'A') && (*buf <= 'F')) | |
2258 | j = ((j << 4) | ((*buf++ - 'A') + 10)); | |
2259 | else if ((*buf >= '0') && (*buf <= '9')) | |
2260 | j = ((j << 4) | (*buf++ - '0')); | |
2261 | else | |
2262 | return -EINVAL; | |
2263 | if (i % 2) { | |
2264 | wwn[i/2] = j & 0xff; | |
2265 | j = 0; | |
2266 | } | |
2267 | } | |
2268 | return 0; | |
2269 | } | |
352e5fd1 JS |
2270 | /** |
2271 | * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid | |
2272 | * @dev: class device that is converted into a Scsi_host. | |
2273 | * @attr: device attribute, not used. | |
2274 | * @buf: containing the string lpfc_soft_wwn_key. | |
2275 | * @count: must be size of lpfc_soft_wwn_key. | |
2276 | * | |
2277 | * Returns: | |
2278 | * -EINVAL if the buffer does not contain lpfc_soft_wwn_key | |
2279 | * length of buf indicates success | |
2280 | **/ | |
2281 | static ssize_t | |
2282 | lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr, | |
2283 | const char *buf, size_t count) | |
2284 | { | |
2285 | struct Scsi_Host *shost = class_to_shost(dev); | |
2286 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
2287 | struct lpfc_hba *phba = vport->phba; | |
2288 | unsigned int cnt = count; | |
2289 | ||
2290 | /* | |
2291 | * We're doing a simple sanity check for soft_wwpn setting. | |
2292 | * We require that the user write a specific key to enable | |
2293 | * the soft_wwpn attribute to be settable. Once the attribute | |
2294 | * is written, the enable key resets. If further updates are | |
2295 | * desired, the key must be written again to re-enable the | |
2296 | * attribute. | |
2297 | * | |
2298 | * The "key" is not secret - it is a hardcoded string shown | |
2299 | * here. The intent is to protect against the random user or | |
2300 | * application that is just writing attributes. | |
2301 | */ | |
2302 | ||
2303 | /* count may include a LF at end of string */ | |
2304 | if (buf[cnt-1] == '\n') | |
2305 | cnt--; | |
2306 | ||
2307 | if ((cnt != strlen(lpfc_soft_wwn_key)) || | |
2308 | (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0)) | |
2309 | return -EINVAL; | |
2310 | ||
2311 | phba->soft_wwn_enable = 1; | |
2312 | ||
2313 | dev_printk(KERN_WARNING, &phba->pcidev->dev, | |
2314 | "lpfc%d: soft_wwpn assignment has been enabled.\n", | |
2315 | phba->brd_no); | |
2316 | dev_printk(KERN_WARNING, &phba->pcidev->dev, | |
2317 | " The soft_wwpn feature is not supported by Broadcom."); | |
2318 | ||
2319 | return count; | |
2320 | } | |
2321 | static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL, | |
2322 | lpfc_soft_wwn_enable_store); | |
2323 | ||
2324 | /** | |
2325 | * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter | |
2326 | * @dev: class device that is converted into a Scsi_host. | |
2327 | * @attr: device attribute, not used. | |
2328 | * @buf: on return contains the wwpn in hexadecimal. | |
2329 | * | |
2330 | * Returns: size of formatted string. | |
2331 | **/ | |
2332 | static ssize_t | |
2333 | lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr, | |
2334 | char *buf) | |
2335 | { | |
2336 | struct Scsi_Host *shost = class_to_shost(dev); | |
2337 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
2338 | struct lpfc_hba *phba = vport->phba; | |
2339 | ||
2340 | return snprintf(buf, PAGE_SIZE, "0x%llx\n", | |
2341 | (unsigned long long)phba->cfg_soft_wwpn); | |
2342 | } | |
2343 | ||
2344 | /** | |
2345 | * lpfc_soft_wwpn_store - Set the ww port name of the adapter | |
2346 | * @dev class device that is converted into a Scsi_host. | |
2347 | * @attr: device attribute, not used. | |
2348 | * @buf: contains the wwpn in hexadecimal. | |
2349 | * @count: number of wwpn bytes in buf | |
2350 | * | |
2351 | * Returns: | |
2352 | * -EACCES hba reset not enabled, adapter over temp | |
2353 | * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid | |
2354 | * -EIO error taking adapter offline or online | |
2355 | * value of count on success | |
2356 | **/ | |
2357 | static ssize_t | |
2358 | lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr, | |
2359 | const char *buf, size_t count) | |
2360 | { | |
2361 | struct Scsi_Host *shost = class_to_shost(dev); | |
2362 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
2363 | struct lpfc_hba *phba = vport->phba; | |
2364 | struct completion online_compl; | |
2365 | int stat1 = 0, stat2 = 0; | |
2366 | unsigned int cnt = count; | |
2367 | u8 wwpn[WWN_SZ]; | |
2368 | int rc; | |
2369 | ||
2370 | if (!phba->cfg_enable_hba_reset) | |
2371 | return -EACCES; | |
2372 | spin_lock_irq(&phba->hbalock); | |
2373 | if (phba->over_temp_state == HBA_OVER_TEMP) { | |
2374 | spin_unlock_irq(&phba->hbalock); | |
2375 | return -EACCES; | |
2376 | } | |
2377 | spin_unlock_irq(&phba->hbalock); | |
2378 | /* count may include a LF at end of string */ | |
2379 | if (buf[cnt-1] == '\n') | |
2380 | cnt--; | |
2381 | ||
2382 | if (!phba->soft_wwn_enable) | |
2383 | return -EINVAL; | |
2384 | ||
2385 | /* lock setting wwpn, wwnn down */ | |
2386 | phba->soft_wwn_enable = 0; | |
2387 | ||
2388 | rc = lpfc_wwn_set(buf, cnt, wwpn); | |
e2934ed1 | 2389 | if (rc) { |
352e5fd1 JS |
2390 | /* not able to set wwpn, unlock it */ |
2391 | phba->soft_wwn_enable = 1; | |
2392 | return rc; | |
2393 | } | |
2394 | ||
2395 | phba->cfg_soft_wwpn = wwn_to_u64(wwpn); | |
2396 | fc_host_port_name(shost) = phba->cfg_soft_wwpn; | |
2397 | if (phba->cfg_soft_wwnn) | |
2398 | fc_host_node_name(shost) = phba->cfg_soft_wwnn; | |
2399 | ||
2400 | dev_printk(KERN_NOTICE, &phba->pcidev->dev, | |
2401 | "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no); | |
2402 | ||
2403 | stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE); | |
2404 | if (stat1) | |
2405 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
2406 | "0463 lpfc_soft_wwpn attribute set failed to " | |
2407 | "reinit adapter - %d\n", stat1); | |
2408 | init_completion(&online_compl); | |
2409 | rc = lpfc_workq_post_event(phba, &stat2, &online_compl, | |
2410 | LPFC_EVT_ONLINE); | |
2411 | if (rc == 0) | |
2412 | return -ENOMEM; | |
2413 | ||
2414 | wait_for_completion(&online_compl); | |
2415 | if (stat2) | |
2416 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
2417 | "0464 lpfc_soft_wwpn attribute set failed to " | |
2418 | "reinit adapter - %d\n", stat2); | |
2419 | return (stat1 || stat2) ? -EIO : count; | |
2420 | } | |
2421 | static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR, | |
2422 | lpfc_soft_wwpn_show, lpfc_soft_wwpn_store); | |
2423 | ||
2424 | /** | |
2425 | * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter | |
2426 | * @dev: class device that is converted into a Scsi_host. | |
2427 | * @attr: device attribute, not used. | |
2428 | * @buf: on return contains the wwnn in hexadecimal. | |
2429 | * | |
2430 | * Returns: size of formatted string. | |
2431 | **/ | |
2432 | static ssize_t | |
2433 | lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr, | |
2434 | char *buf) | |
2435 | { | |
2436 | struct Scsi_Host *shost = class_to_shost(dev); | |
2437 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
2438 | return snprintf(buf, PAGE_SIZE, "0x%llx\n", | |
2439 | (unsigned long long)phba->cfg_soft_wwnn); | |
2440 | } | |
2441 | ||
2442 | /** | |
2443 | * lpfc_soft_wwnn_store - sets the ww node name of the adapter | |
2444 | * @cdev: class device that is converted into a Scsi_host. | |
2445 | * @buf: contains the ww node name in hexadecimal. | |
2446 | * @count: number of wwnn bytes in buf. | |
2447 | * | |
2448 | * Returns: | |
2449 | * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid | |
2450 | * value of count on success | |
2451 | **/ | |
2452 | static ssize_t | |
2453 | lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr, | |
2454 | const char *buf, size_t count) | |
2455 | { | |
2456 | struct Scsi_Host *shost = class_to_shost(dev); | |
2457 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
2458 | unsigned int cnt = count; | |
2459 | u8 wwnn[WWN_SZ]; | |
2460 | int rc; | |
2461 | ||
2462 | /* count may include a LF at end of string */ | |
2463 | if (buf[cnt-1] == '\n') | |
2464 | cnt--; | |
2465 | ||
2466 | if (!phba->soft_wwn_enable) | |
2467 | return -EINVAL; | |
2468 | ||
2469 | rc = lpfc_wwn_set(buf, cnt, wwnn); | |
e2934ed1 | 2470 | if (rc) { |
352e5fd1 JS |
2471 | /* Allow wwnn to be set many times, as long as the enable |
2472 | * is set. However, once the wwpn is set, everything locks. | |
2473 | */ | |
2474 | return rc; | |
2475 | } | |
2476 | ||
2477 | phba->cfg_soft_wwnn = wwn_to_u64(wwnn); | |
2478 | ||
2479 | dev_printk(KERN_NOTICE, &phba->pcidev->dev, | |
2480 | "lpfc%d: soft_wwnn set. Value will take effect upon " | |
2481 | "setting of the soft_wwpn\n", phba->brd_no); | |
2482 | ||
2483 | return count; | |
2484 | } | |
2485 | static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR, | |
2486 | lpfc_soft_wwnn_show, lpfc_soft_wwnn_store); | |
a12e07bc | 2487 | |
1ba981fd JS |
2488 | /** |
2489 | * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for | |
2490 | * Optimized Access Storage (OAS) operations. | |
2491 | * @dev: class device that is converted into a Scsi_host. | |
2492 | * @attr: device attribute, not used. | |
2493 | * @buf: buffer for passing information. | |
2494 | * | |
2495 | * Returns: | |
2496 | * value of count | |
2497 | **/ | |
2498 | static ssize_t | |
2499 | lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr, | |
2500 | char *buf) | |
2501 | { | |
2502 | struct Scsi_Host *shost = class_to_shost(dev); | |
2503 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
2504 | ||
2505 | return snprintf(buf, PAGE_SIZE, "0x%llx\n", | |
2506 | wwn_to_u64(phba->cfg_oas_tgt_wwpn)); | |
2507 | } | |
2508 | ||
2509 | /** | |
2510 | * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for | |
2511 | * Optimized Access Storage (OAS) operations. | |
2512 | * @dev: class device that is converted into a Scsi_host. | |
2513 | * @attr: device attribute, not used. | |
2514 | * @buf: buffer for passing information. | |
2515 | * @count: Size of the data buffer. | |
2516 | * | |
2517 | * Returns: | |
2518 | * -EINVAL count is invalid, invalid wwpn byte invalid | |
2519 | * -EPERM oas is not supported by hba | |
2520 | * value of count on success | |
2521 | **/ | |
2522 | static ssize_t | |
2523 | lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr, | |
2524 | const char *buf, size_t count) | |
2525 | { | |
2526 | struct Scsi_Host *shost = class_to_shost(dev); | |
2527 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
2528 | unsigned int cnt = count; | |
2529 | uint8_t wwpn[WWN_SZ]; | |
2530 | int rc; | |
2531 | ||
f38fa0bb | 2532 | if (!phba->cfg_fof) |
1ba981fd JS |
2533 | return -EPERM; |
2534 | ||
2535 | /* count may include a LF at end of string */ | |
2536 | if (buf[cnt-1] == '\n') | |
2537 | cnt--; | |
2538 | ||
2539 | rc = lpfc_wwn_set(buf, cnt, wwpn); | |
2540 | if (rc) | |
2541 | return rc; | |
2542 | ||
2543 | memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t))); | |
2544 | memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t))); | |
2545 | if (wwn_to_u64(wwpn) == 0) | |
2546 | phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET; | |
2547 | else | |
2548 | phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET; | |
2549 | phba->cfg_oas_flags &= ~OAS_LUN_VALID; | |
2550 | phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN; | |
2551 | return count; | |
2552 | } | |
2553 | static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR, | |
2554 | lpfc_oas_tgt_show, lpfc_oas_tgt_store); | |
2555 | ||
c92c841c JS |
2556 | /** |
2557 | * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for | |
2558 | * Optimized Access Storage (OAS) operations. | |
2559 | * @dev: class device that is converted into a Scsi_host. | |
2560 | * @attr: device attribute, not used. | |
2561 | * @buf: buffer for passing information. | |
2562 | * | |
2563 | * Returns: | |
2564 | * value of count | |
2565 | **/ | |
2566 | static ssize_t | |
2567 | lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr, | |
2568 | char *buf) | |
2569 | { | |
2570 | struct Scsi_Host *shost = class_to_shost(dev); | |
2571 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
2572 | ||
2573 | return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority); | |
2574 | } | |
2575 | ||
2576 | /** | |
2577 | * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for | |
2578 | * Optimized Access Storage (OAS) operations. | |
2579 | * @dev: class device that is converted into a Scsi_host. | |
2580 | * @attr: device attribute, not used. | |
2581 | * @buf: buffer for passing information. | |
2582 | * @count: Size of the data buffer. | |
2583 | * | |
2584 | * Returns: | |
2585 | * -EINVAL count is invalid, invalid wwpn byte invalid | |
2586 | * -EPERM oas is not supported by hba | |
2587 | * value of count on success | |
2588 | **/ | |
2589 | static ssize_t | |
2590 | lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr, | |
2591 | const char *buf, size_t count) | |
2592 | { | |
2593 | struct Scsi_Host *shost = class_to_shost(dev); | |
2594 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
2595 | unsigned int cnt = count; | |
2596 | unsigned long val; | |
2597 | int ret; | |
2598 | ||
2599 | if (!phba->cfg_fof) | |
2600 | return -EPERM; | |
2601 | ||
2602 | /* count may include a LF at end of string */ | |
2603 | if (buf[cnt-1] == '\n') | |
2604 | cnt--; | |
2605 | ||
2606 | ret = kstrtoul(buf, 0, &val); | |
2607 | if (ret || (val > 0x7f)) | |
2608 | return -EINVAL; | |
2609 | ||
2610 | if (val) | |
2611 | phba->cfg_oas_priority = (uint8_t)val; | |
2612 | else | |
2613 | phba->cfg_oas_priority = phba->cfg_XLanePriority; | |
2614 | return count; | |
2615 | } | |
2616 | static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR, | |
2617 | lpfc_oas_priority_show, lpfc_oas_priority_store); | |
2618 | ||
1ba981fd JS |
2619 | /** |
2620 | * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled | |
2621 | * for Optimized Access Storage (OAS) operations. | |
2622 | * @dev: class device that is converted into a Scsi_host. | |
2623 | * @attr: device attribute, not used. | |
2624 | * @buf: buffer for passing information. | |
2625 | * | |
2626 | * Returns: | |
2627 | * value of count on success | |
2628 | **/ | |
2629 | static ssize_t | |
2630 | lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr, | |
2631 | char *buf) | |
2632 | { | |
2633 | struct Scsi_Host *shost = class_to_shost(dev); | |
2634 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
2635 | ||
2636 | return snprintf(buf, PAGE_SIZE, "0x%llx\n", | |
2637 | wwn_to_u64(phba->cfg_oas_vpt_wwpn)); | |
2638 | } | |
2639 | ||
2640 | /** | |
2641 | * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled | |
2642 | * for Optimized Access Storage (OAS) operations. | |
2643 | * @dev: class device that is converted into a Scsi_host. | |
2644 | * @attr: device attribute, not used. | |
2645 | * @buf: buffer for passing information. | |
2646 | * @count: Size of the data buffer. | |
2647 | * | |
2648 | * Returns: | |
2649 | * -EINVAL count is invalid, invalid wwpn byte invalid | |
2650 | * -EPERM oas is not supported by hba | |
2651 | * value of count on success | |
2652 | **/ | |
2653 | static ssize_t | |
2654 | lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr, | |
2655 | const char *buf, size_t count) | |
2656 | { | |
2657 | struct Scsi_Host *shost = class_to_shost(dev); | |
2658 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
2659 | unsigned int cnt = count; | |
2660 | uint8_t wwpn[WWN_SZ]; | |
2661 | int rc; | |
2662 | ||
f38fa0bb | 2663 | if (!phba->cfg_fof) |
1ba981fd JS |
2664 | return -EPERM; |
2665 | ||
2666 | /* count may include a LF at end of string */ | |
2667 | if (buf[cnt-1] == '\n') | |
2668 | cnt--; | |
2669 | ||
2670 | rc = lpfc_wwn_set(buf, cnt, wwpn); | |
2671 | if (rc) | |
2672 | return rc; | |
2673 | ||
2674 | memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t))); | |
2675 | memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t))); | |
2676 | if (wwn_to_u64(wwpn) == 0) | |
2677 | phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT; | |
2678 | else | |
2679 | phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT; | |
2680 | phba->cfg_oas_flags &= ~OAS_LUN_VALID; | |
b5749fe1 JS |
2681 | if (phba->cfg_oas_priority == 0) |
2682 | phba->cfg_oas_priority = phba->cfg_XLanePriority; | |
1ba981fd JS |
2683 | phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN; |
2684 | return count; | |
2685 | } | |
2686 | static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR, | |
2687 | lpfc_oas_vpt_show, lpfc_oas_vpt_store); | |
2688 | ||
2689 | /** | |
2690 | * lpfc_oas_lun_state_show - Return the current state (enabled or disabled) | |
2691 | * of whether luns will be enabled or disabled | |
2692 | * for Optimized Access Storage (OAS) operations. | |
2693 | * @dev: class device that is converted into a Scsi_host. | |
2694 | * @attr: device attribute, not used. | |
2695 | * @buf: buffer for passing information. | |
2696 | * | |
2697 | * Returns: | |
2698 | * size of formatted string. | |
2699 | **/ | |
2700 | static ssize_t | |
2701 | lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr, | |
2702 | char *buf) | |
2703 | { | |
2704 | struct Scsi_Host *shost = class_to_shost(dev); | |
2705 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
2706 | ||
2707 | return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state); | |
2708 | } | |
2709 | ||
2710 | /** | |
2711 | * lpfc_oas_lun_state_store - Store the state (enabled or disabled) | |
2712 | * of whether luns will be enabled or disabled | |
2713 | * for Optimized Access Storage (OAS) operations. | |
2714 | * @dev: class device that is converted into a Scsi_host. | |
2715 | * @attr: device attribute, not used. | |
2716 | * @buf: buffer for passing information. | |
2717 | * @count: Size of the data buffer. | |
2718 | * | |
2719 | * Returns: | |
2720 | * -EINVAL count is invalid, invalid wwpn byte invalid | |
2721 | * -EPERM oas is not supported by hba | |
2722 | * value of count on success | |
2723 | **/ | |
2724 | static ssize_t | |
2725 | lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr, | |
2726 | const char *buf, size_t count) | |
2727 | { | |
2728 | struct Scsi_Host *shost = class_to_shost(dev); | |
2729 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
2730 | int val = 0; | |
2731 | ||
f38fa0bb | 2732 | if (!phba->cfg_fof) |
1ba981fd JS |
2733 | return -EPERM; |
2734 | ||
2735 | if (!isdigit(buf[0])) | |
2736 | return -EINVAL; | |
2737 | ||
2738 | if (sscanf(buf, "%i", &val) != 1) | |
2739 | return -EINVAL; | |
2740 | ||
2741 | if ((val != 0) && (val != 1)) | |
2742 | return -EINVAL; | |
2743 | ||
2744 | phba->cfg_oas_lun_state = val; | |
1ba981fd JS |
2745 | return strlen(buf); |
2746 | } | |
2747 | static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR, | |
2748 | lpfc_oas_lun_state_show, lpfc_oas_lun_state_store); | |
2749 | ||
2750 | /** | |
2751 | * lpfc_oas_lun_status_show - Return the status of the Optimized Access | |
2752 | * Storage (OAS) lun returned by the | |
2753 | * lpfc_oas_lun_show function. | |
2754 | * @dev: class device that is converted into a Scsi_host. | |
2755 | * @attr: device attribute, not used. | |
2756 | * @buf: buffer for passing information. | |
2757 | * | |
2758 | * Returns: | |
2759 | * size of formatted string. | |
2760 | **/ | |
2761 | static ssize_t | |
2762 | lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr, | |
2763 | char *buf) | |
2764 | { | |
2765 | struct Scsi_Host *shost = class_to_shost(dev); | |
2766 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
2767 | ||
2768 | if (!(phba->cfg_oas_flags & OAS_LUN_VALID)) | |
2769 | return -EFAULT; | |
2770 | ||
2771 | return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status); | |
2772 | } | |
2773 | static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO, | |
2774 | lpfc_oas_lun_status_show, NULL); | |
2775 | ||
2776 | ||
2777 | /** | |
2778 | * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage | |
2779 | * (OAS) operations. | |
2780 | * @phba: lpfc_hba pointer. | |
2781 | * @ndlp: pointer to fcp target node. | |
2782 | * @lun: the fc lun for setting oas state. | |
2783 | * @oas_state: the oas state to be set to the lun. | |
2784 | * | |
2785 | * Returns: | |
2786 | * SUCCESS : 0 | |
2787 | * -EPERM OAS is not enabled or not supported by this port. | |
2788 | * | |
2789 | */ | |
2790 | static size_t | |
2791 | lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[], | |
c92c841c JS |
2792 | uint8_t tgt_wwpn[], uint64_t lun, |
2793 | uint32_t oas_state, uint8_t pri) | |
1ba981fd JS |
2794 | { |
2795 | ||
2796 | int rc = 0; | |
2797 | ||
f38fa0bb | 2798 | if (!phba->cfg_fof) |
1ba981fd JS |
2799 | return -EPERM; |
2800 | ||
2801 | if (oas_state) { | |
2802 | if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn, | |
c92c841c JS |
2803 | (struct lpfc_name *)tgt_wwpn, |
2804 | lun, pri)) | |
1ba981fd JS |
2805 | rc = -ENOMEM; |
2806 | } else { | |
2807 | lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn, | |
b5749fe1 | 2808 | (struct lpfc_name *)tgt_wwpn, lun, pri); |
1ba981fd JS |
2809 | } |
2810 | return rc; | |
2811 | ||
2812 | } | |
2813 | ||
2814 | /** | |
2815 | * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized | |
2816 | * Access Storage (OAS) operations. | |
2817 | * @phba: lpfc_hba pointer. | |
2818 | * @vpt_wwpn: wwpn of the vport associated with the returned lun | |
2819 | * @tgt_wwpn: wwpn of the target associated with the returned lun | |
2820 | * @lun_status: status of the lun returned lun | |
2821 | * | |
2822 | * Returns the first or next lun enabled for OAS operations for the vport/target | |
2823 | * specified. If a lun is found, its vport wwpn, target wwpn and status is | |
2824 | * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned. | |
2825 | * | |
2826 | * Return: | |
2827 | * lun that is OAS enabled for the vport/target | |
2828 | * NOT_OAS_ENABLED_LUN when no oas enabled lun found. | |
2829 | */ | |
2830 | static uint64_t | |
2831 | lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[], | |
b5749fe1 JS |
2832 | uint8_t tgt_wwpn[], uint32_t *lun_status, |
2833 | uint32_t *lun_pri) | |
1ba981fd JS |
2834 | { |
2835 | uint64_t found_lun; | |
2836 | ||
2837 | if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn) | |
2838 | return NOT_OAS_ENABLED_LUN; | |
2839 | if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *) | |
2840 | phba->sli4_hba.oas_next_vpt_wwpn, | |
2841 | (struct lpfc_name *) | |
2842 | phba->sli4_hba.oas_next_tgt_wwpn, | |
2843 | &phba->sli4_hba.oas_next_lun, | |
2844 | (struct lpfc_name *)vpt_wwpn, | |
2845 | (struct lpfc_name *)tgt_wwpn, | |
b5749fe1 | 2846 | &found_lun, lun_status, lun_pri)) |
1ba981fd JS |
2847 | return found_lun; |
2848 | else | |
2849 | return NOT_OAS_ENABLED_LUN; | |
2850 | } | |
2851 | ||
2852 | /** | |
2853 | * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations | |
2854 | * @phba: lpfc_hba pointer. | |
2855 | * @vpt_wwpn: vport wwpn by reference. | |
2856 | * @tgt_wwpn: target wwpn by reference. | |
2857 | * @lun: the fc lun for setting oas state. | |
2858 | * @oas_state: the oas state to be set to the oas_lun. | |
2859 | * | |
2860 | * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE) | |
2861 | * a lun for OAS operations. | |
2862 | * | |
2863 | * Return: | |
2864 | * SUCCESS: 0 | |
2865 | * -ENOMEM: failed to enable an lun for OAS operations | |
2866 | * -EPERM: OAS is not enabled | |
2867 | */ | |
2868 | static ssize_t | |
2869 | lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[], | |
2870 | uint8_t tgt_wwpn[], uint64_t lun, | |
c92c841c | 2871 | uint32_t oas_state, uint8_t pri) |
1ba981fd JS |
2872 | { |
2873 | ||
2874 | int rc; | |
2875 | ||
2876 | rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun, | |
c92c841c | 2877 | oas_state, pri); |
1ba981fd JS |
2878 | return rc; |
2879 | } | |
2880 | ||
2881 | /** | |
2882 | * lpfc_oas_lun_show - Return oas enabled luns from a chosen target | |
2883 | * @dev: class device that is converted into a Scsi_host. | |
2884 | * @attr: device attribute, not used. | |
2885 | * @buf: buffer for passing information. | |
2886 | * | |
2887 | * This routine returns a lun enabled for OAS each time the function | |
2888 | * is called. | |
2889 | * | |
2890 | * Returns: | |
2891 | * SUCCESS: size of formatted string. | |
2892 | * -EFAULT: target or vport wwpn was not set properly. | |
2893 | * -EPERM: oas is not enabled. | |
2894 | **/ | |
2895 | static ssize_t | |
2896 | lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr, | |
2897 | char *buf) | |
2898 | { | |
2899 | struct Scsi_Host *shost = class_to_shost(dev); | |
2900 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
2901 | ||
2902 | uint64_t oas_lun; | |
2903 | int len = 0; | |
2904 | ||
f38fa0bb | 2905 | if (!phba->cfg_fof) |
1ba981fd JS |
2906 | return -EPERM; |
2907 | ||
2908 | if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0) | |
2909 | if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT)) | |
2910 | return -EFAULT; | |
2911 | ||
2912 | if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0) | |
2913 | if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET)) | |
2914 | return -EFAULT; | |
2915 | ||
2916 | oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn, | |
2917 | phba->cfg_oas_tgt_wwpn, | |
b5749fe1 JS |
2918 | &phba->cfg_oas_lun_status, |
2919 | &phba->cfg_oas_priority); | |
1ba981fd JS |
2920 | if (oas_lun != NOT_OAS_ENABLED_LUN) |
2921 | phba->cfg_oas_flags |= OAS_LUN_VALID; | |
2922 | ||
2923 | len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun); | |
2924 | ||
2925 | return len; | |
2926 | } | |
2927 | ||
2928 | /** | |
2929 | * lpfc_oas_lun_store - Sets the OAS state for lun | |
2930 | * @dev: class device that is converted into a Scsi_host. | |
2931 | * @attr: device attribute, not used. | |
2932 | * @buf: buffer for passing information. | |
2933 | * | |
2934 | * This function sets the OAS state for lun. Before this function is called, | |
2935 | * the vport wwpn, target wwpn, and oas state need to be set. | |
2936 | * | |
2937 | * Returns: | |
2938 | * SUCCESS: size of formatted string. | |
2939 | * -EFAULT: target or vport wwpn was not set properly. | |
2940 | * -EPERM: oas is not enabled. | |
2941 | * size of formatted string. | |
2942 | **/ | |
2943 | static ssize_t | |
2944 | lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr, | |
2945 | const char *buf, size_t count) | |
2946 | { | |
2947 | struct Scsi_Host *shost = class_to_shost(dev); | |
2948 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
2949 | uint64_t scsi_lun; | |
b5749fe1 | 2950 | uint32_t pri; |
1ba981fd JS |
2951 | ssize_t rc; |
2952 | ||
f38fa0bb | 2953 | if (!phba->cfg_fof) |
1ba981fd JS |
2954 | return -EPERM; |
2955 | ||
2956 | if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0) | |
2957 | return -EFAULT; | |
2958 | ||
2959 | if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0) | |
2960 | return -EFAULT; | |
2961 | ||
2962 | if (!isdigit(buf[0])) | |
2963 | return -EINVAL; | |
2964 | ||
2965 | if (sscanf(buf, "0x%llx", &scsi_lun) != 1) | |
2966 | return -EINVAL; | |
2967 | ||
b5749fe1 JS |
2968 | pri = phba->cfg_oas_priority; |
2969 | if (pri == 0) | |
2970 | pri = phba->cfg_XLanePriority; | |
2971 | ||
1ba981fd | 2972 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
c92c841c JS |
2973 | "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx " |
2974 | "priority 0x%x with oas state %d\n", | |
1ba981fd JS |
2975 | wwn_to_u64(phba->cfg_oas_vpt_wwpn), |
2976 | wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun, | |
b5749fe1 | 2977 | pri, phba->cfg_oas_lun_state); |
1ba981fd JS |
2978 | |
2979 | rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn, | |
c92c841c | 2980 | phba->cfg_oas_tgt_wwpn, scsi_lun, |
b5749fe1 | 2981 | phba->cfg_oas_lun_state, pri); |
1ba981fd JS |
2982 | if (rc) |
2983 | return rc; | |
2984 | ||
2985 | return count; | |
2986 | } | |
2987 | static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR, | |
2988 | lpfc_oas_lun_show, lpfc_oas_lun_store); | |
c3f28afa | 2989 | |
f358dd0c JS |
2990 | int lpfc_enable_nvmet_cnt; |
2991 | unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = { | |
2992 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
2993 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; | |
2994 | module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444); | |
2995 | MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target"); | |
2996 | ||
875fbdfe | 2997 | static int lpfc_poll = 0; |
ab56dc2e | 2998 | module_param(lpfc_poll, int, S_IRUGO); |
875fbdfe JSEC |
2999 | MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:" |
3000 | " 0 - none," | |
3001 | " 1 - poll with interrupts enabled" | |
3002 | " 3 - poll and disable FCP ring interrupts"); | |
3003 | ||
ee959b00 TJ |
3004 | static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR, |
3005 | lpfc_poll_show, lpfc_poll_store); | |
dea3101e | 3006 | |
12247e81 JS |
3007 | LPFC_ATTR(sli_mode, 0, 0, 3, |
3008 | "SLI mode selector:" | |
3009 | " 0 - auto (SLI-3 if supported)," | |
3010 | " 2 - select SLI-2 even on SLI-3 capable HBAs," | |
3011 | " 3 - select SLI-3"); | |
92d7f7b0 | 3012 | |
458c083e JS |
3013 | LPFC_ATTR_R(enable_npiv, 1, 0, 1, |
3014 | "Enable NPIV functionality"); | |
92d7f7b0 | 3015 | |
7d791df7 JS |
3016 | LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2, |
3017 | "FCF Fast failover=1 Priority failover=2"); | |
3018 | ||
e5771b4d JS |
3019 | /* |
3020 | # lpfc_enable_rrq: Track XRI/OXID reuse after IO failures | |
3021 | # 0x0 = disabled, XRI/OXID use not tracked. | |
3022 | # 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent. | |
3023 | # 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent. | |
3024 | */ | |
31202b0e JS |
3025 | LPFC_ATTR_R(enable_rrq, 2, 0, 2, |
3026 | "Enable RRQ functionality"); | |
19ca7609 | 3027 | |
84d1b006 JS |
3028 | /* |
3029 | # lpfc_suppress_link_up: Bring link up at initialization | |
3030 | # 0x0 = bring link up (issue MBX_INIT_LINK) | |
3031 | # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK) | |
3032 | # 0x2 = never bring up link | |
3033 | # Default value is 0. | |
3034 | */ | |
e40a02c1 JS |
3035 | LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK, |
3036 | LPFC_DELAY_INIT_LINK_INDEFINITELY, | |
3037 | "Suppress Link Up at initialization"); | |
2a9bf3d0 JS |
3038 | /* |
3039 | # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS | |
3040 | # 1 - (1024) | |
3041 | # 2 - (2048) | |
3042 | # 3 - (3072) | |
3043 | # 4 - (4096) | |
3044 | # 5 - (5120) | |
3045 | */ | |
3046 | static ssize_t | |
3047 | lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf) | |
3048 | { | |
3049 | struct Scsi_Host *shost = class_to_shost(dev); | |
3050 | struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba; | |
3051 | ||
3052 | return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max); | |
3053 | } | |
3054 | ||
3055 | static DEVICE_ATTR(iocb_hw, S_IRUGO, | |
3056 | lpfc_iocb_hw_show, NULL); | |
3057 | static ssize_t | |
3058 | lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf) | |
3059 | { | |
3060 | struct Scsi_Host *shost = class_to_shost(dev); | |
3061 | struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba; | |
895427bd | 3062 | struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba); |
2a9bf3d0 | 3063 | |
895427bd | 3064 | return snprintf(buf, PAGE_SIZE, "%d\n", pring->txq_max); |
2a9bf3d0 JS |
3065 | } |
3066 | ||
3067 | static DEVICE_ATTR(txq_hw, S_IRUGO, | |
3068 | lpfc_txq_hw_show, NULL); | |
3069 | static ssize_t | |
3070 | lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr, | |
3071 | char *buf) | |
3072 | { | |
3073 | struct Scsi_Host *shost = class_to_shost(dev); | |
3074 | struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba; | |
895427bd | 3075 | struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba); |
2a9bf3d0 | 3076 | |
895427bd | 3077 | return snprintf(buf, PAGE_SIZE, "%d\n", pring->txcmplq_max); |
2a9bf3d0 JS |
3078 | } |
3079 | ||
3080 | static DEVICE_ATTR(txcmplq_hw, S_IRUGO, | |
3081 | lpfc_txcmplq_hw_show, NULL); | |
3082 | ||
0d8c8ba3 | 3083 | LPFC_ATTR_R(iocb_cnt, 2, 1, 5, |
2a9bf3d0 | 3084 | "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs"); |
84d1b006 | 3085 | |
c01f3208 JS |
3086 | /* |
3087 | # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear | |
3088 | # until the timer expires. Value range is [0,255]. Default value is 30. | |
3089 | */ | |
3090 | static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO; | |
3091 | static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO; | |
3092 | module_param(lpfc_nodev_tmo, int, 0); | |
3093 | MODULE_PARM_DESC(lpfc_nodev_tmo, | |
3094 | "Seconds driver will hold I/O waiting " | |
3095 | "for a device to come back"); | |
e59058c4 JS |
3096 | |
3097 | /** | |
3621a710 | 3098 | * lpfc_nodev_tmo_show - Return the hba dev loss timeout value |
e59058c4 JS |
3099 | * @dev: class converted to a Scsi_host structure. |
3100 | * @attr: device attribute, not used. | |
3101 | * @buf: on return contains the dev loss timeout in decimal. | |
3102 | * | |
3103 | * Returns: size of formatted string. | |
3104 | **/ | |
c01f3208 | 3105 | static ssize_t |
ee959b00 TJ |
3106 | lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr, |
3107 | char *buf) | |
c01f3208 | 3108 | { |
ee959b00 | 3109 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 | 3110 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
e40a02c1 | 3111 | |
3de2a653 | 3112 | return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo); |
c01f3208 JS |
3113 | } |
3114 | ||
e59058c4 | 3115 | /** |
3621a710 | 3116 | * lpfc_nodev_tmo_init - Set the hba nodev timeout value |
e59058c4 JS |
3117 | * @vport: lpfc vport structure pointer. |
3118 | * @val: contains the nodev timeout value. | |
3119 | * | |
3120 | * Description: | |
3121 | * If the devloss tmo is already set then nodev tmo is set to devloss tmo, | |
3122 | * a kernel error message is printed and zero is returned. | |
3123 | * Else if val is in range then nodev tmo and devloss tmo are set to val. | |
3124 | * Otherwise nodev tmo is set to the default value. | |
3125 | * | |
3126 | * Returns: | |
3127 | * zero if already set or if val is in range | |
3128 | * -EINVAL val out of range | |
3129 | **/ | |
c01f3208 | 3130 | static int |
3de2a653 JS |
3131 | lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val) |
3132 | { | |
3133 | if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) { | |
3134 | vport->cfg_nodev_tmo = vport->cfg_devloss_tmo; | |
3135 | if (val != LPFC_DEF_DEVLOSS_TMO) | |
e8b62011 | 3136 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
6c86068d JS |
3137 | "0407 Ignoring lpfc_nodev_tmo module " |
3138 | "parameter because lpfc_devloss_tmo " | |
3139 | "is set.\n"); | |
c01f3208 JS |
3140 | return 0; |
3141 | } | |
3142 | ||
3143 | if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) { | |
3de2a653 JS |
3144 | vport->cfg_nodev_tmo = val; |
3145 | vport->cfg_devloss_tmo = val; | |
c01f3208 JS |
3146 | return 0; |
3147 | } | |
e8b62011 JS |
3148 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
3149 | "0400 lpfc_nodev_tmo attribute cannot be set to" | |
3150 | " %d, allowed range is [%d, %d]\n", | |
3151 | val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO); | |
3de2a653 | 3152 | vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO; |
c01f3208 JS |
3153 | return -EINVAL; |
3154 | } | |
3155 | ||
e59058c4 | 3156 | /** |
3621a710 | 3157 | * lpfc_update_rport_devloss_tmo - Update dev loss tmo value |
e59058c4 JS |
3158 | * @vport: lpfc vport structure pointer. |
3159 | * | |
3160 | * Description: | |
3161 | * Update all the ndlp's dev loss tmo with the vport devloss tmo value. | |
3162 | **/ | |
7054a606 | 3163 | static void |
3de2a653 | 3164 | lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport) |
7054a606 | 3165 | { |
858c9f6c | 3166 | struct Scsi_Host *shost; |
7054a606 JS |
3167 | struct lpfc_nodelist *ndlp; |
3168 | ||
51ef4c26 JS |
3169 | shost = lpfc_shost_from_vport(vport); |
3170 | spin_lock_irq(shost->host_lock); | |
3171 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) | |
e47c9093 | 3172 | if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport) |
51ef4c26 JS |
3173 | ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo; |
3174 | spin_unlock_irq(shost->host_lock); | |
7054a606 JS |
3175 | } |
3176 | ||
e59058c4 | 3177 | /** |
3621a710 | 3178 | * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values |
e59058c4 JS |
3179 | * @vport: lpfc vport structure pointer. |
3180 | * @val: contains the tmo value. | |
3181 | * | |
3182 | * Description: | |
3183 | * If the devloss tmo is already set or the vport dev loss tmo has changed | |
3184 | * then a kernel error message is printed and zero is returned. | |
3185 | * Else if val is in range then nodev tmo and devloss tmo are set to val. | |
3186 | * Otherwise nodev tmo is set to the default value. | |
3187 | * | |
3188 | * Returns: | |
3189 | * zero if already set or if val is in range | |
3190 | * -EINVAL val out of range | |
3191 | **/ | |
c01f3208 | 3192 | static int |
3de2a653 | 3193 | lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val) |
c01f3208 | 3194 | { |
3de2a653 JS |
3195 | if (vport->dev_loss_tmo_changed || |
3196 | (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) { | |
e8b62011 | 3197 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
6c86068d JS |
3198 | "0401 Ignoring change to lpfc_nodev_tmo " |
3199 | "because lpfc_devloss_tmo is set.\n"); | |
c01f3208 JS |
3200 | return 0; |
3201 | } | |
c01f3208 | 3202 | if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) { |
3de2a653 JS |
3203 | vport->cfg_nodev_tmo = val; |
3204 | vport->cfg_devloss_tmo = val; | |
0af5d708 MC |
3205 | /* |
3206 | * For compat: set the fc_host dev loss so new rports | |
3207 | * will get the value. | |
3208 | */ | |
3209 | fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val; | |
3de2a653 | 3210 | lpfc_update_rport_devloss_tmo(vport); |
c01f3208 JS |
3211 | return 0; |
3212 | } | |
e8b62011 | 3213 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
6c86068d | 3214 | "0403 lpfc_nodev_tmo attribute cannot be set to " |
e8b62011 JS |
3215 | "%d, allowed range is [%d, %d]\n", |
3216 | val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO); | |
c01f3208 JS |
3217 | return -EINVAL; |
3218 | } | |
3219 | ||
3de2a653 | 3220 | lpfc_vport_param_store(nodev_tmo) |
c01f3208 | 3221 | |
ee959b00 TJ |
3222 | static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR, |
3223 | lpfc_nodev_tmo_show, lpfc_nodev_tmo_store); | |
c01f3208 JS |
3224 | |
3225 | /* | |
3226 | # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that | |
3227 | # disappear until the timer expires. Value range is [0,255]. Default | |
3228 | # value is 30. | |
3229 | */ | |
ab56dc2e | 3230 | module_param(lpfc_devloss_tmo, int, S_IRUGO); |
c01f3208 JS |
3231 | MODULE_PARM_DESC(lpfc_devloss_tmo, |
3232 | "Seconds driver will hold I/O waiting " | |
3233 | "for a device to come back"); | |
3de2a653 JS |
3234 | lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO, |
3235 | LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO) | |
3236 | lpfc_vport_param_show(devloss_tmo) | |
e59058c4 JS |
3237 | |
3238 | /** | |
3621a710 | 3239 | * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit |
e59058c4 JS |
3240 | * @vport: lpfc vport structure pointer. |
3241 | * @val: contains the tmo value. | |
3242 | * | |
3243 | * Description: | |
3244 | * If val is in a valid range then set the vport nodev tmo, | |
3245 | * devloss tmo, also set the vport dev loss tmo changed flag. | |
3246 | * Else a kernel error message is printed. | |
3247 | * | |
3248 | * Returns: | |
3249 | * zero if val is in range | |
3250 | * -EINVAL val out of range | |
3251 | **/ | |
c01f3208 | 3252 | static int |
3de2a653 | 3253 | lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val) |
c01f3208 JS |
3254 | { |
3255 | if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) { | |
3de2a653 JS |
3256 | vport->cfg_nodev_tmo = val; |
3257 | vport->cfg_devloss_tmo = val; | |
3258 | vport->dev_loss_tmo_changed = 1; | |
0af5d708 | 3259 | fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val; |
3de2a653 | 3260 | lpfc_update_rport_devloss_tmo(vport); |
c01f3208 JS |
3261 | return 0; |
3262 | } | |
3263 | ||
e8b62011 | 3264 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
6c86068d JS |
3265 | "0404 lpfc_devloss_tmo attribute cannot be set to " |
3266 | "%d, allowed range is [%d, %d]\n", | |
e8b62011 | 3267 | val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO); |
c01f3208 JS |
3268 | return -EINVAL; |
3269 | } | |
3270 | ||
3de2a653 | 3271 | lpfc_vport_param_store(devloss_tmo) |
ee959b00 TJ |
3272 | static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR, |
3273 | lpfc_devloss_tmo_show, lpfc_devloss_tmo_store); | |
c01f3208 | 3274 | |
f358dd0c JS |
3275 | /* |
3276 | * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it | |
3277 | * lpfc_suppress_rsp = 0 Disable | |
3278 | * lpfc_suppress_rsp = 1 Enable (default) | |
3279 | * | |
3280 | */ | |
3281 | LPFC_ATTR_R(suppress_rsp, 1, 0, 1, | |
3282 | "Enable suppress rsp feature is firmware supports it"); | |
3283 | ||
895427bd JS |
3284 | /* |
3285 | * lpfc_enable_fc4_type: Defines what FC4 types are supported. | |
3286 | * Supported Values: 1 - register just FCP | |
3287 | * 3 - register both FCP and NVME | |
3288 | * Supported values are [1,3]. Default value is 3 | |
3289 | */ | |
3290 | LPFC_ATTR_R(enable_fc4_type, LPFC_ENABLE_BOTH, | |
3291 | LPFC_ENABLE_FCP, LPFC_ENABLE_BOTH, | |
3292 | "Define fc4 type to register with fabric."); | |
3293 | ||
3294 | /* | |
3295 | * lpfc_xri_split: Defines the division of XRI resources between SCSI and NVME | |
3296 | * This parameter is only used if: | |
f358dd0c JS |
3297 | * lpfc_enable_fc4_type is 3 - register both FCP and NVME and |
3298 | * port is not configured for NVMET. | |
895427bd JS |
3299 | * |
3300 | * ELS/CT always get 10% of XRIs, up to a maximum of 250 | |
3301 | * The remaining XRIs get split up based on lpfc_xri_split per port: | |
3302 | * | |
3303 | * Supported Values are in percentages | |
3304 | * the xri_split value is the percentage the SCSI port will get. The remaining | |
3305 | * percentage will go to NVME. | |
3306 | */ | |
3307 | LPFC_ATTR_R(xri_split, 50, 10, 90, | |
3308 | "Division of XRI resources between SCSI and NVME"); | |
3309 | ||
dea3101e JB |
3310 | /* |
3311 | # lpfc_log_verbose: Only turn this flag on if you are willing to risk being | |
3312 | # deluged with LOTS of information. | |
3313 | # You can set a bit mask to record specific types of verbose messages: | |
f4b4c68f | 3314 | # See lpfc_logmsh.h for definitions. |
dea3101e | 3315 | */ |
f4b4c68f | 3316 | LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff, |
e8b62011 | 3317 | "Verbose logging bit-mask"); |
dea3101e | 3318 | |
7ee5d43e JS |
3319 | /* |
3320 | # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters | |
3321 | # objects that have been registered with the nameserver after login. | |
3322 | */ | |
cf971240 | 3323 | LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1, |
7ee5d43e JS |
3324 | "Deregister nameserver objects before LOGO"); |
3325 | ||
dea3101e JB |
3326 | /* |
3327 | # lun_queue_depth: This parameter is used to limit the number of outstanding | |
572709e2 JS |
3328 | # commands per FCP LUN. Value range is [1,512]. Default value is 30. |
3329 | # If this parameter value is greater than 1/8th the maximum number of exchanges | |
3330 | # supported by the HBA port, then the lun queue depth will be reduced to | |
3331 | # 1/8th the maximum number of exchanges. | |
dea3101e | 3332 | */ |
572709e2 | 3333 | LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512, |
3de2a653 | 3334 | "Max number of FCP commands we can queue to a specific LUN"); |
dea3101e | 3335 | |
7dc517df JS |
3336 | /* |
3337 | # tgt_queue_depth: This parameter is used to limit the number of outstanding | |
3338 | # commands per target port. Value range is [10,65535]. Default value is 65535. | |
3339 | */ | |
3340 | LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535, | |
572709e2 | 3341 | "Max number of FCP commands we can queue to a specific target port"); |
7dc517df | 3342 | |
b28485ac JW |
3343 | /* |
3344 | # hba_queue_depth: This parameter is used to limit the number of outstanding | |
3345 | # commands per lpfc HBA. Value range is [32,8192]. If this parameter | |
3346 | # value is greater than the maximum number of exchanges supported by the HBA, | |
3347 | # then maximum number of exchanges supported by the HBA is used to determine | |
3348 | # the hba_queue_depth. | |
3349 | */ | |
3350 | LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192, | |
3351 | "Max number of FCP commands we can queue to a lpfc HBA"); | |
3352 | ||
92d7f7b0 JS |
3353 | /* |
3354 | # peer_port_login: This parameter allows/prevents logins | |
3355 | # between peer ports hosted on the same physical port. | |
3356 | # When this parameter is set 0 peer ports of same physical port | |
3357 | # are not allowed to login to each other. | |
3358 | # When this parameter is set 1 peer ports of same physical port | |
3359 | # are allowed to login to each other. | |
3360 | # Default value of this parameter is 0. | |
3361 | */ | |
3de2a653 JS |
3362 | LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1, |
3363 | "Allow peer ports on the same physical port to login to each " | |
3364 | "other."); | |
92d7f7b0 JS |
3365 | |
3366 | /* | |
3de2a653 | 3367 | # restrict_login: This parameter allows/prevents logins |
92d7f7b0 JS |
3368 | # between Virtual Ports and remote initiators. |
3369 | # When this parameter is not set (0) Virtual Ports will accept PLOGIs from | |
3370 | # other initiators and will attempt to PLOGI all remote ports. | |
3371 | # When this parameter is set (1) Virtual Ports will reject PLOGIs from | |
3372 | # remote ports and will not attempt to PLOGI to other initiators. | |
3373 | # This parameter does not restrict to the physical port. | |
3374 | # This parameter does not restrict logins to Fabric resident remote ports. | |
3375 | # Default value of this parameter is 1. | |
3376 | */ | |
3de2a653 | 3377 | static int lpfc_restrict_login = 1; |
ab56dc2e | 3378 | module_param(lpfc_restrict_login, int, S_IRUGO); |
3de2a653 JS |
3379 | MODULE_PARM_DESC(lpfc_restrict_login, |
3380 | "Restrict virtual ports login to remote initiators."); | |
3381 | lpfc_vport_param_show(restrict_login); | |
3382 | ||
e59058c4 | 3383 | /** |
3621a710 | 3384 | * lpfc_restrict_login_init - Set the vport restrict login flag |
e59058c4 JS |
3385 | * @vport: lpfc vport structure pointer. |
3386 | * @val: contains the restrict login value. | |
3387 | * | |
3388 | * Description: | |
3389 | * If val is not in a valid range then log a kernel error message and set | |
3390 | * the vport restrict login to one. | |
3391 | * If the port type is physical clear the restrict login flag and return. | |
3392 | * Else set the restrict login flag to val. | |
3393 | * | |
3394 | * Returns: | |
3395 | * zero if val is in range | |
3396 | * -EINVAL val out of range | |
3397 | **/ | |
3de2a653 JS |
3398 | static int |
3399 | lpfc_restrict_login_init(struct lpfc_vport *vport, int val) | |
3400 | { | |
3401 | if (val < 0 || val > 1) { | |
e8b62011 | 3402 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
d7c255b2 | 3403 | "0422 lpfc_restrict_login attribute cannot " |
e8b62011 JS |
3404 | "be set to %d, allowed range is [0, 1]\n", |
3405 | val); | |
3de2a653 JS |
3406 | vport->cfg_restrict_login = 1; |
3407 | return -EINVAL; | |
3408 | } | |
3409 | if (vport->port_type == LPFC_PHYSICAL_PORT) { | |
3410 | vport->cfg_restrict_login = 0; | |
3411 | return 0; | |
3412 | } | |
3413 | vport->cfg_restrict_login = val; | |
3414 | return 0; | |
3415 | } | |
3416 | ||
e59058c4 | 3417 | /** |
3621a710 | 3418 | * lpfc_restrict_login_set - Set the vport restrict login flag |
e59058c4 JS |
3419 | * @vport: lpfc vport structure pointer. |
3420 | * @val: contains the restrict login value. | |
3421 | * | |
3422 | * Description: | |
3423 | * If val is not in a valid range then log a kernel error message and set | |
3424 | * the vport restrict login to one. | |
3425 | * If the port type is physical and the val is not zero log a kernel | |
3426 | * error message, clear the restrict login flag and return zero. | |
3427 | * Else set the restrict login flag to val. | |
3428 | * | |
3429 | * Returns: | |
3430 | * zero if val is in range | |
3431 | * -EINVAL val out of range | |
3432 | **/ | |
3de2a653 JS |
3433 | static int |
3434 | lpfc_restrict_login_set(struct lpfc_vport *vport, int val) | |
3435 | { | |
3436 | if (val < 0 || val > 1) { | |
e8b62011 | 3437 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
d7c255b2 | 3438 | "0425 lpfc_restrict_login attribute cannot " |
e8b62011 JS |
3439 | "be set to %d, allowed range is [0, 1]\n", |
3440 | val); | |
3de2a653 JS |
3441 | vport->cfg_restrict_login = 1; |
3442 | return -EINVAL; | |
3443 | } | |
3444 | if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) { | |
e8b62011 JS |
3445 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
3446 | "0468 lpfc_restrict_login must be 0 for " | |
3447 | "Physical ports.\n"); | |
3de2a653 JS |
3448 | vport->cfg_restrict_login = 0; |
3449 | return 0; | |
3450 | } | |
3451 | vport->cfg_restrict_login = val; | |
3452 | return 0; | |
3453 | } | |
3454 | lpfc_vport_param_store(restrict_login); | |
ee959b00 TJ |
3455 | static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR, |
3456 | lpfc_restrict_login_show, lpfc_restrict_login_store); | |
92d7f7b0 | 3457 | |
dea3101e JB |
3458 | /* |
3459 | # Some disk devices have a "select ID" or "select Target" capability. | |
3460 | # From a protocol standpoint "select ID" usually means select the | |
3461 | # Fibre channel "ALPA". In the FC-AL Profile there is an "informative | |
3462 | # annex" which contains a table that maps a "select ID" (a number | |
3463 | # between 0 and 7F) to an ALPA. By default, for compatibility with | |
3464 | # older drivers, the lpfc driver scans this table from low ALPA to high | |
3465 | # ALPA. | |
3466 | # | |
3467 | # Turning on the scan-down variable (on = 1, off = 0) will | |
3468 | # cause the lpfc driver to use an inverted table, effectively | |
3469 | # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1. | |
3470 | # | |
3471 | # (Note: This "select ID" functionality is a LOOP ONLY characteristic | |
3472 | # and will not work across a fabric. Also this parameter will take | |
3473 | # effect only in the case when ALPA map is not available.) | |
3474 | */ | |
3de2a653 JS |
3475 | LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1, |
3476 | "Start scanning for devices from highest ALPA to lowest"); | |
dea3101e | 3477 | |
dea3101e JB |
3478 | /* |
3479 | # lpfc_topology: link topology for init link | |
3480 | # 0x0 = attempt loop mode then point-to-point | |
367c2713 | 3481 | # 0x01 = internal loopback mode |
dea3101e JB |
3482 | # 0x02 = attempt point-to-point mode only |
3483 | # 0x04 = attempt loop mode only | |
3484 | # 0x06 = attempt point-to-point mode then loop | |
3485 | # Set point-to-point mode if you want to run as an N_Port. | |
3486 | # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6]. | |
3487 | # Default value is 0. | |
3488 | */ | |
0a035439 JS |
3489 | LPFC_ATTR(topology, 0, 0, 6, |
3490 | "Select Fibre Channel topology"); | |
e59058c4 JS |
3491 | |
3492 | /** | |
3621a710 | 3493 | * lpfc_topology_set - Set the adapters topology field |
e59058c4 JS |
3494 | * @phba: lpfc_hba pointer. |
3495 | * @val: topology value. | |
3496 | * | |
3497 | * Description: | |
3498 | * If val is in a valid range then set the adapter's topology field and | |
3499 | * issue a lip; if the lip fails reset the topology to the old value. | |
3500 | * | |
3501 | * If the value is not in range log a kernel error message and return an error. | |
3502 | * | |
3503 | * Returns: | |
3504 | * zero if val is in range and lip okay | |
3505 | * non-zero return value from lpfc_issue_lip() | |
3506 | * -EINVAL val out of range | |
3507 | **/ | |
a257bf90 JS |
3508 | static ssize_t |
3509 | lpfc_topology_store(struct device *dev, struct device_attribute *attr, | |
3510 | const char *buf, size_t count) | |
83108bd3 | 3511 | { |
a257bf90 JS |
3512 | struct Scsi_Host *shost = class_to_shost(dev); |
3513 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
3514 | struct lpfc_hba *phba = vport->phba; | |
3515 | int val = 0; | |
3516 | int nolip = 0; | |
3517 | const char *val_buf = buf; | |
83108bd3 JS |
3518 | int err; |
3519 | uint32_t prev_val; | |
a257bf90 JS |
3520 | |
3521 | if (!strncmp(buf, "nolip ", strlen("nolip "))) { | |
3522 | nolip = 1; | |
3523 | val_buf = &buf[strlen("nolip ")]; | |
3524 | } | |
3525 | ||
3526 | if (!isdigit(val_buf[0])) | |
3527 | return -EINVAL; | |
3528 | if (sscanf(val_buf, "%i", &val) != 1) | |
3529 | return -EINVAL; | |
3530 | ||
83108bd3 JS |
3531 | if (val >= 0 && val <= 6) { |
3532 | prev_val = phba->cfg_topology; | |
ff78d8f9 JS |
3533 | if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G && |
3534 | val == 4) { | |
3535 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, | |
3536 | "3113 Loop mode not supported at speed %d\n", | |
d38dd52c | 3537 | val); |
ff78d8f9 JS |
3538 | return -EINVAL; |
3539 | } | |
d38dd52c JS |
3540 | if (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC && |
3541 | val == 4) { | |
3542 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, | |
3543 | "3114 Loop mode not supported\n"); | |
3544 | return -EINVAL; | |
3545 | } | |
3546 | phba->cfg_topology = val; | |
a257bf90 JS |
3547 | if (nolip) |
3548 | return strlen(buf); | |
3549 | ||
88a2cfbb JS |
3550 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
3551 | "3054 lpfc_topology changed from %d to %d\n", | |
3552 | prev_val, val); | |
e74c03c8 JS |
3553 | if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4) |
3554 | phba->fc_topology_changed = 1; | |
83108bd3 | 3555 | err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport)); |
a257bf90 | 3556 | if (err) { |
83108bd3 | 3557 | phba->cfg_topology = prev_val; |
a257bf90 JS |
3558 | return -EINVAL; |
3559 | } else | |
3560 | return strlen(buf); | |
83108bd3 JS |
3561 | } |
3562 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3563 | "%d:0467 lpfc_topology attribute cannot be set to %d, " | |
3564 | "allowed range is [0, 6]\n", | |
3565 | phba->brd_no, val); | |
3566 | return -EINVAL; | |
3567 | } | |
0a035439 | 3568 | |
83108bd3 | 3569 | lpfc_param_show(topology) |
ee959b00 | 3570 | static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR, |
83108bd3 | 3571 | lpfc_topology_show, lpfc_topology_store); |
dea3101e | 3572 | |
21e9a0a5 JS |
3573 | /** |
3574 | * lpfc_static_vport_show: Read callback function for | |
3575 | * lpfc_static_vport sysfs file. | |
3576 | * @dev: Pointer to class device object. | |
3577 | * @attr: device attribute structure. | |
3578 | * @buf: Data buffer. | |
3579 | * | |
3580 | * This function is the read call back function for | |
3581 | * lpfc_static_vport sysfs file. The lpfc_static_vport | |
3582 | * sysfs file report the mageability of the vport. | |
3583 | **/ | |
3584 | static ssize_t | |
3585 | lpfc_static_vport_show(struct device *dev, struct device_attribute *attr, | |
3586 | char *buf) | |
3587 | { | |
3588 | struct Scsi_Host *shost = class_to_shost(dev); | |
3589 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
3590 | if (vport->vport_flag & STATIC_VPORT) | |
3591 | sprintf(buf, "1\n"); | |
3592 | else | |
3593 | sprintf(buf, "0\n"); | |
3594 | ||
3595 | return strlen(buf); | |
3596 | } | |
3597 | ||
3598 | /* | |
3599 | * Sysfs attribute to control the statistical data collection. | |
3600 | */ | |
3601 | static DEVICE_ATTR(lpfc_static_vport, S_IRUGO, | |
3602 | lpfc_static_vport_show, NULL); | |
ea2151b4 JS |
3603 | |
3604 | /** | |
3621a710 | 3605 | * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file |
ea2151b4 JS |
3606 | * @dev: Pointer to class device. |
3607 | * @buf: Data buffer. | |
3608 | * @count: Size of the data buffer. | |
3609 | * | |
3610 | * This function get called when an user write to the lpfc_stat_data_ctrl | |
3611 | * sysfs file. This function parse the command written to the sysfs file | |
3612 | * and take appropriate action. These commands are used for controlling | |
3613 | * driver statistical data collection. | |
3614 | * Following are the command this function handles. | |
3615 | * | |
3616 | * setbucket <bucket_type> <base> <step> | |
3617 | * = Set the latency buckets. | |
3618 | * destroybucket = destroy all the buckets. | |
3619 | * start = start data collection | |
3620 | * stop = stop data collection | |
3621 | * reset = reset the collected data | |
3622 | **/ | |
3623 | static ssize_t | |
3624 | lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr, | |
3625 | const char *buf, size_t count) | |
3626 | { | |
3627 | struct Scsi_Host *shost = class_to_shost(dev); | |
3628 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
3629 | struct lpfc_hba *phba = vport->phba; | |
3630 | #define LPFC_MAX_DATA_CTRL_LEN 1024 | |
3631 | static char bucket_data[LPFC_MAX_DATA_CTRL_LEN]; | |
3632 | unsigned long i; | |
3633 | char *str_ptr, *token; | |
3634 | struct lpfc_vport **vports; | |
3635 | struct Scsi_Host *v_shost; | |
3636 | char *bucket_type_str, *base_str, *step_str; | |
3637 | unsigned long base, step, bucket_type; | |
3638 | ||
3639 | if (!strncmp(buf, "setbucket", strlen("setbucket"))) { | |
a257bf90 | 3640 | if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1)) |
ea2151b4 JS |
3641 | return -EINVAL; |
3642 | ||
eb016566 | 3643 | strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN); |
ea2151b4 JS |
3644 | str_ptr = &bucket_data[0]; |
3645 | /* Ignore this token - this is command token */ | |
3646 | token = strsep(&str_ptr, "\t "); | |
3647 | if (!token) | |
3648 | return -EINVAL; | |
3649 | ||
3650 | bucket_type_str = strsep(&str_ptr, "\t "); | |
3651 | if (!bucket_type_str) | |
3652 | return -EINVAL; | |
3653 | ||
3654 | if (!strncmp(bucket_type_str, "linear", strlen("linear"))) | |
3655 | bucket_type = LPFC_LINEAR_BUCKET; | |
3656 | else if (!strncmp(bucket_type_str, "power2", strlen("power2"))) | |
3657 | bucket_type = LPFC_POWER2_BUCKET; | |
3658 | else | |
3659 | return -EINVAL; | |
3660 | ||
3661 | base_str = strsep(&str_ptr, "\t "); | |
3662 | if (!base_str) | |
3663 | return -EINVAL; | |
3664 | base = simple_strtoul(base_str, NULL, 0); | |
3665 | ||
3666 | step_str = strsep(&str_ptr, "\t "); | |
3667 | if (!step_str) | |
3668 | return -EINVAL; | |
3669 | step = simple_strtoul(step_str, NULL, 0); | |
3670 | if (!step) | |
3671 | return -EINVAL; | |
3672 | ||
3673 | /* Block the data collection for every vport */ | |
3674 | vports = lpfc_create_vport_work_array(phba); | |
3675 | if (vports == NULL) | |
3676 | return -ENOMEM; | |
3677 | ||
f4b4c68f | 3678 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
ea2151b4 JS |
3679 | v_shost = lpfc_shost_from_vport(vports[i]); |
3680 | spin_lock_irq(v_shost->host_lock); | |
3681 | /* Block and reset data collection */ | |
3682 | vports[i]->stat_data_blocked = 1; | |
3683 | if (vports[i]->stat_data_enabled) | |
3684 | lpfc_vport_reset_stat_data(vports[i]); | |
3685 | spin_unlock_irq(v_shost->host_lock); | |
3686 | } | |
3687 | ||
3688 | /* Set the bucket attributes */ | |
3689 | phba->bucket_type = bucket_type; | |
3690 | phba->bucket_base = base; | |
3691 | phba->bucket_step = step; | |
3692 | ||
f4b4c68f | 3693 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
ea2151b4 JS |
3694 | v_shost = lpfc_shost_from_vport(vports[i]); |
3695 | ||
3696 | /* Unblock data collection */ | |
3697 | spin_lock_irq(v_shost->host_lock); | |
3698 | vports[i]->stat_data_blocked = 0; | |
3699 | spin_unlock_irq(v_shost->host_lock); | |
3700 | } | |
3701 | lpfc_destroy_vport_work_array(phba, vports); | |
3702 | return strlen(buf); | |
3703 | } | |
3704 | ||
3705 | if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) { | |
3706 | vports = lpfc_create_vport_work_array(phba); | |
3707 | if (vports == NULL) | |
3708 | return -ENOMEM; | |
3709 | ||
f4b4c68f | 3710 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
ea2151b4 JS |
3711 | v_shost = lpfc_shost_from_vport(vports[i]); |
3712 | spin_lock_irq(shost->host_lock); | |
3713 | vports[i]->stat_data_blocked = 1; | |
3714 | lpfc_free_bucket(vport); | |
3715 | vport->stat_data_enabled = 0; | |
3716 | vports[i]->stat_data_blocked = 0; | |
3717 | spin_unlock_irq(shost->host_lock); | |
3718 | } | |
3719 | lpfc_destroy_vport_work_array(phba, vports); | |
3720 | phba->bucket_type = LPFC_NO_BUCKET; | |
3721 | phba->bucket_base = 0; | |
3722 | phba->bucket_step = 0; | |
3723 | return strlen(buf); | |
3724 | } | |
3725 | ||
3726 | if (!strncmp(buf, "start", strlen("start"))) { | |
3727 | /* If no buckets configured return error */ | |
3728 | if (phba->bucket_type == LPFC_NO_BUCKET) | |
3729 | return -EINVAL; | |
3730 | spin_lock_irq(shost->host_lock); | |
3731 | if (vport->stat_data_enabled) { | |
3732 | spin_unlock_irq(shost->host_lock); | |
3733 | return strlen(buf); | |
3734 | } | |
3735 | lpfc_alloc_bucket(vport); | |
3736 | vport->stat_data_enabled = 1; | |
3737 | spin_unlock_irq(shost->host_lock); | |
3738 | return strlen(buf); | |
3739 | } | |
3740 | ||
3741 | if (!strncmp(buf, "stop", strlen("stop"))) { | |
3742 | spin_lock_irq(shost->host_lock); | |
3743 | if (vport->stat_data_enabled == 0) { | |
3744 | spin_unlock_irq(shost->host_lock); | |
3745 | return strlen(buf); | |
3746 | } | |
3747 | lpfc_free_bucket(vport); | |
3748 | vport->stat_data_enabled = 0; | |
3749 | spin_unlock_irq(shost->host_lock); | |
3750 | return strlen(buf); | |
3751 | } | |
3752 | ||
3753 | if (!strncmp(buf, "reset", strlen("reset"))) { | |
3754 | if ((phba->bucket_type == LPFC_NO_BUCKET) | |
3755 | || !vport->stat_data_enabled) | |
3756 | return strlen(buf); | |
3757 | spin_lock_irq(shost->host_lock); | |
3758 | vport->stat_data_blocked = 1; | |
3759 | lpfc_vport_reset_stat_data(vport); | |
3760 | vport->stat_data_blocked = 0; | |
3761 | spin_unlock_irq(shost->host_lock); | |
3762 | return strlen(buf); | |
3763 | } | |
3764 | return -EINVAL; | |
3765 | } | |
3766 | ||
3767 | ||
3768 | /** | |
3621a710 | 3769 | * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file |
ea2151b4 JS |
3770 | * @dev: Pointer to class device object. |
3771 | * @buf: Data buffer. | |
3772 | * | |
3773 | * This function is the read call back function for | |
3774 | * lpfc_stat_data_ctrl sysfs file. This function report the | |
3775 | * current statistical data collection state. | |
3776 | **/ | |
3777 | static ssize_t | |
3778 | lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr, | |
3779 | char *buf) | |
3780 | { | |
3781 | struct Scsi_Host *shost = class_to_shost(dev); | |
3782 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
3783 | struct lpfc_hba *phba = vport->phba; | |
3784 | int index = 0; | |
3785 | int i; | |
3786 | char *bucket_type; | |
3787 | unsigned long bucket_value; | |
3788 | ||
3789 | switch (phba->bucket_type) { | |
3790 | case LPFC_LINEAR_BUCKET: | |
3791 | bucket_type = "linear"; | |
3792 | break; | |
3793 | case LPFC_POWER2_BUCKET: | |
3794 | bucket_type = "power2"; | |
3795 | break; | |
3796 | default: | |
3797 | bucket_type = "No Bucket"; | |
3798 | break; | |
3799 | } | |
3800 | ||
3801 | sprintf(&buf[index], "Statistical Data enabled :%d, " | |
3802 | "blocked :%d, Bucket type :%s, Bucket base :%d," | |
3803 | " Bucket step :%d\nLatency Ranges :", | |
3804 | vport->stat_data_enabled, vport->stat_data_blocked, | |
3805 | bucket_type, phba->bucket_base, phba->bucket_step); | |
3806 | index = strlen(buf); | |
3807 | if (phba->bucket_type != LPFC_NO_BUCKET) { | |
3808 | for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) { | |
3809 | if (phba->bucket_type == LPFC_LINEAR_BUCKET) | |
3810 | bucket_value = phba->bucket_base + | |
3811 | phba->bucket_step * i; | |
3812 | else | |
3813 | bucket_value = phba->bucket_base + | |
3814 | (1 << i) * phba->bucket_step; | |
3815 | ||
3816 | if (index + 10 > PAGE_SIZE) | |
3817 | break; | |
3818 | sprintf(&buf[index], "%08ld ", bucket_value); | |
3819 | index = strlen(buf); | |
3820 | } | |
3821 | } | |
3822 | sprintf(&buf[index], "\n"); | |
3823 | return strlen(buf); | |
3824 | } | |
3825 | ||
3826 | /* | |
3827 | * Sysfs attribute to control the statistical data collection. | |
3828 | */ | |
3829 | static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR, | |
3830 | lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store); | |
3831 | ||
3832 | /* | |
3833 | * lpfc_drvr_stat_data: sysfs attr to get driver statistical data. | |
3834 | */ | |
3835 | ||
3836 | /* | |
3837 | * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN | |
3838 | * for each target. | |
3839 | */ | |
3840 | #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18) | |
3841 | #define MAX_STAT_DATA_SIZE_PER_TARGET \ | |
3842 | STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT) | |
3843 | ||
3844 | ||
3845 | /** | |
3621a710 | 3846 | * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute |
2c3c8bea | 3847 | * @filp: sysfs file |
ea2151b4 JS |
3848 | * @kobj: Pointer to the kernel object |
3849 | * @bin_attr: Attribute object | |
3850 | * @buff: Buffer pointer | |
3851 | * @off: File offset | |
3852 | * @count: Buffer size | |
3853 | * | |
3854 | * This function is the read call back function for lpfc_drvr_stat_data | |
3855 | * sysfs file. This function export the statistical data to user | |
3856 | * applications. | |
3857 | **/ | |
3858 | static ssize_t | |
2c3c8bea CW |
3859 | sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj, |
3860 | struct bin_attribute *bin_attr, | |
ea2151b4 JS |
3861 | char *buf, loff_t off, size_t count) |
3862 | { | |
3863 | struct device *dev = container_of(kobj, struct device, | |
3864 | kobj); | |
3865 | struct Scsi_Host *shost = class_to_shost(dev); | |
3866 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
3867 | struct lpfc_hba *phba = vport->phba; | |
3868 | int i = 0, index = 0; | |
3869 | unsigned long nport_index; | |
3870 | struct lpfc_nodelist *ndlp = NULL; | |
3871 | nport_index = (unsigned long)off / | |
3872 | MAX_STAT_DATA_SIZE_PER_TARGET; | |
3873 | ||
3874 | if (!vport->stat_data_enabled || vport->stat_data_blocked | |
3875 | || (phba->bucket_type == LPFC_NO_BUCKET)) | |
3876 | return 0; | |
3877 | ||
3878 | spin_lock_irq(shost->host_lock); | |
3879 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { | |
3880 | if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data) | |
3881 | continue; | |
3882 | ||
3883 | if (nport_index > 0) { | |
3884 | nport_index--; | |
3885 | continue; | |
3886 | } | |
3887 | ||
3888 | if ((index + MAX_STAT_DATA_SIZE_PER_TARGET) | |
3889 | > count) | |
3890 | break; | |
3891 | ||
3892 | if (!ndlp->lat_data) | |
3893 | continue; | |
3894 | ||
3895 | /* Print the WWN */ | |
3896 | sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:", | |
3897 | ndlp->nlp_portname.u.wwn[0], | |
3898 | ndlp->nlp_portname.u.wwn[1], | |
3899 | ndlp->nlp_portname.u.wwn[2], | |
3900 | ndlp->nlp_portname.u.wwn[3], | |
3901 | ndlp->nlp_portname.u.wwn[4], | |
3902 | ndlp->nlp_portname.u.wwn[5], | |
3903 | ndlp->nlp_portname.u.wwn[6], | |
3904 | ndlp->nlp_portname.u.wwn[7]); | |
3905 | ||
3906 | index = strlen(buf); | |
3907 | ||
3908 | for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) { | |
3909 | sprintf(&buf[index], "%010u,", | |
3910 | ndlp->lat_data[i].cmd_count); | |
3911 | index = strlen(buf); | |
3912 | } | |
3913 | sprintf(&buf[index], "\n"); | |
3914 | index = strlen(buf); | |
3915 | } | |
3916 | spin_unlock_irq(shost->host_lock); | |
3917 | return index; | |
3918 | } | |
3919 | ||
3920 | static struct bin_attribute sysfs_drvr_stat_data_attr = { | |
3921 | .attr = { | |
3922 | .name = "lpfc_drvr_stat_data", | |
3923 | .mode = S_IRUSR, | |
ea2151b4 JS |
3924 | }, |
3925 | .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET, | |
3926 | .read = sysfs_drvr_stat_data_read, | |
3927 | .write = NULL, | |
3928 | }; | |
3929 | ||
dea3101e JB |
3930 | /* |
3931 | # lpfc_link_speed: Link speed selection for initializing the Fibre Channel | |
3932 | # connection. | |
76a95d75 | 3933 | # Value range is [0,16]. Default value is 0. |
dea3101e | 3934 | */ |
e59058c4 | 3935 | /** |
3621a710 | 3936 | * lpfc_link_speed_set - Set the adapters link speed |
e59058c4 JS |
3937 | * @phba: lpfc_hba pointer. |
3938 | * @val: link speed value. | |
3939 | * | |
3940 | * Description: | |
3941 | * If val is in a valid range then set the adapter's link speed field and | |
3942 | * issue a lip; if the lip fails reset the link speed to the old value. | |
3943 | * | |
3944 | * Notes: | |
3945 | * If the value is not in range log a kernel error message and return an error. | |
3946 | * | |
3947 | * Returns: | |
3948 | * zero if val is in range and lip okay. | |
3949 | * non-zero return value from lpfc_issue_lip() | |
3950 | * -EINVAL val out of range | |
3951 | **/ | |
a257bf90 JS |
3952 | static ssize_t |
3953 | lpfc_link_speed_store(struct device *dev, struct device_attribute *attr, | |
3954 | const char *buf, size_t count) | |
83108bd3 | 3955 | { |
a257bf90 JS |
3956 | struct Scsi_Host *shost = class_to_shost(dev); |
3957 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
3958 | struct lpfc_hba *phba = vport->phba; | |
76a95d75 | 3959 | int val = LPFC_USER_LINK_SPEED_AUTO; |
a257bf90 JS |
3960 | int nolip = 0; |
3961 | const char *val_buf = buf; | |
83108bd3 | 3962 | int err; |
c691816e JS |
3963 | uint32_t prev_val, if_type; |
3964 | ||
3965 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); | |
3966 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2 && | |
3967 | phba->hba_flag & HBA_FORCED_LINK_SPEED) | |
3968 | return -EPERM; | |
83108bd3 | 3969 | |
a257bf90 JS |
3970 | if (!strncmp(buf, "nolip ", strlen("nolip "))) { |
3971 | nolip = 1; | |
3972 | val_buf = &buf[strlen("nolip ")]; | |
3973 | } | |
3974 | ||
3975 | if (!isdigit(val_buf[0])) | |
3976 | return -EINVAL; | |
3977 | if (sscanf(val_buf, "%i", &val) != 1) | |
3978 | return -EINVAL; | |
3979 | ||
88a2cfbb JS |
3980 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
3981 | "3055 lpfc_link_speed changed from %d to %d %s\n", | |
3982 | phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)"); | |
3983 | ||
76a95d75 JS |
3984 | if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) || |
3985 | ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) || | |
3986 | ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) || | |
3987 | ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) || | |
3988 | ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) || | |
d38dd52c JS |
3989 | ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) || |
3990 | ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb))) { | |
76a95d75 JS |
3991 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
3992 | "2879 lpfc_link_speed attribute cannot be set " | |
3993 | "to %d. Speed is not supported by this port.\n", | |
3994 | val); | |
83108bd3 | 3995 | return -EINVAL; |
76a95d75 | 3996 | } |
ff78d8f9 JS |
3997 | if (val == LPFC_USER_LINK_SPEED_16G && |
3998 | phba->fc_topology == LPFC_TOPOLOGY_LOOP) { | |
3999 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4000 | "3112 lpfc_link_speed attribute cannot be set " | |
4001 | "to %d. Speed is not supported in loop mode.\n", | |
4002 | val); | |
4003 | return -EINVAL; | |
4004 | } | |
76a95d75 JS |
4005 | if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) && |
4006 | (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) { | |
83108bd3 JS |
4007 | prev_val = phba->cfg_link_speed; |
4008 | phba->cfg_link_speed = val; | |
a257bf90 JS |
4009 | if (nolip) |
4010 | return strlen(buf); | |
4011 | ||
83108bd3 | 4012 | err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport)); |
a257bf90 | 4013 | if (err) { |
83108bd3 | 4014 | phba->cfg_link_speed = prev_val; |
a257bf90 JS |
4015 | return -EINVAL; |
4016 | } else | |
4017 | return strlen(buf); | |
83108bd3 | 4018 | } |
83108bd3 | 4019 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
76a95d75 JS |
4020 | "0469 lpfc_link_speed attribute cannot be set to %d, " |
4021 | "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val); | |
83108bd3 JS |
4022 | return -EINVAL; |
4023 | } | |
4024 | ||
4025 | static int lpfc_link_speed = 0; | |
ab56dc2e | 4026 | module_param(lpfc_link_speed, int, S_IRUGO); |
83108bd3 JS |
4027 | MODULE_PARM_DESC(lpfc_link_speed, "Select link speed"); |
4028 | lpfc_param_show(link_speed) | |
e59058c4 JS |
4029 | |
4030 | /** | |
3621a710 | 4031 | * lpfc_link_speed_init - Set the adapters link speed |
e59058c4 JS |
4032 | * @phba: lpfc_hba pointer. |
4033 | * @val: link speed value. | |
4034 | * | |
4035 | * Description: | |
4036 | * If val is in a valid range then set the adapter's link speed field. | |
4037 | * | |
4038 | * Notes: | |
4039 | * If the value is not in range log a kernel error message, clear the link | |
4040 | * speed and return an error. | |
4041 | * | |
4042 | * Returns: | |
4043 | * zero if val saved. | |
4044 | * -EINVAL val out of range | |
4045 | **/ | |
83108bd3 JS |
4046 | static int |
4047 | lpfc_link_speed_init(struct lpfc_hba *phba, int val) | |
4048 | { | |
ff78d8f9 JS |
4049 | if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) { |
4050 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4051 | "3111 lpfc_link_speed of %d cannot " | |
4052 | "support loop mode, setting topology to default.\n", | |
4053 | val); | |
4054 | phba->cfg_topology = 0; | |
4055 | } | |
76a95d75 JS |
4056 | if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) && |
4057 | (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) { | |
83108bd3 JS |
4058 | phba->cfg_link_speed = val; |
4059 | return 0; | |
4060 | } | |
4061 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
d7c255b2 | 4062 | "0405 lpfc_link_speed attribute cannot " |
83108bd3 JS |
4063 | "be set to %d, allowed values are " |
4064 | "["LPFC_LINK_SPEED_STRING"]\n", val); | |
76a95d75 | 4065 | phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO; |
83108bd3 JS |
4066 | return -EINVAL; |
4067 | } | |
4068 | ||
ee959b00 | 4069 | static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR, |
76a95d75 | 4070 | lpfc_link_speed_show, lpfc_link_speed_store); |
dea3101e | 4071 | |
0d878419 JS |
4072 | /* |
4073 | # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER) | |
4074 | # 0 = aer disabled or not supported | |
4075 | # 1 = aer supported and enabled (default) | |
4076 | # Value range is [0,1]. Default value is 1. | |
4077 | */ | |
506139a2 JS |
4078 | LPFC_ATTR(aer_support, 1, 0, 1, |
4079 | "Enable PCIe device AER support"); | |
4080 | lpfc_param_show(aer_support) | |
0d878419 JS |
4081 | |
4082 | /** | |
4083 | * lpfc_aer_support_store - Set the adapter for aer support | |
4084 | * | |
4085 | * @dev: class device that is converted into a Scsi_host. | |
4086 | * @attr: device attribute, not used. | |
912e3acd | 4087 | * @buf: containing enable or disable aer flag. |
0d878419 JS |
4088 | * @count: unused variable. |
4089 | * | |
4090 | * Description: | |
4091 | * If the val is 1 and currently the device's AER capability was not | |
4092 | * enabled, invoke the kernel's enable AER helper routine, trying to | |
4093 | * enable the device's AER capability. If the helper routine enabling | |
4094 | * AER returns success, update the device's cfg_aer_support flag to | |
4095 | * indicate AER is supported by the device; otherwise, if the device | |
4096 | * AER capability is already enabled to support AER, then do nothing. | |
4097 | * | |
4098 | * If the val is 0 and currently the device's AER support was enabled, | |
4099 | * invoke the kernel's disable AER helper routine. After that, update | |
4100 | * the device's cfg_aer_support flag to indicate AER is not supported | |
4101 | * by the device; otherwise, if the device AER capability is already | |
4102 | * disabled from supporting AER, then do nothing. | |
4103 | * | |
4104 | * Returns: | |
4105 | * length of the buf on success if val is in range the intended mode | |
4106 | * is supported. | |
4107 | * -EINVAL if val out of range or intended mode is not supported. | |
4108 | **/ | |
4109 | static ssize_t | |
4110 | lpfc_aer_support_store(struct device *dev, struct device_attribute *attr, | |
4111 | const char *buf, size_t count) | |
4112 | { | |
4113 | struct Scsi_Host *shost = class_to_shost(dev); | |
4114 | struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; | |
4115 | struct lpfc_hba *phba = vport->phba; | |
4116 | int val = 0, rc = -EINVAL; | |
4117 | ||
4118 | if (!isdigit(buf[0])) | |
4119 | return -EINVAL; | |
4120 | if (sscanf(buf, "%i", &val) != 1) | |
4121 | return -EINVAL; | |
4122 | ||
4123 | switch (val) { | |
4124 | case 0: | |
4125 | if (phba->hba_flag & HBA_AER_ENABLED) { | |
4126 | rc = pci_disable_pcie_error_reporting(phba->pcidev); | |
4127 | if (!rc) { | |
4128 | spin_lock_irq(&phba->hbalock); | |
4129 | phba->hba_flag &= ~HBA_AER_ENABLED; | |
4130 | spin_unlock_irq(&phba->hbalock); | |
4131 | phba->cfg_aer_support = 0; | |
4132 | rc = strlen(buf); | |
4133 | } else | |
891478a2 JS |
4134 | rc = -EPERM; |
4135 | } else { | |
0d878419 | 4136 | phba->cfg_aer_support = 0; |
891478a2 JS |
4137 | rc = strlen(buf); |
4138 | } | |
0d878419 JS |
4139 | break; |
4140 | case 1: | |
4141 | if (!(phba->hba_flag & HBA_AER_ENABLED)) { | |
4142 | rc = pci_enable_pcie_error_reporting(phba->pcidev); | |
4143 | if (!rc) { | |
4144 | spin_lock_irq(&phba->hbalock); | |
4145 | phba->hba_flag |= HBA_AER_ENABLED; | |
4146 | spin_unlock_irq(&phba->hbalock); | |
4147 | phba->cfg_aer_support = 1; | |
4148 | rc = strlen(buf); | |
4149 | } else | |
891478a2 JS |
4150 | rc = -EPERM; |
4151 | } else { | |
0d878419 | 4152 | phba->cfg_aer_support = 1; |
891478a2 JS |
4153 | rc = strlen(buf); |
4154 | } | |
0d878419 JS |
4155 | break; |
4156 | default: | |
4157 | rc = -EINVAL; | |
4158 | break; | |
4159 | } | |
4160 | return rc; | |
4161 | } | |
4162 | ||
0d878419 JS |
4163 | static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR, |
4164 | lpfc_aer_support_show, lpfc_aer_support_store); | |
4165 | ||
4166 | /** | |
4167 | * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device | |
4168 | * @dev: class device that is converted into a Scsi_host. | |
4169 | * @attr: device attribute, not used. | |
912e3acd | 4170 | * @buf: containing flag 1 for aer cleanup state. |
0d878419 JS |
4171 | * @count: unused variable. |
4172 | * | |
4173 | * Description: | |
4174 | * If the @buf contains 1 and the device currently has the AER support | |
4175 | * enabled, then invokes the kernel AER helper routine | |
4176 | * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable | |
4177 | * error status register. | |
4178 | * | |
4179 | * Notes: | |
4180 | * | |
4181 | * Returns: | |
4182 | * -EINVAL if the buf does not contain the 1 or the device is not currently | |
4183 | * enabled with the AER support. | |
4184 | **/ | |
4185 | static ssize_t | |
4186 | lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr, | |
4187 | const char *buf, size_t count) | |
4188 | { | |
4189 | struct Scsi_Host *shost = class_to_shost(dev); | |
4190 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
4191 | struct lpfc_hba *phba = vport->phba; | |
4192 | int val, rc = -1; | |
4193 | ||
4194 | if (!isdigit(buf[0])) | |
4195 | return -EINVAL; | |
4196 | if (sscanf(buf, "%i", &val) != 1) | |
4197 | return -EINVAL; | |
891478a2 JS |
4198 | if (val != 1) |
4199 | return -EINVAL; | |
0d878419 | 4200 | |
891478a2 | 4201 | if (phba->hba_flag & HBA_AER_ENABLED) |
0d878419 JS |
4202 | rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev); |
4203 | ||
4204 | if (rc == 0) | |
4205 | return strlen(buf); | |
4206 | else | |
891478a2 | 4207 | return -EPERM; |
0d878419 JS |
4208 | } |
4209 | ||
4210 | static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL, | |
4211 | lpfc_aer_cleanup_state); | |
4212 | ||
912e3acd JS |
4213 | /** |
4214 | * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions | |
4215 | * | |
4216 | * @dev: class device that is converted into a Scsi_host. | |
4217 | * @attr: device attribute, not used. | |
4218 | * @buf: containing the string the number of vfs to be enabled. | |
4219 | * @count: unused variable. | |
4220 | * | |
4221 | * Description: | |
4222 | * When this api is called either through user sysfs, the driver shall | |
4223 | * try to enable or disable SR-IOV virtual functions according to the | |
4224 | * following: | |
4225 | * | |
4226 | * If zero virtual function has been enabled to the physical function, | |
4227 | * the driver shall invoke the pci enable virtual function api trying | |
4228 | * to enable the virtual functions. If the nr_vfn provided is greater | |
4229 | * than the maximum supported, the maximum virtual function number will | |
4230 | * be used for invoking the api; otherwise, the nr_vfn provided shall | |
4231 | * be used for invoking the api. If the api call returned success, the | |
4232 | * actual number of virtual functions enabled will be set to the driver | |
4233 | * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver | |
4234 | * cfg_sriov_nr_virtfn remains zero. | |
4235 | * | |
4236 | * If none-zero virtual functions have already been enabled to the | |
4237 | * physical function, as reflected by the driver's cfg_sriov_nr_virtfn, | |
4238 | * -EINVAL will be returned and the driver does nothing; | |
4239 | * | |
4240 | * If the nr_vfn provided is zero and none-zero virtual functions have | |
4241 | * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the | |
4242 | * disabling virtual function api shall be invoded to disable all the | |
4243 | * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to | |
4244 | * zero. Otherwise, if zero virtual function has been enabled, do | |
4245 | * nothing. | |
4246 | * | |
4247 | * Returns: | |
4248 | * length of the buf on success if val is in range the intended mode | |
4249 | * is supported. | |
4250 | * -EINVAL if val out of range or intended mode is not supported. | |
4251 | **/ | |
4252 | static ssize_t | |
4253 | lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr, | |
4254 | const char *buf, size_t count) | |
4255 | { | |
4256 | struct Scsi_Host *shost = class_to_shost(dev); | |
4257 | struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; | |
4258 | struct lpfc_hba *phba = vport->phba; | |
4259 | struct pci_dev *pdev = phba->pcidev; | |
4260 | int val = 0, rc = -EINVAL; | |
4261 | ||
4262 | /* Sanity check on user data */ | |
4263 | if (!isdigit(buf[0])) | |
4264 | return -EINVAL; | |
4265 | if (sscanf(buf, "%i", &val) != 1) | |
4266 | return -EINVAL; | |
4267 | if (val < 0) | |
4268 | return -EINVAL; | |
4269 | ||
4270 | /* Request disabling virtual functions */ | |
4271 | if (val == 0) { | |
4272 | if (phba->cfg_sriov_nr_virtfn > 0) { | |
4273 | pci_disable_sriov(pdev); | |
4274 | phba->cfg_sriov_nr_virtfn = 0; | |
4275 | } | |
4276 | return strlen(buf); | |
4277 | } | |
4278 | ||
4279 | /* Request enabling virtual functions */ | |
4280 | if (phba->cfg_sriov_nr_virtfn > 0) { | |
4281 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4282 | "3018 There are %d virtual functions " | |
4283 | "enabled on physical function.\n", | |
4284 | phba->cfg_sriov_nr_virtfn); | |
4285 | return -EEXIST; | |
4286 | } | |
4287 | ||
4288 | if (val <= LPFC_MAX_VFN_PER_PFN) | |
4289 | phba->cfg_sriov_nr_virtfn = val; | |
4290 | else { | |
4291 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4292 | "3019 Enabling %d virtual functions is not " | |
4293 | "allowed.\n", val); | |
4294 | return -EINVAL; | |
4295 | } | |
4296 | ||
4297 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn); | |
4298 | if (rc) { | |
4299 | phba->cfg_sriov_nr_virtfn = 0; | |
4300 | rc = -EPERM; | |
4301 | } else | |
4302 | rc = strlen(buf); | |
4303 | ||
4304 | return rc; | |
4305 | } | |
4306 | ||
0cfbbf2f JS |
4307 | LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN, |
4308 | "Enable PCIe device SR-IOV virtual fn"); | |
912e3acd | 4309 | |
0cfbbf2f | 4310 | lpfc_param_show(sriov_nr_virtfn) |
912e3acd JS |
4311 | static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR, |
4312 | lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store); | |
4313 | ||
c71ab861 JS |
4314 | /** |
4315 | * lpfc_request_firmware_store - Request for Linux generic firmware upgrade | |
4316 | * | |
4317 | * @dev: class device that is converted into a Scsi_host. | |
4318 | * @attr: device attribute, not used. | |
4319 | * @buf: containing the string the number of vfs to be enabled. | |
4320 | * @count: unused variable. | |
4321 | * | |
4322 | * Description: | |
4323 | * | |
4324 | * Returns: | |
4325 | * length of the buf on success if val is in range the intended mode | |
4326 | * is supported. | |
4327 | * -EINVAL if val out of range or intended mode is not supported. | |
4328 | **/ | |
4329 | static ssize_t | |
4330 | lpfc_request_firmware_upgrade_store(struct device *dev, | |
4331 | struct device_attribute *attr, | |
4332 | const char *buf, size_t count) | |
4333 | { | |
4334 | struct Scsi_Host *shost = class_to_shost(dev); | |
4335 | struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; | |
4336 | struct lpfc_hba *phba = vport->phba; | |
4337 | int val = 0, rc = -EINVAL; | |
4338 | ||
4339 | /* Sanity check on user data */ | |
4340 | if (!isdigit(buf[0])) | |
4341 | return -EINVAL; | |
4342 | if (sscanf(buf, "%i", &val) != 1) | |
4343 | return -EINVAL; | |
4344 | if (val != 1) | |
4345 | return -EINVAL; | |
4346 | ||
4347 | rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE); | |
4348 | if (rc) | |
4349 | rc = -EPERM; | |
4350 | else | |
4351 | rc = strlen(buf); | |
4352 | return rc; | |
4353 | } | |
4354 | ||
4355 | static int lpfc_req_fw_upgrade; | |
4356 | module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR); | |
4357 | MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade"); | |
4358 | lpfc_param_show(request_firmware_upgrade) | |
4359 | ||
4360 | /** | |
4361 | * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade | |
4362 | * @phba: lpfc_hba pointer. | |
4363 | * @val: 0 or 1. | |
4364 | * | |
4365 | * Description: | |
4366 | * Set the initial Linux generic firmware upgrade enable or disable flag. | |
4367 | * | |
4368 | * Returns: | |
4369 | * zero if val saved. | |
4370 | * -EINVAL val out of range | |
4371 | **/ | |
4372 | static int | |
4373 | lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val) | |
4374 | { | |
4375 | if (val >= 0 && val <= 1) { | |
4376 | phba->cfg_request_firmware_upgrade = val; | |
4377 | return 0; | |
4378 | } | |
4379 | return -EINVAL; | |
4380 | } | |
4381 | static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR, | |
4382 | lpfc_request_firmware_upgrade_show, | |
4383 | lpfc_request_firmware_upgrade_store); | |
4384 | ||
173edbb2 JS |
4385 | /** |
4386 | * lpfc_fcp_imax_store | |
4387 | * | |
4388 | * @dev: class device that is converted into a Scsi_host. | |
4389 | * @attr: device attribute, not used. | |
4390 | * @buf: string with the number of fast-path FCP interrupts per second. | |
4391 | * @count: unused variable. | |
4392 | * | |
4393 | * Description: | |
4394 | * If val is in a valid range [636,651042], then set the adapter's | |
4395 | * maximum number of fast-path FCP interrupts per second. | |
4396 | * | |
4397 | * Returns: | |
4398 | * length of the buf on success if val is in range the intended mode | |
4399 | * is supported. | |
4400 | * -EINVAL if val out of range or intended mode is not supported. | |
4401 | **/ | |
4402 | static ssize_t | |
4403 | lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr, | |
4404 | const char *buf, size_t count) | |
4405 | { | |
4406 | struct Scsi_Host *shost = class_to_shost(dev); | |
4407 | struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; | |
4408 | struct lpfc_hba *phba = vport->phba; | |
4409 | int val = 0, i; | |
4410 | ||
bf8dae83 JS |
4411 | /* fcp_imax is only valid for SLI4 */ |
4412 | if (phba->sli_rev != LPFC_SLI_REV4) | |
4413 | return -EINVAL; | |
4414 | ||
173edbb2 JS |
4415 | /* Sanity check on user data */ |
4416 | if (!isdigit(buf[0])) | |
4417 | return -EINVAL; | |
4418 | if (sscanf(buf, "%i", &val) != 1) | |
4419 | return -EINVAL; | |
4420 | ||
bf8dae83 JS |
4421 | /* |
4422 | * Value range for the HBA is [5000,5000000] | |
4423 | * The value for each EQ depends on how many EQs are configured. | |
895427bd | 4424 | * Allow value == 0 |
bf8dae83 | 4425 | */ |
895427bd | 4426 | if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX)) |
173edbb2 JS |
4427 | return -EINVAL; |
4428 | ||
4429 | phba->cfg_fcp_imax = (uint32_t)val; | |
895427bd JS |
4430 | for (i = 0; i < phba->io_channel_irqs; i++) |
4431 | lpfc_modify_hba_eq_delay(phba, i); | |
173edbb2 JS |
4432 | |
4433 | return strlen(buf); | |
4434 | } | |
4435 | ||
4436 | /* | |
4437 | # lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second | |
bf8dae83 | 4438 | # for the HBA. |
173edbb2 | 4439 | # |
bf8dae83 | 4440 | # Value range is [5,000 to 5,000,000]. Default value is 50,000. |
173edbb2 | 4441 | */ |
bf8dae83 | 4442 | static int lpfc_fcp_imax = LPFC_DEF_IMAX; |
173edbb2 JS |
4443 | module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR); |
4444 | MODULE_PARM_DESC(lpfc_fcp_imax, | |
bf8dae83 | 4445 | "Set the maximum number of FCP interrupts per second per HBA"); |
173edbb2 JS |
4446 | lpfc_param_show(fcp_imax) |
4447 | ||
4448 | /** | |
4449 | * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable | |
4450 | * @phba: lpfc_hba pointer. | |
4451 | * @val: link speed value. | |
4452 | * | |
4453 | * Description: | |
4454 | * If val is in a valid range [636,651042], then initialize the adapter's | |
4455 | * maximum number of fast-path FCP interrupts per second. | |
4456 | * | |
4457 | * Returns: | |
4458 | * zero if val saved. | |
4459 | * -EINVAL val out of range | |
4460 | **/ | |
4461 | static int | |
4462 | lpfc_fcp_imax_init(struct lpfc_hba *phba, int val) | |
4463 | { | |
bf8dae83 JS |
4464 | if (phba->sli_rev != LPFC_SLI_REV4) { |
4465 | phba->cfg_fcp_imax = 0; | |
4466 | return 0; | |
4467 | } | |
4468 | ||
895427bd JS |
4469 | if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) || |
4470 | (val == 0)) { | |
173edbb2 JS |
4471 | phba->cfg_fcp_imax = val; |
4472 | return 0; | |
4473 | } | |
4474 | ||
4475 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6c86068d JS |
4476 | "3016 lpfc_fcp_imax: %d out of range, using default\n", |
4477 | val); | |
bf8dae83 | 4478 | phba->cfg_fcp_imax = LPFC_DEF_IMAX; |
173edbb2 JS |
4479 | |
4480 | return 0; | |
4481 | } | |
4482 | ||
4483 | static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR, | |
4484 | lpfc_fcp_imax_show, lpfc_fcp_imax_store); | |
4485 | ||
7bb03bbf JS |
4486 | /** |
4487 | * lpfc_state_show - Display current driver CPU affinity | |
4488 | * @dev: class converted to a Scsi_host structure. | |
4489 | * @attr: device attribute, not used. | |
4490 | * @buf: on return contains text describing the state of the link. | |
4491 | * | |
4492 | * Returns: size of formatted string. | |
4493 | **/ | |
4494 | static ssize_t | |
4495 | lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr, | |
4496 | char *buf) | |
4497 | { | |
4498 | struct Scsi_Host *shost = class_to_shost(dev); | |
4499 | struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; | |
4500 | struct lpfc_hba *phba = vport->phba; | |
4501 | struct lpfc_vector_map_info *cpup; | |
76fd07a6 | 4502 | int len = 0; |
7bb03bbf JS |
4503 | |
4504 | if ((phba->sli_rev != LPFC_SLI_REV4) || | |
4505 | (phba->intr_type != MSIX)) | |
4506 | return len; | |
4507 | ||
4508 | switch (phba->cfg_fcp_cpu_map) { | |
4509 | case 0: | |
4510 | len += snprintf(buf + len, PAGE_SIZE-len, | |
4511 | "fcp_cpu_map: No mapping (%d)\n", | |
4512 | phba->cfg_fcp_cpu_map); | |
4513 | return len; | |
4514 | case 1: | |
4515 | len += snprintf(buf + len, PAGE_SIZE-len, | |
4516 | "fcp_cpu_map: HBA centric mapping (%d): " | |
4517 | "%d online CPUs\n", | |
4518 | phba->cfg_fcp_cpu_map, | |
4519 | phba->sli4_hba.num_online_cpu); | |
4520 | break; | |
4521 | case 2: | |
4522 | len += snprintf(buf + len, PAGE_SIZE-len, | |
4523 | "fcp_cpu_map: Driver centric mapping (%d): " | |
4524 | "%d online CPUs\n", | |
4525 | phba->cfg_fcp_cpu_map, | |
4526 | phba->sli4_hba.num_online_cpu); | |
4527 | break; | |
4528 | } | |
4529 | ||
76fd07a6 JS |
4530 | while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) { |
4531 | cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu]; | |
4532 | ||
4533 | /* margin should fit in this and the truncated message */ | |
7bb03bbf JS |
4534 | if (cpup->irq == LPFC_VECTOR_MAP_EMPTY) |
4535 | len += snprintf(buf + len, PAGE_SIZE-len, | |
4536 | "CPU %02d io_chan %02d " | |
4537 | "physid %d coreid %d\n", | |
76fd07a6 JS |
4538 | phba->sli4_hba.curr_disp_cpu, |
4539 | cpup->channel_id, cpup->phys_id, | |
7bb03bbf JS |
4540 | cpup->core_id); |
4541 | else | |
4542 | len += snprintf(buf + len, PAGE_SIZE-len, | |
4543 | "CPU %02d io_chan %02d " | |
4544 | "physid %d coreid %d IRQ %d\n", | |
76fd07a6 JS |
4545 | phba->sli4_hba.curr_disp_cpu, |
4546 | cpup->channel_id, cpup->phys_id, | |
7bb03bbf JS |
4547 | cpup->core_id, cpup->irq); |
4548 | ||
76fd07a6 JS |
4549 | phba->sli4_hba.curr_disp_cpu++; |
4550 | ||
4551 | /* display max number of CPUs keeping some margin */ | |
4552 | if (phba->sli4_hba.curr_disp_cpu < | |
4553 | phba->sli4_hba.num_present_cpu && | |
4554 | (len >= (PAGE_SIZE - 64))) { | |
4555 | len += snprintf(buf + len, PAGE_SIZE-len, "more...\n"); | |
4556 | break; | |
4557 | } | |
7bb03bbf | 4558 | } |
76fd07a6 JS |
4559 | |
4560 | if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu) | |
4561 | phba->sli4_hba.curr_disp_cpu = 0; | |
4562 | ||
7bb03bbf JS |
4563 | return len; |
4564 | } | |
4565 | ||
4566 | /** | |
4567 | * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors | |
4568 | * @dev: class device that is converted into a Scsi_host. | |
4569 | * @attr: device attribute, not used. | |
4570 | * @buf: one or more lpfc_polling_flags values. | |
4571 | * @count: not used. | |
4572 | * | |
4573 | * Returns: | |
4574 | * -EINVAL - Not implemented yet. | |
4575 | **/ | |
4576 | static ssize_t | |
4577 | lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr, | |
4578 | const char *buf, size_t count) | |
4579 | { | |
4580 | int status = -EINVAL; | |
4581 | return status; | |
4582 | } | |
4583 | ||
4584 | /* | |
4585 | # lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors | |
4586 | # for the HBA. | |
4587 | # | |
4588 | # Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2). | |
4589 | # 0 - Do not affinitze IRQ vectors | |
4590 | # 1 - Affintize HBA vectors with respect to each HBA | |
4591 | # (start with CPU0 for each HBA) | |
4592 | # 2 - Affintize HBA vectors with respect to the entire driver | |
4593 | # (round robin thru all CPUs across all HBAs) | |
4594 | */ | |
4595 | static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP; | |
4596 | module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR); | |
4597 | MODULE_PARM_DESC(lpfc_fcp_cpu_map, | |
4598 | "Defines how to map CPUs to IRQ vectors per HBA"); | |
4599 | ||
4600 | /** | |
4601 | * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable | |
4602 | * @phba: lpfc_hba pointer. | |
4603 | * @val: link speed value. | |
4604 | * | |
4605 | * Description: | |
4606 | * If val is in a valid range [0-2], then affinitze the adapter's | |
4607 | * MSIX vectors. | |
4608 | * | |
4609 | * Returns: | |
4610 | * zero if val saved. | |
4611 | * -EINVAL val out of range | |
4612 | **/ | |
4613 | static int | |
4614 | lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val) | |
4615 | { | |
4616 | if (phba->sli_rev != LPFC_SLI_REV4) { | |
4617 | phba->cfg_fcp_cpu_map = 0; | |
4618 | return 0; | |
4619 | } | |
4620 | ||
4621 | if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) { | |
4622 | phba->cfg_fcp_cpu_map = val; | |
4623 | return 0; | |
4624 | } | |
4625 | ||
4626 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6c86068d JS |
4627 | "3326 lpfc_fcp_cpu_map: %d out of range, using " |
4628 | "default\n", val); | |
7bb03bbf JS |
4629 | phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP; |
4630 | ||
4631 | return 0; | |
4632 | } | |
4633 | ||
4634 | static DEVICE_ATTR(lpfc_fcp_cpu_map, S_IRUGO | S_IWUSR, | |
4635 | lpfc_fcp_cpu_map_show, lpfc_fcp_cpu_map_store); | |
4636 | ||
dea3101e JB |
4637 | /* |
4638 | # lpfc_fcp_class: Determines FC class to use for the FCP protocol. | |
4639 | # Value range is [2,3]. Default value is 3. | |
4640 | */ | |
3de2a653 JS |
4641 | LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3, |
4642 | "Select Fibre Channel class of service for FCP sequences"); | |
dea3101e JB |
4643 | |
4644 | /* | |
4645 | # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range | |
4646 | # is [0,1]. Default value is 0. | |
4647 | */ | |
3de2a653 JS |
4648 | LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1, |
4649 | "Use ADISC on rediscovery to authenticate FCP devices"); | |
dea3101e | 4650 | |
3cb01c57 JS |
4651 | /* |
4652 | # lpfc_first_burst_size: First burst size to use on the NPorts | |
4653 | # that support first burst. | |
4654 | # Value range is [0,65536]. Default value is 0. | |
4655 | */ | |
4656 | LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536, | |
4657 | "First burst size for Targets that support first burst"); | |
4658 | ||
895427bd JS |
4659 | /* |
4660 | * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions. | |
4661 | * For the Initiator (I), enabling this parameter means that an NVME | |
4662 | * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value | |
4663 | * will be processed by the initiator for subsequent NVME FCP IO. | |
4664 | * Parameter supported on physical port only - no NPIV support. | |
4665 | * Value range is [0,1]. Default value is 0 (disabled). | |
4666 | */ | |
4667 | LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1, | |
4668 | "Enable First Burst feature on I and T functions."); | |
4669 | ||
977b5a0a JS |
4670 | /* |
4671 | # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue | |
4672 | # depth. Default value is 0. When the value of this parameter is zero the | |
4673 | # SCSI command completion time is not used for controlling I/O queue depth. When | |
4674 | # the parameter is set to a non-zero value, the I/O queue depth is controlled | |
4675 | # to limit the I/O completion time to the parameter value. | |
4676 | # The value is set in milliseconds. | |
4677 | */ | |
ed5b1529 | 4678 | LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000, |
977b5a0a | 4679 | "Use command completion time to control queue depth"); |
ed5b1529 | 4680 | |
977b5a0a | 4681 | lpfc_vport_param_show(max_scsicmpl_time); |
977b5a0a JS |
4682 | static int |
4683 | lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val) | |
4684 | { | |
4685 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
4686 | struct lpfc_nodelist *ndlp, *next_ndlp; | |
4687 | ||
4688 | if (val == vport->cfg_max_scsicmpl_time) | |
4689 | return 0; | |
4690 | if ((val < 0) || (val > 60000)) | |
4691 | return -EINVAL; | |
4692 | vport->cfg_max_scsicmpl_time = val; | |
4693 | ||
4694 | spin_lock_irq(shost->host_lock); | |
4695 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { | |
4696 | if (!NLP_CHK_NODE_ACT(ndlp)) | |
4697 | continue; | |
4698 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) | |
4699 | continue; | |
7dc517df | 4700 | ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth; |
977b5a0a JS |
4701 | } |
4702 | spin_unlock_irq(shost->host_lock); | |
4703 | return 0; | |
4704 | } | |
4705 | lpfc_vport_param_store(max_scsicmpl_time); | |
4706 | static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR, | |
4707 | lpfc_max_scsicmpl_time_show, | |
4708 | lpfc_max_scsicmpl_time_store); | |
4709 | ||
dea3101e JB |
4710 | /* |
4711 | # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value | |
4712 | # range is [0,1]. Default value is 0. | |
4713 | */ | |
4714 | LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support"); | |
4715 | ||
49aa143d | 4716 | /* |
895427bd JS |
4717 | * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds |
4718 | * range is [0,1]. Default value is 0. | |
4719 | * For [0], FCP commands are issued to Work Queues ina round robin fashion. | |
4720 | * For [1], FCP commands are issued to a Work Queue associated with the | |
4721 | * current CPU. | |
4722 | * | |
4723 | * LPFC_FCP_SCHED_ROUND_ROBIN == 0 | |
4724 | * LPFC_FCP_SCHED_BY_CPU == 1 | |
4725 | * | |
4726 | * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu | |
4727 | * affinity for FCP/NVME I/Os through Work Queues associated with the current | |
4728 | * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os | |
4729 | * through WQs will be used. | |
4730 | */ | |
4731 | LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_ROUND_ROBIN, | |
4732 | LPFC_FCP_SCHED_ROUND_ROBIN, | |
4733 | LPFC_FCP_SCHED_BY_CPU, | |
4734 | "Determine scheduling algorithm for " | |
4735 | "issuing commands [0] - Round Robin, [1] - Current CPU"); | |
49aa143d | 4736 | |
a6571c6e JS |
4737 | /* |
4738 | # lpfc_fcp2_no_tgt_reset: Determine bus reset behavior | |
4739 | # range is [0,1]. Default value is 0. | |
4740 | # For [0], bus reset issues target reset to ALL devices | |
4741 | # For [1], bus reset issues target reset to non-FCP2 devices | |
4742 | */ | |
4743 | LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for " | |
4744 | "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset"); | |
4745 | ||
4746 | ||
dea3101e JB |
4747 | /* |
4748 | # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing | |
4749 | # cr_delay (msec) or cr_count outstanding commands. cr_delay can take | |
7054a606 | 4750 | # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay |
dea3101e JB |
4751 | # is 0. Default value of cr_count is 1. The cr_count feature is disabled if |
4752 | # cr_delay is set to 0. | |
4753 | */ | |
8189fd19 | 4754 | LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an " |
dea3101e JB |
4755 | "interrupt response is generated"); |
4756 | ||
8189fd19 | 4757 | LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an " |
dea3101e JB |
4758 | "interrupt response is generated"); |
4759 | ||
cf5bf97e JW |
4760 | /* |
4761 | # lpfc_multi_ring_support: Determines how many rings to spread available | |
4762 | # cmd/rsp IOCB entries across. | |
4763 | # Value range is [1,2]. Default value is 1. | |
4764 | */ | |
4765 | LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary " | |
4766 | "SLI rings to spread IOCB entries across"); | |
4767 | ||
a4bc3379 JS |
4768 | /* |
4769 | # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this | |
4770 | # identifies what rctl value to configure the additional ring for. | |
4771 | # Value range is [1,0xff]. Default value is 4 (Unsolicated Data). | |
4772 | */ | |
6a9c52cf | 4773 | LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1, |
a4bc3379 JS |
4774 | 255, "Identifies RCTL for additional ring configuration"); |
4775 | ||
4776 | /* | |
4777 | # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this | |
4778 | # identifies what type value to configure the additional ring for. | |
4779 | # Value range is [1,0xff]. Default value is 5 (LLC/SNAP). | |
4780 | */ | |
6a9c52cf | 4781 | LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1, |
a4bc3379 JS |
4782 | 255, "Identifies TYPE for additional ring configuration"); |
4783 | ||
dea3101e | 4784 | /* |
4258e98e JS |
4785 | # lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN |
4786 | # 0 = SmartSAN functionality disabled (default) | |
4787 | # 1 = SmartSAN functionality enabled | |
4788 | # This parameter will override the value of lpfc_fdmi_on module parameter. | |
4789 | # Value range is [0,1]. Default value is 0. | |
dea3101e | 4790 | */ |
4258e98e JS |
4791 | LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality"); |
4792 | ||
4793 | /* | |
4794 | # lpfc_fdmi_on: Controls FDMI support. | |
4795 | # 0 No FDMI support (default) | |
4796 | # 1 Traditional FDMI support | |
8663cbbe JS |
4797 | # Traditional FDMI support means the driver will assume FDMI-2 support; |
4798 | # however, if that fails, it will fallback to FDMI-1. | |
4799 | # If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on. | |
4800 | # If lpfc_enable_SmartSAN is set 0, the driver uses the current value of | |
4801 | # lpfc_fdmi_on. | |
4802 | # Value range [0,1]. Default value is 0. | |
4258e98e | 4803 | */ |
8663cbbe | 4804 | LPFC_ATTR_R(fdmi_on, 0, 0, 1, "Enable FDMI support"); |
dea3101e JB |
4805 | |
4806 | /* | |
4807 | # Specifies the maximum number of ELS cmds we can have outstanding (for | |
4808 | # discovery). Value range is [1,64]. Default value = 32. | |
4809 | */ | |
3de2a653 | 4810 | LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands " |
dea3101e JB |
4811 | "during discovery"); |
4812 | ||
4813 | /* | |
c4a7c922 JS |
4814 | # lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that |
4815 | # will be scanned by the SCSI midlayer when sequential scanning is | |
4816 | # used; and is also the highest LUN ID allowed when the SCSI midlayer | |
4817 | # parses REPORT_LUN responses. The lpfc driver has no LUN count or | |
4818 | # LUN ID limit, but the SCSI midlayer requires this field for the uses | |
4819 | # above. The lpfc driver limits the default value to 255 for two reasons. | |
4820 | # As it bounds the sequential scan loop, scanning for thousands of luns | |
4821 | # on a target can take minutes of wall clock time. Additionally, | |
4822 | # there are FC targets, such as JBODs, that only recognize 8-bits of | |
4823 | # LUN ID. When they receive a value greater than 8 bits, they chop off | |
4824 | # the high order bits. In other words, they see LUN IDs 0, 256, 512, | |
4825 | # and so on all as LUN ID 0. This causes the linux kernel, which sees | |
4826 | # valid responses at each of the LUN IDs, to believe there are multiple | |
4827 | # devices present, when in fact, there is only 1. | |
4828 | # A customer that is aware of their target behaviors, and the results as | |
4829 | # indicated above, is welcome to increase the lpfc_max_luns value. | |
4830 | # As mentioned, this value is not used by the lpfc driver, only the | |
4831 | # SCSI midlayer. | |
65a29c16 JS |
4832 | # Value range is [0,65535]. Default value is 255. |
4833 | # NOTE: The SCSI layer might probe all allowed LUN on some old targets. | |
dea3101e | 4834 | */ |
1abf635d | 4835 | LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID"); |
dea3101e | 4836 | |
875fbdfe JSEC |
4837 | /* |
4838 | # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring. | |
4839 | # Value range is [1,255], default value is 10. | |
4840 | */ | |
4841 | LPFC_ATTR_RW(poll_tmo, 10, 1, 255, | |
4842 | "Milliseconds driver will wait between polling FCP ring"); | |
4843 | ||
4ff43246 | 4844 | /* |
0c411222 JS |
4845 | # lpfc_task_mgmt_tmo: Maximum time to wait for task management commands |
4846 | # to complete in seconds. Value range is [5,180], default value is 60. | |
4847 | */ | |
4848 | LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180, | |
4849 | "Maximum time to wait for task management commands to complete"); | |
4850 | /* | |
4ff43246 JS |
4851 | # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that |
4852 | # support this feature | |
8605c46c | 4853 | # 0 = MSI disabled |
4ff43246 | 4854 | # 1 = MSI enabled |
8605c46c GK |
4855 | # 2 = MSI-X enabled (default) |
4856 | # Value range is [0,2]. Default value is 2. | |
4ff43246 | 4857 | */ |
8605c46c | 4858 | LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or " |
db2378e0 | 4859 | "MSI-X (2), if possible"); |
4ff43246 | 4860 | |
67d12733 | 4861 | /* |
f358dd0c | 4862 | * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs |
895427bd JS |
4863 | * |
4864 | * 0 = NVME OAS disabled | |
4865 | * 1 = NVME OAS enabled | |
4866 | * | |
4867 | * Value range is [0,1]. Default value is 0. | |
4868 | */ | |
4869 | LPFC_ATTR_RW(nvme_oas, 0, 0, 1, | |
4870 | "Use OAS bit on NVME IOs"); | |
4871 | ||
4872 | /* | |
4873 | * lpfc_fcp_io_channel: Set the number of FCP IO channels the driver | |
4874 | * will advertise it supports to the SCSI layer. This also will map to | |
4875 | * the number of WQs the driver will create. | |
4876 | * | |
4877 | * 0 = Configure the number of io channels to the number of active CPUs. | |
4878 | * 1,32 = Manually specify how many io channels to use. | |
4879 | * | |
4880 | * Value range is [0,32]. Default value is 4. | |
4881 | */ | |
4882 | LPFC_ATTR_R(fcp_io_channel, | |
4883 | LPFC_FCP_IO_CHAN_DEF, | |
4884 | LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX, | |
67d12733 JS |
4885 | "Set the number of FCP I/O channels"); |
4886 | ||
895427bd JS |
4887 | /* |
4888 | * lpfc_nvme_io_channel: Set the number of IO hardware queues the driver | |
4889 | * will advertise it supports to the NVME layer. This also will map to | |
4890 | * the number of WQs the driver will create. | |
4891 | * | |
4892 | * This module parameter is valid when lpfc_enable_fc4_type is set | |
4893 | * to support NVME. | |
4894 | * | |
4895 | * The NVME Layer will try to create this many, plus 1 administrative | |
4896 | * hardware queue. The administrative queue will always map to WQ 0 | |
4897 | * A hardware IO queue maps (qidx) to a specific driver WQ. | |
4898 | * | |
4899 | * 0 = Configure the number of io channels to the number of active CPUs. | |
4900 | * 1,32 = Manually specify how many io channels to use. | |
4901 | * | |
4902 | * Value range is [0,32]. Default value is 0. | |
4903 | */ | |
4904 | LPFC_ATTR_R(nvme_io_channel, | |
4905 | LPFC_NVME_IO_CHAN_DEF, | |
4906 | LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX, | |
4907 | "Set the number of NVME I/O channels"); | |
4908 | ||
13815c83 JS |
4909 | /* |
4910 | # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware. | |
4911 | # 0 = HBA resets disabled | |
4912 | # 1 = HBA resets enabled (default) | |
4913 | # Value range is [0,1]. Default value is 1. | |
4914 | */ | |
4915 | LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver."); | |
c3f28afa | 4916 | |
13815c83 | 4917 | /* |
eb7a339e | 4918 | # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer.. |
13815c83 JS |
4919 | # 0 = HBA Heartbeat disabled |
4920 | # 1 = HBA Heartbeat enabled (default) | |
4921 | # Value range is [0,1]. Default value is 1. | |
4922 | */ | |
eb7a339e | 4923 | LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat."); |
92d7f7b0 | 4924 | |
1ba981fd JS |
4925 | /* |
4926 | # lpfc_EnableXLane: Enable Express Lane Feature | |
4927 | # 0x0 Express Lane Feature disabled | |
4928 | # 0x1 Express Lane Feature enabled | |
4929 | # Value range is [0,1]. Default value is 0. | |
4930 | */ | |
4931 | LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature."); | |
4932 | ||
4933 | /* | |
4934 | # lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature | |
4935 | # 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits) | |
4936 | # Value range is [0x0,0x7f]. Default value is 0 | |
4937 | */ | |
28d7f3df | 4938 | LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature."); |
1ba981fd | 4939 | |
81301a9b JS |
4940 | /* |
4941 | # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF) | |
4942 | # 0 = BlockGuard disabled (default) | |
4943 | # 1 = BlockGuard enabled | |
4944 | # Value range is [0,1]. Default value is 0. | |
4945 | */ | |
4946 | LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support"); | |
4947 | ||
ba20c853 JS |
4948 | /* |
4949 | # lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine | |
4950 | # 0 = disabled (default) | |
4951 | # 1 = enabled | |
4952 | # Value range is [0,1]. Default value is 0. | |
5688d670 JS |
4953 | # |
4954 | # This feature in under investigation and may be supported in the future. | |
ba20c853 JS |
4955 | */ |
4956 | unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF; | |
4957 | ||
81301a9b JS |
4958 | /* |
4959 | # lpfc_prot_mask: i | |
4960 | # - Bit mask of host protection capabilities used to register with the | |
4961 | # SCSI mid-layer | |
4962 | # - Only meaningful if BG is turned on (lpfc_enable_bg=1). | |
4963 | # - Allows you to ultimately specify which profiles to use | |
4964 | # - Default will result in registering capabilities for all profiles. | |
005ffa70 JS |
4965 | # - SHOST_DIF_TYPE1_PROTECTION 1 |
4966 | # HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection | |
4967 | # - SHOST_DIX_TYPE0_PROTECTION 8 | |
4968 | # HBA supports DIX Type 0: Host to HBA protection only | |
4969 | # - SHOST_DIX_TYPE1_PROTECTION 16 | |
4970 | # HBA supports DIX Type 1: Host to HBA Type 1 protection | |
81301a9b JS |
4971 | # |
4972 | */ | |
b3b98b74 JS |
4973 | LPFC_ATTR(prot_mask, |
4974 | (SHOST_DIF_TYPE1_PROTECTION | | |
4975 | SHOST_DIX_TYPE0_PROTECTION | | |
4976 | SHOST_DIX_TYPE1_PROTECTION), | |
4977 | 0, | |
4978 | (SHOST_DIF_TYPE1_PROTECTION | | |
4979 | SHOST_DIX_TYPE0_PROTECTION | | |
4980 | SHOST_DIX_TYPE1_PROTECTION), | |
4981 | "T10-DIF host protection capabilities mask"); | |
81301a9b JS |
4982 | |
4983 | /* | |
4984 | # lpfc_prot_guard: i | |
4985 | # - Bit mask of protection guard types to register with the SCSI mid-layer | |
005ffa70 | 4986 | # - Guard types are currently either 1) T10-DIF CRC 2) IP checksum |
81301a9b JS |
4987 | # - Allows you to ultimately specify which profiles to use |
4988 | # - Default will result in registering capabilities for all guard types | |
4989 | # | |
4990 | */ | |
b3b98b74 JS |
4991 | LPFC_ATTR(prot_guard, |
4992 | SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP, | |
4993 | "T10-DIF host protection guard type"); | |
81301a9b | 4994 | |
92494144 JS |
4995 | /* |
4996 | * Delay initial NPort discovery when Clean Address bit is cleared in | |
4997 | * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed. | |
4998 | * This parameter can have value 0 or 1. | |
4999 | * When this parameter is set to 0, no delay is added to the initial | |
5000 | * discovery. | |
5001 | * When this parameter is set to non-zero value, initial Nport discovery is | |
5002 | * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC | |
5003 | * accept and FCID/Fabric name/Fabric portname is changed. | |
5004 | * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion | |
5005 | * when Clean Address bit is cleared in FLOGI/FDISC | |
5006 | * accept and FCID/Fabric name/Fabric portname is changed. | |
5007 | * Default value is 0. | |
5008 | */ | |
8eb8b960 JS |
5009 | LPFC_ATTR(delay_discovery, 0, 0, 1, |
5010 | "Delay NPort discovery when Clean Address bit is cleared."); | |
81301a9b | 5011 | |
83108bd3 | 5012 | /* |
3621a710 | 5013 | * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count |
96f7077f | 5014 | * This value can be set to values between 64 and 4096. The default value is |
83108bd3 JS |
5015 | * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer |
5016 | * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE). | |
96f7077f JS |
5017 | * Because of the additional overhead involved in setting up T10-DIF, |
5018 | * this parameter will be limited to 128 if BlockGuard is enabled under SLI4 | |
5019 | * and will be limited to 512 if BlockGuard is enabled under SLI3. | |
83108bd3 JS |
5020 | */ |
5021 | LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT, | |
5022 | LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count"); | |
5023 | ||
7bdedb34 JS |
5024 | /* |
5025 | * lpfc_enable_mds_diags: Enable MDS Diagnostics | |
5026 | * 0 = MDS Diagnostics disabled (default) | |
5027 | * 1 = MDS Diagnostics enabled | |
5028 | * Value range is [0,1]. Default value is 0. | |
5029 | */ | |
5030 | LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics"); | |
5031 | ||
ee959b00 | 5032 | struct device_attribute *lpfc_hba_attrs[] = { |
895427bd | 5033 | &dev_attr_nvme_info, |
81301a9b JS |
5034 | &dev_attr_bg_info, |
5035 | &dev_attr_bg_guard_err, | |
5036 | &dev_attr_bg_apptag_err, | |
5037 | &dev_attr_bg_reftag_err, | |
ee959b00 TJ |
5038 | &dev_attr_info, |
5039 | &dev_attr_serialnum, | |
5040 | &dev_attr_modeldesc, | |
5041 | &dev_attr_modelname, | |
5042 | &dev_attr_programtype, | |
5043 | &dev_attr_portnum, | |
5044 | &dev_attr_fwrev, | |
5045 | &dev_attr_hdw, | |
5046 | &dev_attr_option_rom_version, | |
bbd1ae41 | 5047 | &dev_attr_link_state, |
ee959b00 | 5048 | &dev_attr_num_discovered_ports, |
84774a4d | 5049 | &dev_attr_menlo_mgmt_mode, |
ee959b00 | 5050 | &dev_attr_lpfc_drvr_version, |
45ed1190 | 5051 | &dev_attr_lpfc_enable_fip, |
ee959b00 TJ |
5052 | &dev_attr_lpfc_temp_sensor, |
5053 | &dev_attr_lpfc_log_verbose, | |
5054 | &dev_attr_lpfc_lun_queue_depth, | |
7dc517df | 5055 | &dev_attr_lpfc_tgt_queue_depth, |
ee959b00 TJ |
5056 | &dev_attr_lpfc_hba_queue_depth, |
5057 | &dev_attr_lpfc_peer_port_login, | |
5058 | &dev_attr_lpfc_nodev_tmo, | |
5059 | &dev_attr_lpfc_devloss_tmo, | |
895427bd JS |
5060 | &dev_attr_lpfc_enable_fc4_type, |
5061 | &dev_attr_lpfc_xri_split, | |
ee959b00 TJ |
5062 | &dev_attr_lpfc_fcp_class, |
5063 | &dev_attr_lpfc_use_adisc, | |
3cb01c57 | 5064 | &dev_attr_lpfc_first_burst_size, |
ee959b00 TJ |
5065 | &dev_attr_lpfc_ack0, |
5066 | &dev_attr_lpfc_topology, | |
5067 | &dev_attr_lpfc_scan_down, | |
5068 | &dev_attr_lpfc_link_speed, | |
49aa143d | 5069 | &dev_attr_lpfc_fcp_io_sched, |
a6571c6e | 5070 | &dev_attr_lpfc_fcp2_no_tgt_reset, |
ee959b00 TJ |
5071 | &dev_attr_lpfc_cr_delay, |
5072 | &dev_attr_lpfc_cr_count, | |
5073 | &dev_attr_lpfc_multi_ring_support, | |
5074 | &dev_attr_lpfc_multi_ring_rctl, | |
5075 | &dev_attr_lpfc_multi_ring_type, | |
5076 | &dev_attr_lpfc_fdmi_on, | |
4258e98e | 5077 | &dev_attr_lpfc_enable_SmartSAN, |
ee959b00 TJ |
5078 | &dev_attr_lpfc_max_luns, |
5079 | &dev_attr_lpfc_enable_npiv, | |
7d791df7 | 5080 | &dev_attr_lpfc_fcf_failover_policy, |
19ca7609 | 5081 | &dev_attr_lpfc_enable_rrq, |
ee959b00 TJ |
5082 | &dev_attr_nport_evt_cnt, |
5083 | &dev_attr_board_mode, | |
5084 | &dev_attr_max_vpi, | |
5085 | &dev_attr_used_vpi, | |
5086 | &dev_attr_max_rpi, | |
5087 | &dev_attr_used_rpi, | |
5088 | &dev_attr_max_xri, | |
5089 | &dev_attr_used_xri, | |
5090 | &dev_attr_npiv_info, | |
5091 | &dev_attr_issue_reset, | |
5092 | &dev_attr_lpfc_poll, | |
5093 | &dev_attr_lpfc_poll_tmo, | |
0c411222 | 5094 | &dev_attr_lpfc_task_mgmt_tmo, |
ee959b00 | 5095 | &dev_attr_lpfc_use_msi, |
895427bd | 5096 | &dev_attr_lpfc_nvme_oas, |
da0436e9 | 5097 | &dev_attr_lpfc_fcp_imax, |
7bb03bbf | 5098 | &dev_attr_lpfc_fcp_cpu_map, |
67d12733 | 5099 | &dev_attr_lpfc_fcp_io_channel, |
f358dd0c | 5100 | &dev_attr_lpfc_suppress_rsp, |
895427bd JS |
5101 | &dev_attr_lpfc_nvme_io_channel, |
5102 | &dev_attr_lpfc_nvme_enable_fb, | |
81301a9b | 5103 | &dev_attr_lpfc_enable_bg, |
352e5fd1 JS |
5104 | &dev_attr_lpfc_soft_wwnn, |
5105 | &dev_attr_lpfc_soft_wwpn, | |
5106 | &dev_attr_lpfc_soft_wwn_enable, | |
ee959b00 TJ |
5107 | &dev_attr_lpfc_enable_hba_reset, |
5108 | &dev_attr_lpfc_enable_hba_heartbeat, | |
1ba981fd JS |
5109 | &dev_attr_lpfc_EnableXLane, |
5110 | &dev_attr_lpfc_XLanePriority, | |
5111 | &dev_attr_lpfc_xlane_lun, | |
5112 | &dev_attr_lpfc_xlane_tgt, | |
5113 | &dev_attr_lpfc_xlane_vpt, | |
5114 | &dev_attr_lpfc_xlane_lun_state, | |
5115 | &dev_attr_lpfc_xlane_lun_status, | |
c92c841c | 5116 | &dev_attr_lpfc_xlane_priority, |
ee959b00 | 5117 | &dev_attr_lpfc_sg_seg_cnt, |
977b5a0a | 5118 | &dev_attr_lpfc_max_scsicmpl_time, |
ea2151b4 | 5119 | &dev_attr_lpfc_stat_data_ctrl, |
0d878419 JS |
5120 | &dev_attr_lpfc_aer_support, |
5121 | &dev_attr_lpfc_aer_state_cleanup, | |
912e3acd | 5122 | &dev_attr_lpfc_sriov_nr_virtfn, |
c71ab861 | 5123 | &dev_attr_lpfc_req_fw_upgrade, |
84d1b006 | 5124 | &dev_attr_lpfc_suppress_link_up, |
2a9bf3d0 JS |
5125 | &dev_attr_lpfc_iocb_cnt, |
5126 | &dev_attr_iocb_hw, | |
5127 | &dev_attr_txq_hw, | |
5128 | &dev_attr_txcmplq_hw, | |
bc73905a JS |
5129 | &dev_attr_lpfc_fips_level, |
5130 | &dev_attr_lpfc_fips_rev, | |
ab56dc2e | 5131 | &dev_attr_lpfc_dss, |
912e3acd | 5132 | &dev_attr_lpfc_sriov_hw_max_virtfn, |
026abb87 | 5133 | &dev_attr_protocol, |
1ba981fd | 5134 | &dev_attr_lpfc_xlane_supported, |
7bdedb34 | 5135 | &dev_attr_lpfc_enable_mds_diags, |
dea3101e JB |
5136 | NULL, |
5137 | }; | |
5138 | ||
ee959b00 TJ |
5139 | struct device_attribute *lpfc_vport_attrs[] = { |
5140 | &dev_attr_info, | |
bbd1ae41 | 5141 | &dev_attr_link_state, |
ee959b00 TJ |
5142 | &dev_attr_num_discovered_ports, |
5143 | &dev_attr_lpfc_drvr_version, | |
5144 | &dev_attr_lpfc_log_verbose, | |
5145 | &dev_attr_lpfc_lun_queue_depth, | |
7dc517df | 5146 | &dev_attr_lpfc_tgt_queue_depth, |
ee959b00 TJ |
5147 | &dev_attr_lpfc_nodev_tmo, |
5148 | &dev_attr_lpfc_devloss_tmo, | |
5149 | &dev_attr_lpfc_hba_queue_depth, | |
5150 | &dev_attr_lpfc_peer_port_login, | |
5151 | &dev_attr_lpfc_restrict_login, | |
5152 | &dev_attr_lpfc_fcp_class, | |
5153 | &dev_attr_lpfc_use_adisc, | |
3cb01c57 | 5154 | &dev_attr_lpfc_first_burst_size, |
ee959b00 TJ |
5155 | &dev_attr_lpfc_max_luns, |
5156 | &dev_attr_nport_evt_cnt, | |
5157 | &dev_attr_npiv_info, | |
5158 | &dev_attr_lpfc_enable_da_id, | |
ea2151b4 JS |
5159 | &dev_attr_lpfc_max_scsicmpl_time, |
5160 | &dev_attr_lpfc_stat_data_ctrl, | |
21e9a0a5 | 5161 | &dev_attr_lpfc_static_vport, |
bc73905a JS |
5162 | &dev_attr_lpfc_fips_level, |
5163 | &dev_attr_lpfc_fips_rev, | |
3de2a653 JS |
5164 | NULL, |
5165 | }; | |
5166 | ||
e59058c4 | 5167 | /** |
3621a710 | 5168 | * sysfs_ctlreg_write - Write method for writing to ctlreg |
2c3c8bea | 5169 | * @filp: open sysfs file |
e59058c4 JS |
5170 | * @kobj: kernel kobject that contains the kernel class device. |
5171 | * @bin_attr: kernel attributes passed to us. | |
5172 | * @buf: contains the data to be written to the adapter IOREG space. | |
5173 | * @off: offset into buffer to beginning of data. | |
5174 | * @count: bytes to transfer. | |
5175 | * | |
5176 | * Description: | |
5177 | * Accessed via /sys/class/scsi_host/hostxxx/ctlreg. | |
5178 | * Uses the adapter io control registers to send buf contents to the adapter. | |
5179 | * | |
5180 | * Returns: | |
5181 | * -ERANGE off and count combo out of range | |
5182 | * -EINVAL off, count or buff address invalid | |
5183 | * -EPERM adapter is offline | |
5184 | * value of count, buf contents written | |
5185 | **/ | |
dea3101e | 5186 | static ssize_t |
2c3c8bea CW |
5187 | sysfs_ctlreg_write(struct file *filp, struct kobject *kobj, |
5188 | struct bin_attribute *bin_attr, | |
91a69029 | 5189 | char *buf, loff_t off, size_t count) |
dea3101e JB |
5190 | { |
5191 | size_t buf_off; | |
ee959b00 TJ |
5192 | struct device *dev = container_of(kobj, struct device, kobj); |
5193 | struct Scsi_Host *shost = class_to_shost(dev); | |
2e0fef85 JS |
5194 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
5195 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 5196 | |
f1126688 JS |
5197 | if (phba->sli_rev >= LPFC_SLI_REV4) |
5198 | return -EPERM; | |
5199 | ||
dea3101e JB |
5200 | if ((off + count) > FF_REG_AREA_SIZE) |
5201 | return -ERANGE; | |
5202 | ||
f7a919b4 JS |
5203 | if (count <= LPFC_REG_WRITE_KEY_SIZE) |
5204 | return 0; | |
dea3101e JB |
5205 | |
5206 | if (off % 4 || count % 4 || (unsigned long)buf % 4) | |
5207 | return -EINVAL; | |
5208 | ||
f7a919b4 JS |
5209 | /* This is to protect HBA registers from accidental writes. */ |
5210 | if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE)) | |
5211 | return -EINVAL; | |
5212 | ||
5213 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) | |
dea3101e | 5214 | return -EPERM; |
dea3101e | 5215 | |
2e0fef85 | 5216 | spin_lock_irq(&phba->hbalock); |
f7a919b4 JS |
5217 | for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE; |
5218 | buf_off += sizeof(uint32_t)) | |
5219 | writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)), | |
dea3101e JB |
5220 | phba->ctrl_regs_memmap_p + off + buf_off); |
5221 | ||
2e0fef85 | 5222 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
5223 | |
5224 | return count; | |
5225 | } | |
5226 | ||
e59058c4 | 5227 | /** |
3621a710 | 5228 | * sysfs_ctlreg_read - Read method for reading from ctlreg |
2c3c8bea | 5229 | * @filp: open sysfs file |
e59058c4 JS |
5230 | * @kobj: kernel kobject that contains the kernel class device. |
5231 | * @bin_attr: kernel attributes passed to us. | |
af901ca1 | 5232 | * @buf: if successful contains the data from the adapter IOREG space. |
e59058c4 JS |
5233 | * @off: offset into buffer to beginning of data. |
5234 | * @count: bytes to transfer. | |
5235 | * | |
5236 | * Description: | |
5237 | * Accessed via /sys/class/scsi_host/hostxxx/ctlreg. | |
5238 | * Uses the adapter io control registers to read data into buf. | |
5239 | * | |
5240 | * Returns: | |
5241 | * -ERANGE off and count combo out of range | |
5242 | * -EINVAL off, count or buff address invalid | |
5243 | * value of count, buf contents read | |
5244 | **/ | |
dea3101e | 5245 | static ssize_t |
2c3c8bea CW |
5246 | sysfs_ctlreg_read(struct file *filp, struct kobject *kobj, |
5247 | struct bin_attribute *bin_attr, | |
91a69029 | 5248 | char *buf, loff_t off, size_t count) |
dea3101e JB |
5249 | { |
5250 | size_t buf_off; | |
5251 | uint32_t * tmp_ptr; | |
ee959b00 TJ |
5252 | struct device *dev = container_of(kobj, struct device, kobj); |
5253 | struct Scsi_Host *shost = class_to_shost(dev); | |
2e0fef85 JS |
5254 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
5255 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 5256 | |
f1126688 JS |
5257 | if (phba->sli_rev >= LPFC_SLI_REV4) |
5258 | return -EPERM; | |
5259 | ||
dea3101e JB |
5260 | if (off > FF_REG_AREA_SIZE) |
5261 | return -ERANGE; | |
5262 | ||
5263 | if ((off + count) > FF_REG_AREA_SIZE) | |
5264 | count = FF_REG_AREA_SIZE - off; | |
5265 | ||
5266 | if (count == 0) return 0; | |
5267 | ||
5268 | if (off % 4 || count % 4 || (unsigned long)buf % 4) | |
5269 | return -EINVAL; | |
5270 | ||
2e0fef85 | 5271 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
5272 | |
5273 | for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) { | |
5274 | tmp_ptr = (uint32_t *)(buf + buf_off); | |
5275 | *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off); | |
5276 | } | |
5277 | ||
2e0fef85 | 5278 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
5279 | |
5280 | return count; | |
5281 | } | |
5282 | ||
5283 | static struct bin_attribute sysfs_ctlreg_attr = { | |
5284 | .attr = { | |
5285 | .name = "ctlreg", | |
5286 | .mode = S_IRUSR | S_IWUSR, | |
dea3101e JB |
5287 | }, |
5288 | .size = 256, | |
5289 | .read = sysfs_ctlreg_read, | |
5290 | .write = sysfs_ctlreg_write, | |
5291 | }; | |
5292 | ||
e59058c4 | 5293 | /** |
3621a710 | 5294 | * sysfs_mbox_write - Write method for writing information via mbox |
2c3c8bea | 5295 | * @filp: open sysfs file |
e59058c4 JS |
5296 | * @kobj: kernel kobject that contains the kernel class device. |
5297 | * @bin_attr: kernel attributes passed to us. | |
5298 | * @buf: contains the data to be written to sysfs mbox. | |
5299 | * @off: offset into buffer to beginning of data. | |
5300 | * @count: bytes to transfer. | |
5301 | * | |
5302 | * Description: | |
026abb87 JS |
5303 | * Deprecated function. All mailbox access from user space is performed via the |
5304 | * bsg interface. | |
e59058c4 JS |
5305 | * |
5306 | * Returns: | |
026abb87 | 5307 | * -EPERM operation not permitted |
e59058c4 | 5308 | **/ |
dea3101e | 5309 | static ssize_t |
2c3c8bea CW |
5310 | sysfs_mbox_write(struct file *filp, struct kobject *kobj, |
5311 | struct bin_attribute *bin_attr, | |
91a69029 | 5312 | char *buf, loff_t off, size_t count) |
dea3101e | 5313 | { |
026abb87 | 5314 | return -EPERM; |
dea3101e JB |
5315 | } |
5316 | ||
e59058c4 | 5317 | /** |
3621a710 | 5318 | * sysfs_mbox_read - Read method for reading information via mbox |
2c3c8bea | 5319 | * @filp: open sysfs file |
e59058c4 JS |
5320 | * @kobj: kernel kobject that contains the kernel class device. |
5321 | * @bin_attr: kernel attributes passed to us. | |
5322 | * @buf: contains the data to be read from sysfs mbox. | |
5323 | * @off: offset into buffer to beginning of data. | |
5324 | * @count: bytes to transfer. | |
5325 | * | |
5326 | * Description: | |
026abb87 JS |
5327 | * Deprecated function. All mailbox access from user space is performed via the |
5328 | * bsg interface. | |
e59058c4 JS |
5329 | * |
5330 | * Returns: | |
026abb87 | 5331 | * -EPERM operation not permitted |
e59058c4 | 5332 | **/ |
dea3101e | 5333 | static ssize_t |
2c3c8bea CW |
5334 | sysfs_mbox_read(struct file *filp, struct kobject *kobj, |
5335 | struct bin_attribute *bin_attr, | |
91a69029 | 5336 | char *buf, loff_t off, size_t count) |
dea3101e | 5337 | { |
026abb87 | 5338 | return -EPERM; |
dea3101e JB |
5339 | } |
5340 | ||
5341 | static struct bin_attribute sysfs_mbox_attr = { | |
5342 | .attr = { | |
5343 | .name = "mbox", | |
5344 | .mode = S_IRUSR | S_IWUSR, | |
dea3101e | 5345 | }, |
c0c11512 | 5346 | .size = MAILBOX_SYSFS_MAX, |
dea3101e JB |
5347 | .read = sysfs_mbox_read, |
5348 | .write = sysfs_mbox_write, | |
5349 | }; | |
5350 | ||
e59058c4 | 5351 | /** |
3621a710 | 5352 | * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries |
e59058c4 JS |
5353 | * @vport: address of lpfc vport structure. |
5354 | * | |
5355 | * Return codes: | |
5356 | * zero on success | |
5357 | * error return code from sysfs_create_bin_file() | |
5358 | **/ | |
dea3101e | 5359 | int |
2e0fef85 | 5360 | lpfc_alloc_sysfs_attr(struct lpfc_vport *vport) |
dea3101e | 5361 | { |
2e0fef85 | 5362 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
dea3101e JB |
5363 | int error; |
5364 | ||
ee959b00 | 5365 | error = sysfs_create_bin_file(&shost->shost_dev.kobj, |
eada272d JS |
5366 | &sysfs_drvr_stat_data_attr); |
5367 | ||
5368 | /* Virtual ports do not need ctrl_reg and mbox */ | |
5369 | if (error || vport->port_type == LPFC_NPIV_PORT) | |
dea3101e JB |
5370 | goto out; |
5371 | ||
ee959b00 | 5372 | error = sysfs_create_bin_file(&shost->shost_dev.kobj, |
eada272d | 5373 | &sysfs_ctlreg_attr); |
dea3101e | 5374 | if (error) |
eada272d | 5375 | goto out_remove_stat_attr; |
dea3101e | 5376 | |
ea2151b4 | 5377 | error = sysfs_create_bin_file(&shost->shost_dev.kobj, |
eada272d | 5378 | &sysfs_mbox_attr); |
ea2151b4 | 5379 | if (error) |
eada272d | 5380 | goto out_remove_ctlreg_attr; |
ea2151b4 | 5381 | |
dea3101e JB |
5382 | return 0; |
5383 | out_remove_ctlreg_attr: | |
ee959b00 | 5384 | sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr); |
eada272d JS |
5385 | out_remove_stat_attr: |
5386 | sysfs_remove_bin_file(&shost->shost_dev.kobj, | |
5387 | &sysfs_drvr_stat_data_attr); | |
dea3101e JB |
5388 | out: |
5389 | return error; | |
5390 | } | |
5391 | ||
e59058c4 | 5392 | /** |
3621a710 | 5393 | * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries |
e59058c4 JS |
5394 | * @vport: address of lpfc vport structure. |
5395 | **/ | |
dea3101e | 5396 | void |
2e0fef85 | 5397 | lpfc_free_sysfs_attr(struct lpfc_vport *vport) |
dea3101e | 5398 | { |
2e0fef85 | 5399 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
ea2151b4 JS |
5400 | sysfs_remove_bin_file(&shost->shost_dev.kobj, |
5401 | &sysfs_drvr_stat_data_attr); | |
eada272d JS |
5402 | /* Virtual ports do not need ctrl_reg and mbox */ |
5403 | if (vport->port_type == LPFC_NPIV_PORT) | |
5404 | return; | |
ee959b00 TJ |
5405 | sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr); |
5406 | sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr); | |
dea3101e JB |
5407 | } |
5408 | ||
dea3101e JB |
5409 | /* |
5410 | * Dynamic FC Host Attributes Support | |
5411 | */ | |
5412 | ||
6c9231f6 JS |
5413 | /** |
5414 | * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host | |
5415 | * @shost: kernel scsi host pointer. | |
5416 | **/ | |
5417 | static void | |
5418 | lpfc_get_host_symbolic_name(struct Scsi_Host *shost) | |
5419 | { | |
5420 | struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; | |
5421 | ||
5422 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), | |
5423 | sizeof fc_host_symbolic_name(shost)); | |
5424 | } | |
5425 | ||
e59058c4 | 5426 | /** |
3621a710 | 5427 | * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id |
e59058c4 JS |
5428 | * @shost: kernel scsi host pointer. |
5429 | **/ | |
dea3101e JB |
5430 | static void |
5431 | lpfc_get_host_port_id(struct Scsi_Host *shost) | |
5432 | { | |
2e0fef85 JS |
5433 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
5434 | ||
dea3101e | 5435 | /* note: fc_myDID already in cpu endianness */ |
2e0fef85 | 5436 | fc_host_port_id(shost) = vport->fc_myDID; |
dea3101e JB |
5437 | } |
5438 | ||
e59058c4 | 5439 | /** |
3621a710 | 5440 | * lpfc_get_host_port_type - Set the value of the scsi host port type |
e59058c4 JS |
5441 | * @shost: kernel scsi host pointer. |
5442 | **/ | |
dea3101e JB |
5443 | static void |
5444 | lpfc_get_host_port_type(struct Scsi_Host *shost) | |
5445 | { | |
2e0fef85 JS |
5446 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
5447 | struct lpfc_hba *phba = vport->phba; | |
dea3101e JB |
5448 | |
5449 | spin_lock_irq(shost->host_lock); | |
5450 | ||
92d7f7b0 JS |
5451 | if (vport->port_type == LPFC_NPIV_PORT) { |
5452 | fc_host_port_type(shost) = FC_PORTTYPE_NPIV; | |
5453 | } else if (lpfc_is_link_up(phba)) { | |
76a95d75 | 5454 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
2e0fef85 | 5455 | if (vport->fc_flag & FC_PUBLIC_LOOP) |
dea3101e JB |
5456 | fc_host_port_type(shost) = FC_PORTTYPE_NLPORT; |
5457 | else | |
5458 | fc_host_port_type(shost) = FC_PORTTYPE_LPORT; | |
5459 | } else { | |
2e0fef85 | 5460 | if (vport->fc_flag & FC_FABRIC) |
dea3101e JB |
5461 | fc_host_port_type(shost) = FC_PORTTYPE_NPORT; |
5462 | else | |
5463 | fc_host_port_type(shost) = FC_PORTTYPE_PTP; | |
5464 | } | |
5465 | } else | |
5466 | fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN; | |
5467 | ||
5468 | spin_unlock_irq(shost->host_lock); | |
5469 | } | |
5470 | ||
e59058c4 | 5471 | /** |
3621a710 | 5472 | * lpfc_get_host_port_state - Set the value of the scsi host port state |
e59058c4 JS |
5473 | * @shost: kernel scsi host pointer. |
5474 | **/ | |
dea3101e JB |
5475 | static void |
5476 | lpfc_get_host_port_state(struct Scsi_Host *shost) | |
5477 | { | |
2e0fef85 JS |
5478 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
5479 | struct lpfc_hba *phba = vport->phba; | |
dea3101e JB |
5480 | |
5481 | spin_lock_irq(shost->host_lock); | |
5482 | ||
2e0fef85 | 5483 | if (vport->fc_flag & FC_OFFLINE_MODE) |
dea3101e JB |
5484 | fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE; |
5485 | else { | |
2e0fef85 JS |
5486 | switch (phba->link_state) { |
5487 | case LPFC_LINK_UNKNOWN: | |
dea3101e JB |
5488 | case LPFC_LINK_DOWN: |
5489 | fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN; | |
5490 | break; | |
5491 | case LPFC_LINK_UP: | |
dea3101e JB |
5492 | case LPFC_CLEAR_LA: |
5493 | case LPFC_HBA_READY: | |
026abb87 JS |
5494 | /* Links up, reports port state accordingly */ |
5495 | if (vport->port_state < LPFC_VPORT_READY) | |
5496 | fc_host_port_state(shost) = | |
5497 | FC_PORTSTATE_BYPASSED; | |
5498 | else | |
5499 | fc_host_port_state(shost) = | |
5500 | FC_PORTSTATE_ONLINE; | |
dea3101e JB |
5501 | break; |
5502 | case LPFC_HBA_ERROR: | |
5503 | fc_host_port_state(shost) = FC_PORTSTATE_ERROR; | |
5504 | break; | |
5505 | default: | |
5506 | fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN; | |
5507 | break; | |
5508 | } | |
5509 | } | |
5510 | ||
5511 | spin_unlock_irq(shost->host_lock); | |
5512 | } | |
5513 | ||
e59058c4 | 5514 | /** |
3621a710 | 5515 | * lpfc_get_host_speed - Set the value of the scsi host speed |
e59058c4 JS |
5516 | * @shost: kernel scsi host pointer. |
5517 | **/ | |
dea3101e JB |
5518 | static void |
5519 | lpfc_get_host_speed(struct Scsi_Host *shost) | |
5520 | { | |
2e0fef85 JS |
5521 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
5522 | struct lpfc_hba *phba = vport->phba; | |
dea3101e JB |
5523 | |
5524 | spin_lock_irq(shost->host_lock); | |
5525 | ||
a085e87c | 5526 | if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) { |
dea3101e | 5527 | switch(phba->fc_linkspeed) { |
76a95d75 JS |
5528 | case LPFC_LINK_SPEED_1GHZ: |
5529 | fc_host_speed(shost) = FC_PORTSPEED_1GBIT; | |
dea3101e | 5530 | break; |
76a95d75 JS |
5531 | case LPFC_LINK_SPEED_2GHZ: |
5532 | fc_host_speed(shost) = FC_PORTSPEED_2GBIT; | |
dea3101e | 5533 | break; |
76a95d75 JS |
5534 | case LPFC_LINK_SPEED_4GHZ: |
5535 | fc_host_speed(shost) = FC_PORTSPEED_4GBIT; | |
dea3101e | 5536 | break; |
76a95d75 JS |
5537 | case LPFC_LINK_SPEED_8GHZ: |
5538 | fc_host_speed(shost) = FC_PORTSPEED_8GBIT; | |
b87eab38 | 5539 | break; |
76a95d75 JS |
5540 | case LPFC_LINK_SPEED_10GHZ: |
5541 | fc_host_speed(shost) = FC_PORTSPEED_10GBIT; | |
f4b4c68f | 5542 | break; |
76a95d75 JS |
5543 | case LPFC_LINK_SPEED_16GHZ: |
5544 | fc_host_speed(shost) = FC_PORTSPEED_16GBIT; | |
5545 | break; | |
d38dd52c JS |
5546 | case LPFC_LINK_SPEED_32GHZ: |
5547 | fc_host_speed(shost) = FC_PORTSPEED_32GBIT; | |
5548 | break; | |
76a95d75 JS |
5549 | default: |
5550 | fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN; | |
dea3101e JB |
5551 | break; |
5552 | } | |
09372820 JS |
5553 | } else |
5554 | fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN; | |
dea3101e JB |
5555 | |
5556 | spin_unlock_irq(shost->host_lock); | |
5557 | } | |
5558 | ||
e59058c4 | 5559 | /** |
3621a710 | 5560 | * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name |
e59058c4 JS |
5561 | * @shost: kernel scsi host pointer. |
5562 | **/ | |
dea3101e JB |
5563 | static void |
5564 | lpfc_get_host_fabric_name (struct Scsi_Host *shost) | |
5565 | { | |
2e0fef85 JS |
5566 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
5567 | struct lpfc_hba *phba = vport->phba; | |
f631b4be | 5568 | u64 node_name; |
dea3101e JB |
5569 | |
5570 | spin_lock_irq(shost->host_lock); | |
5571 | ||
73d91e50 JS |
5572 | if ((vport->port_state > LPFC_FLOGI) && |
5573 | ((vport->fc_flag & FC_FABRIC) || | |
5574 | ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) && | |
5575 | (vport->fc_flag & FC_PUBLIC_LOOP)))) | |
68ce1eb5 | 5576 | node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn); |
dea3101e JB |
5577 | else |
5578 | /* fabric is local port if there is no F/FL_Port */ | |
09372820 | 5579 | node_name = 0; |
dea3101e JB |
5580 | |
5581 | spin_unlock_irq(shost->host_lock); | |
5582 | ||
f631b4be | 5583 | fc_host_fabric_name(shost) = node_name; |
dea3101e JB |
5584 | } |
5585 | ||
e59058c4 | 5586 | /** |
3621a710 | 5587 | * lpfc_get_stats - Return statistical information about the adapter |
e59058c4 JS |
5588 | * @shost: kernel scsi host pointer. |
5589 | * | |
5590 | * Notes: | |
5591 | * NULL on error for link down, no mbox pool, sli2 active, | |
5592 | * management not allowed, memory allocation error, or mbox error. | |
5593 | * | |
5594 | * Returns: | |
5595 | * NULL for error | |
5596 | * address of the adapter host statistics | |
5597 | **/ | |
dea3101e JB |
5598 | static struct fc_host_statistics * |
5599 | lpfc_get_stats(struct Scsi_Host *shost) | |
5600 | { | |
2e0fef85 JS |
5601 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
5602 | struct lpfc_hba *phba = vport->phba; | |
5603 | struct lpfc_sli *psli = &phba->sli; | |
f888ba3c | 5604 | struct fc_host_statistics *hs = &phba->link_stats; |
64ba8818 | 5605 | struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets; |
dea3101e JB |
5606 | LPFC_MBOXQ_t *pmboxq; |
5607 | MAILBOX_t *pmb; | |
64ba8818 | 5608 | unsigned long seconds; |
433c3579 | 5609 | int rc = 0; |
dea3101e | 5610 | |
92d7f7b0 JS |
5611 | /* |
5612 | * prevent udev from issuing mailbox commands until the port is | |
5613 | * configured. | |
5614 | */ | |
2e0fef85 JS |
5615 | if (phba->link_state < LPFC_LINK_DOWN || |
5616 | !phba->mbox_mem_pool || | |
f4b4c68f | 5617 | (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0) |
92d7f7b0 | 5618 | return NULL; |
2e0fef85 JS |
5619 | |
5620 | if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) | |
46fa311e JS |
5621 | return NULL; |
5622 | ||
dea3101e JB |
5623 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
5624 | if (!pmboxq) | |
5625 | return NULL; | |
5626 | memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t)); | |
5627 | ||
04c68496 | 5628 | pmb = &pmboxq->u.mb; |
dea3101e JB |
5629 | pmb->mbxCommand = MBX_READ_STATUS; |
5630 | pmb->mbxOwner = OWN_HOST; | |
5631 | pmboxq->context1 = NULL; | |
92d7f7b0 | 5632 | pmboxq->vport = vport; |
dea3101e | 5633 | |
75baf696 | 5634 | if (vport->fc_flag & FC_OFFLINE_MODE) |
dea3101e | 5635 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); |
433c3579 | 5636 | else |
dea3101e JB |
5637 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); |
5638 | ||
5639 | if (rc != MBX_SUCCESS) { | |
858c9f6c | 5640 | if (rc != MBX_TIMEOUT) |
433c3579 | 5641 | mempool_free(pmboxq, phba->mbox_mem_pool); |
dea3101e JB |
5642 | return NULL; |
5643 | } | |
5644 | ||
f888ba3c JSEC |
5645 | memset(hs, 0, sizeof (struct fc_host_statistics)); |
5646 | ||
dea3101e | 5647 | hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt; |
73d91e50 JS |
5648 | /* |
5649 | * The MBX_READ_STATUS returns tx_k_bytes which has to | |
5650 | * converted to words | |
5651 | */ | |
5652 | hs->tx_words = (uint64_t) | |
5653 | ((uint64_t)pmb->un.varRdStatus.xmitByteCnt | |
5654 | * (uint64_t)256); | |
dea3101e | 5655 | hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt; |
73d91e50 JS |
5656 | hs->rx_words = (uint64_t) |
5657 | ((uint64_t)pmb->un.varRdStatus.rcvByteCnt | |
5658 | * (uint64_t)256); | |
dea3101e | 5659 | |
433c3579 | 5660 | memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t)); |
dea3101e JB |
5661 | pmb->mbxCommand = MBX_READ_LNK_STAT; |
5662 | pmb->mbxOwner = OWN_HOST; | |
5663 | pmboxq->context1 = NULL; | |
92d7f7b0 | 5664 | pmboxq->vport = vport; |
dea3101e | 5665 | |
75baf696 | 5666 | if (vport->fc_flag & FC_OFFLINE_MODE) |
dea3101e | 5667 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); |
433c3579 | 5668 | else |
dea3101e JB |
5669 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); |
5670 | ||
5671 | if (rc != MBX_SUCCESS) { | |
858c9f6c | 5672 | if (rc != MBX_TIMEOUT) |
92d7f7b0 | 5673 | mempool_free(pmboxq, phba->mbox_mem_pool); |
dea3101e JB |
5674 | return NULL; |
5675 | } | |
5676 | ||
5677 | hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt; | |
5678 | hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt; | |
5679 | hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt; | |
5680 | hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt; | |
5681 | hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord; | |
5682 | hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt; | |
5683 | hs->error_frames = pmb->un.varRdLnk.crcCnt; | |
5684 | ||
64ba8818 JS |
5685 | hs->link_failure_count -= lso->link_failure_count; |
5686 | hs->loss_of_sync_count -= lso->loss_of_sync_count; | |
5687 | hs->loss_of_signal_count -= lso->loss_of_signal_count; | |
5688 | hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count; | |
5689 | hs->invalid_tx_word_count -= lso->invalid_tx_word_count; | |
5690 | hs->invalid_crc_count -= lso->invalid_crc_count; | |
5691 | hs->error_frames -= lso->error_frames; | |
5692 | ||
76a95d75 | 5693 | if (phba->hba_flag & HBA_FCOE_MODE) { |
4d9ab994 JS |
5694 | hs->lip_count = -1; |
5695 | hs->nos_count = (phba->link_events >> 1); | |
5696 | hs->nos_count -= lso->link_events; | |
76a95d75 | 5697 | } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
dea3101e | 5698 | hs->lip_count = (phba->fc_eventTag >> 1); |
64ba8818 | 5699 | hs->lip_count -= lso->link_events; |
dea3101e JB |
5700 | hs->nos_count = -1; |
5701 | } else { | |
5702 | hs->lip_count = -1; | |
5703 | hs->nos_count = (phba->fc_eventTag >> 1); | |
64ba8818 | 5704 | hs->nos_count -= lso->link_events; |
dea3101e JB |
5705 | } |
5706 | ||
5707 | hs->dumped_frames = -1; | |
5708 | ||
64ba8818 JS |
5709 | seconds = get_seconds(); |
5710 | if (seconds < psli->stats_start) | |
5711 | hs->seconds_since_last_reset = seconds + | |
5712 | ((unsigned long)-1 - psli->stats_start); | |
5713 | else | |
5714 | hs->seconds_since_last_reset = seconds - psli->stats_start; | |
dea3101e | 5715 | |
1dcb58e5 JS |
5716 | mempool_free(pmboxq, phba->mbox_mem_pool); |
5717 | ||
dea3101e JB |
5718 | return hs; |
5719 | } | |
5720 | ||
e59058c4 | 5721 | /** |
3621a710 | 5722 | * lpfc_reset_stats - Copy the adapter link stats information |
e59058c4 JS |
5723 | * @shost: kernel scsi host pointer. |
5724 | **/ | |
64ba8818 JS |
5725 | static void |
5726 | lpfc_reset_stats(struct Scsi_Host *shost) | |
5727 | { | |
2e0fef85 JS |
5728 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
5729 | struct lpfc_hba *phba = vport->phba; | |
5730 | struct lpfc_sli *psli = &phba->sli; | |
5731 | struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets; | |
64ba8818 JS |
5732 | LPFC_MBOXQ_t *pmboxq; |
5733 | MAILBOX_t *pmb; | |
5734 | int rc = 0; | |
5735 | ||
2e0fef85 | 5736 | if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) |
46fa311e JS |
5737 | return; |
5738 | ||
64ba8818 JS |
5739 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
5740 | if (!pmboxq) | |
5741 | return; | |
5742 | memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t)); | |
5743 | ||
04c68496 | 5744 | pmb = &pmboxq->u.mb; |
64ba8818 JS |
5745 | pmb->mbxCommand = MBX_READ_STATUS; |
5746 | pmb->mbxOwner = OWN_HOST; | |
5747 | pmb->un.varWords[0] = 0x1; /* reset request */ | |
5748 | pmboxq->context1 = NULL; | |
92d7f7b0 | 5749 | pmboxq->vport = vport; |
64ba8818 | 5750 | |
2e0fef85 | 5751 | if ((vport->fc_flag & FC_OFFLINE_MODE) || |
f4b4c68f | 5752 | (!(psli->sli_flag & LPFC_SLI_ACTIVE))) |
64ba8818 JS |
5753 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); |
5754 | else | |
5755 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); | |
5756 | ||
5757 | if (rc != MBX_SUCCESS) { | |
858c9f6c | 5758 | if (rc != MBX_TIMEOUT) |
64ba8818 JS |
5759 | mempool_free(pmboxq, phba->mbox_mem_pool); |
5760 | return; | |
5761 | } | |
5762 | ||
5763 | memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t)); | |
5764 | pmb->mbxCommand = MBX_READ_LNK_STAT; | |
5765 | pmb->mbxOwner = OWN_HOST; | |
5766 | pmboxq->context1 = NULL; | |
92d7f7b0 | 5767 | pmboxq->vport = vport; |
64ba8818 | 5768 | |
2e0fef85 | 5769 | if ((vport->fc_flag & FC_OFFLINE_MODE) || |
f4b4c68f | 5770 | (!(psli->sli_flag & LPFC_SLI_ACTIVE))) |
64ba8818 JS |
5771 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); |
5772 | else | |
5773 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); | |
5774 | ||
5775 | if (rc != MBX_SUCCESS) { | |
858c9f6c | 5776 | if (rc != MBX_TIMEOUT) |
64ba8818 JS |
5777 | mempool_free( pmboxq, phba->mbox_mem_pool); |
5778 | return; | |
5779 | } | |
5780 | ||
5781 | lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt; | |
5782 | lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt; | |
5783 | lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt; | |
5784 | lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt; | |
5785 | lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord; | |
5786 | lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt; | |
5787 | lso->error_frames = pmb->un.varRdLnk.crcCnt; | |
76a95d75 | 5788 | if (phba->hba_flag & HBA_FCOE_MODE) |
4d9ab994 JS |
5789 | lso->link_events = (phba->link_events >> 1); |
5790 | else | |
5791 | lso->link_events = (phba->fc_eventTag >> 1); | |
64ba8818 JS |
5792 | |
5793 | psli->stats_start = get_seconds(); | |
5794 | ||
1dcb58e5 JS |
5795 | mempool_free(pmboxq, phba->mbox_mem_pool); |
5796 | ||
64ba8818 JS |
5797 | return; |
5798 | } | |
dea3101e JB |
5799 | |
5800 | /* | |
5801 | * The LPFC driver treats linkdown handling as target loss events so there | |
5802 | * are no sysfs handlers for link_down_tmo. | |
5803 | */ | |
685f0bf7 | 5804 | |
e59058c4 | 5805 | /** |
3621a710 | 5806 | * lpfc_get_node_by_target - Return the nodelist for a target |
e59058c4 JS |
5807 | * @starget: kernel scsi target pointer. |
5808 | * | |
5809 | * Returns: | |
5810 | * address of the node list if found | |
5811 | * NULL target not found | |
5812 | **/ | |
685f0bf7 JS |
5813 | static struct lpfc_nodelist * |
5814 | lpfc_get_node_by_target(struct scsi_target *starget) | |
dea3101e | 5815 | { |
2e0fef85 JS |
5816 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); |
5817 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
685f0bf7 | 5818 | struct lpfc_nodelist *ndlp; |
dea3101e JB |
5819 | |
5820 | spin_lock_irq(shost->host_lock); | |
685f0bf7 | 5821 | /* Search for this, mapped, target ID */ |
2e0fef85 | 5822 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
e47c9093 JS |
5823 | if (NLP_CHK_NODE_ACT(ndlp) && |
5824 | ndlp->nlp_state == NLP_STE_MAPPED_NODE && | |
685f0bf7 JS |
5825 | starget->id == ndlp->nlp_sid) { |
5826 | spin_unlock_irq(shost->host_lock); | |
5827 | return ndlp; | |
dea3101e JB |
5828 | } |
5829 | } | |
5830 | spin_unlock_irq(shost->host_lock); | |
685f0bf7 JS |
5831 | return NULL; |
5832 | } | |
dea3101e | 5833 | |
e59058c4 | 5834 | /** |
3621a710 | 5835 | * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1 |
e59058c4 JS |
5836 | * @starget: kernel scsi target pointer. |
5837 | **/ | |
685f0bf7 JS |
5838 | static void |
5839 | lpfc_get_starget_port_id(struct scsi_target *starget) | |
5840 | { | |
5841 | struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget); | |
5842 | ||
5843 | fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1; | |
dea3101e JB |
5844 | } |
5845 | ||
e59058c4 | 5846 | /** |
3621a710 | 5847 | * lpfc_get_starget_node_name - Set the target node name |
e59058c4 JS |
5848 | * @starget: kernel scsi target pointer. |
5849 | * | |
5850 | * Description: Set the target node name to the ndlp node name wwn or zero. | |
5851 | **/ | |
dea3101e JB |
5852 | static void |
5853 | lpfc_get_starget_node_name(struct scsi_target *starget) | |
5854 | { | |
685f0bf7 | 5855 | struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget); |
dea3101e | 5856 | |
685f0bf7 JS |
5857 | fc_starget_node_name(starget) = |
5858 | ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0; | |
dea3101e JB |
5859 | } |
5860 | ||
e59058c4 | 5861 | /** |
3621a710 | 5862 | * lpfc_get_starget_port_name - Set the target port name |
e59058c4 JS |
5863 | * @starget: kernel scsi target pointer. |
5864 | * | |
5865 | * Description: set the target port name to the ndlp port name wwn or zero. | |
5866 | **/ | |
dea3101e JB |
5867 | static void |
5868 | lpfc_get_starget_port_name(struct scsi_target *starget) | |
5869 | { | |
685f0bf7 | 5870 | struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget); |
dea3101e | 5871 | |
685f0bf7 JS |
5872 | fc_starget_port_name(starget) = |
5873 | ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0; | |
dea3101e JB |
5874 | } |
5875 | ||
e59058c4 | 5876 | /** |
3621a710 | 5877 | * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo |
e59058c4 JS |
5878 | * @rport: fc rport address. |
5879 | * @timeout: new value for dev loss tmo. | |
5880 | * | |
5881 | * Description: | |
5882 | * If timeout is non zero set the dev_loss_tmo to timeout, else set | |
5883 | * dev_loss_tmo to one. | |
5884 | **/ | |
dea3101e JB |
5885 | static void |
5886 | lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout) | |
5887 | { | |
dea3101e | 5888 | if (timeout) |
c01f3208 | 5889 | rport->dev_loss_tmo = timeout; |
dea3101e | 5890 | else |
c01f3208 | 5891 | rport->dev_loss_tmo = 1; |
dea3101e JB |
5892 | } |
5893 | ||
e59058c4 | 5894 | /** |
3621a710 | 5895 | * lpfc_rport_show_function - Return rport target information |
e59058c4 JS |
5896 | * |
5897 | * Description: | |
5898 | * Macro that uses field to generate a function with the name lpfc_show_rport_ | |
5899 | * | |
5900 | * lpfc_show_rport_##field: returns the bytes formatted in buf | |
5901 | * @cdev: class converted to an fc_rport. | |
5902 | * @buf: on return contains the target_field or zero. | |
5903 | * | |
5904 | * Returns: size of formatted string. | |
5905 | **/ | |
dea3101e JB |
5906 | #define lpfc_rport_show_function(field, format_string, sz, cast) \ |
5907 | static ssize_t \ | |
ee959b00 TJ |
5908 | lpfc_show_rport_##field (struct device *dev, \ |
5909 | struct device_attribute *attr, \ | |
5910 | char *buf) \ | |
dea3101e | 5911 | { \ |
ee959b00 | 5912 | struct fc_rport *rport = transport_class_to_rport(dev); \ |
dea3101e JB |
5913 | struct lpfc_rport_data *rdata = rport->hostdata; \ |
5914 | return snprintf(buf, sz, format_string, \ | |
5915 | (rdata->target) ? cast rdata->target->field : 0); \ | |
5916 | } | |
5917 | ||
5918 | #define lpfc_rport_rd_attr(field, format_string, sz) \ | |
5919 | lpfc_rport_show_function(field, format_string, sz, ) \ | |
5920 | static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL) | |
5921 | ||
eada272d | 5922 | /** |
3621a710 | 5923 | * lpfc_set_vport_symbolic_name - Set the vport's symbolic name |
eada272d JS |
5924 | * @fc_vport: The fc_vport who's symbolic name has been changed. |
5925 | * | |
5926 | * Description: | |
5927 | * This function is called by the transport after the @fc_vport's symbolic name | |
5928 | * has been changed. This function re-registers the symbolic name with the | |
25985edc | 5929 | * switch to propagate the change into the fabric if the vport is active. |
eada272d JS |
5930 | **/ |
5931 | static void | |
5932 | lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport) | |
5933 | { | |
5934 | struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data; | |
5935 | ||
5936 | if (vport->port_state == LPFC_VPORT_READY) | |
5937 | lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0); | |
5938 | } | |
dea3101e | 5939 | |
f4b4c68f JS |
5940 | /** |
5941 | * lpfc_hba_log_verbose_init - Set hba's log verbose level | |
5942 | * @phba: Pointer to lpfc_hba struct. | |
5943 | * | |
5944 | * This function is called by the lpfc_get_cfgparam() routine to set the | |
5945 | * module lpfc_log_verbose into the @phba cfg_log_verbose for use with | |
70f23fd6 | 5946 | * log message according to the module's lpfc_log_verbose parameter setting |
f4b4c68f JS |
5947 | * before hba port or vport created. |
5948 | **/ | |
5949 | static void | |
5950 | lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose) | |
5951 | { | |
5952 | phba->cfg_log_verbose = verbose; | |
5953 | } | |
5954 | ||
dea3101e JB |
5955 | struct fc_function_template lpfc_transport_functions = { |
5956 | /* fixed attributes the driver supports */ | |
5957 | .show_host_node_name = 1, | |
5958 | .show_host_port_name = 1, | |
5959 | .show_host_supported_classes = 1, | |
5960 | .show_host_supported_fc4s = 1, | |
dea3101e JB |
5961 | .show_host_supported_speeds = 1, |
5962 | .show_host_maxframe_size = 1, | |
6c9231f6 JS |
5963 | |
5964 | .get_host_symbolic_name = lpfc_get_host_symbolic_name, | |
eada272d | 5965 | .show_host_symbolic_name = 1, |
dea3101e JB |
5966 | |
5967 | /* dynamic attributes the driver supports */ | |
5968 | .get_host_port_id = lpfc_get_host_port_id, | |
5969 | .show_host_port_id = 1, | |
5970 | ||
5971 | .get_host_port_type = lpfc_get_host_port_type, | |
5972 | .show_host_port_type = 1, | |
5973 | ||
5974 | .get_host_port_state = lpfc_get_host_port_state, | |
5975 | .show_host_port_state = 1, | |
5976 | ||
5977 | /* active_fc4s is shown but doesn't change (thus no get function) */ | |
5978 | .show_host_active_fc4s = 1, | |
5979 | ||
5980 | .get_host_speed = lpfc_get_host_speed, | |
5981 | .show_host_speed = 1, | |
5982 | ||
5983 | .get_host_fabric_name = lpfc_get_host_fabric_name, | |
5984 | .show_host_fabric_name = 1, | |
5985 | ||
5986 | /* | |
5987 | * The LPFC driver treats linkdown handling as target loss events | |
5988 | * so there are no sysfs handlers for link_down_tmo. | |
5989 | */ | |
5990 | ||
5991 | .get_fc_host_stats = lpfc_get_stats, | |
64ba8818 | 5992 | .reset_fc_host_stats = lpfc_reset_stats, |
dea3101e JB |
5993 | |
5994 | .dd_fcrport_size = sizeof(struct lpfc_rport_data), | |
5995 | .show_rport_maxframe_size = 1, | |
5996 | .show_rport_supported_classes = 1, | |
5997 | ||
dea3101e JB |
5998 | .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo, |
5999 | .show_rport_dev_loss_tmo = 1, | |
6000 | ||
6001 | .get_starget_port_id = lpfc_get_starget_port_id, | |
6002 | .show_starget_port_id = 1, | |
6003 | ||
6004 | .get_starget_node_name = lpfc_get_starget_node_name, | |
6005 | .show_starget_node_name = 1, | |
6006 | ||
6007 | .get_starget_port_name = lpfc_get_starget_port_name, | |
6008 | .show_starget_port_name = 1, | |
91ca7b01 AV |
6009 | |
6010 | .issue_fc_host_lip = lpfc_issue_lip, | |
c01f3208 JS |
6011 | .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk, |
6012 | .terminate_rport_io = lpfc_terminate_rport_io, | |
92d7f7b0 | 6013 | |
92d7f7b0 | 6014 | .dd_fcvport_size = sizeof(struct lpfc_vport *), |
eada272d JS |
6015 | |
6016 | .vport_disable = lpfc_vport_disable, | |
6017 | ||
6018 | .set_vport_symbolic_name = lpfc_set_vport_symbolic_name, | |
f1c3b0fc JS |
6019 | |
6020 | .bsg_request = lpfc_bsg_request, | |
6021 | .bsg_timeout = lpfc_bsg_timeout, | |
92d7f7b0 JS |
6022 | }; |
6023 | ||
98c9ea5c JS |
6024 | struct fc_function_template lpfc_vport_transport_functions = { |
6025 | /* fixed attributes the driver supports */ | |
6026 | .show_host_node_name = 1, | |
6027 | .show_host_port_name = 1, | |
6028 | .show_host_supported_classes = 1, | |
6029 | .show_host_supported_fc4s = 1, | |
6030 | .show_host_supported_speeds = 1, | |
6031 | .show_host_maxframe_size = 1, | |
6c9231f6 JS |
6032 | |
6033 | .get_host_symbolic_name = lpfc_get_host_symbolic_name, | |
eada272d | 6034 | .show_host_symbolic_name = 1, |
98c9ea5c JS |
6035 | |
6036 | /* dynamic attributes the driver supports */ | |
6037 | .get_host_port_id = lpfc_get_host_port_id, | |
6038 | .show_host_port_id = 1, | |
6039 | ||
6040 | .get_host_port_type = lpfc_get_host_port_type, | |
6041 | .show_host_port_type = 1, | |
6042 | ||
6043 | .get_host_port_state = lpfc_get_host_port_state, | |
6044 | .show_host_port_state = 1, | |
6045 | ||
6046 | /* active_fc4s is shown but doesn't change (thus no get function) */ | |
6047 | .show_host_active_fc4s = 1, | |
6048 | ||
6049 | .get_host_speed = lpfc_get_host_speed, | |
6050 | .show_host_speed = 1, | |
6051 | ||
6052 | .get_host_fabric_name = lpfc_get_host_fabric_name, | |
6053 | .show_host_fabric_name = 1, | |
6054 | ||
6055 | /* | |
6056 | * The LPFC driver treats linkdown handling as target loss events | |
6057 | * so there are no sysfs handlers for link_down_tmo. | |
6058 | */ | |
6059 | ||
6060 | .get_fc_host_stats = lpfc_get_stats, | |
6061 | .reset_fc_host_stats = lpfc_reset_stats, | |
6062 | ||
6063 | .dd_fcrport_size = sizeof(struct lpfc_rport_data), | |
6064 | .show_rport_maxframe_size = 1, | |
6065 | .show_rport_supported_classes = 1, | |
6066 | ||
6067 | .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo, | |
6068 | .show_rport_dev_loss_tmo = 1, | |
6069 | ||
6070 | .get_starget_port_id = lpfc_get_starget_port_id, | |
6071 | .show_starget_port_id = 1, | |
6072 | ||
6073 | .get_starget_node_name = lpfc_get_starget_node_name, | |
6074 | .show_starget_node_name = 1, | |
6075 | ||
6076 | .get_starget_port_name = lpfc_get_starget_port_name, | |
6077 | .show_starget_port_name = 1, | |
6078 | ||
6079 | .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk, | |
6080 | .terminate_rport_io = lpfc_terminate_rport_io, | |
6081 | ||
6082 | .vport_disable = lpfc_vport_disable, | |
eada272d JS |
6083 | |
6084 | .set_vport_symbolic_name = lpfc_set_vport_symbolic_name, | |
98c9ea5c JS |
6085 | }; |
6086 | ||
e59058c4 | 6087 | /** |
3621a710 | 6088 | * lpfc_get_cfgparam - Used during probe_one to init the adapter structure |
e59058c4 JS |
6089 | * @phba: lpfc_hba pointer. |
6090 | **/ | |
dea3101e JB |
6091 | void |
6092 | lpfc_get_cfgparam(struct lpfc_hba *phba) | |
6093 | { | |
49aa143d | 6094 | lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched); |
a6571c6e | 6095 | lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset); |
7bcbb752 JSEC |
6096 | lpfc_cr_delay_init(phba, lpfc_cr_delay); |
6097 | lpfc_cr_count_init(phba, lpfc_cr_count); | |
cf5bf97e | 6098 | lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support); |
a4bc3379 JS |
6099 | lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl); |
6100 | lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type); | |
7bcbb752 JSEC |
6101 | lpfc_ack0_init(phba, lpfc_ack0); |
6102 | lpfc_topology_init(phba, lpfc_topology); | |
7bcbb752 | 6103 | lpfc_link_speed_init(phba, lpfc_link_speed); |
875fbdfe | 6104 | lpfc_poll_tmo_init(phba, lpfc_poll_tmo); |
0c411222 | 6105 | lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo); |
78b2d852 | 6106 | lpfc_enable_npiv_init(phba, lpfc_enable_npiv); |
7d791df7 | 6107 | lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy); |
19ca7609 | 6108 | lpfc_enable_rrq_init(phba, lpfc_enable_rrq); |
4258e98e JS |
6109 | lpfc_fdmi_on_init(phba, lpfc_fdmi_on); |
6110 | lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN); | |
4ff43246 | 6111 | lpfc_use_msi_init(phba, lpfc_use_msi); |
895427bd | 6112 | lpfc_nvme_oas_init(phba, lpfc_nvme_oas); |
da0436e9 | 6113 | lpfc_fcp_imax_init(phba, lpfc_fcp_imax); |
7bb03bbf | 6114 | lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map); |
13815c83 JS |
6115 | lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset); |
6116 | lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat); | |
2ea259ee | 6117 | |
1ba981fd JS |
6118 | lpfc_EnableXLane_init(phba, lpfc_EnableXLane); |
6119 | if (phba->sli_rev != LPFC_SLI_REV4) | |
6120 | phba->cfg_EnableXLane = 0; | |
6121 | lpfc_XLanePriority_init(phba, lpfc_XLanePriority); | |
2ea259ee | 6122 | |
1ba981fd JS |
6123 | memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t))); |
6124 | memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t))); | |
6125 | phba->cfg_oas_lun_state = 0; | |
6126 | phba->cfg_oas_lun_status = 0; | |
6127 | phba->cfg_oas_flags = 0; | |
c92c841c | 6128 | phba->cfg_oas_priority = 0; |
81301a9b | 6129 | lpfc_enable_bg_init(phba, lpfc_enable_bg); |
b3b98b74 JS |
6130 | lpfc_prot_mask_init(phba, lpfc_prot_mask); |
6131 | lpfc_prot_guard_init(phba, lpfc_prot_guard); | |
45ed1190 JS |
6132 | if (phba->sli_rev == LPFC_SLI_REV4) |
6133 | phba->cfg_poll = 0; | |
6134 | else | |
1ba981fd | 6135 | phba->cfg_poll = lpfc_poll; |
f358dd0c | 6136 | lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp); |
4258e98e | 6137 | |
895427bd JS |
6138 | lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type); |
6139 | ||
6140 | /* Initialize first burst. Target vs Initiator are different. */ | |
6141 | lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb); | |
6142 | lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel); | |
6143 | lpfc_nvme_io_channel_init(phba, lpfc_nvme_io_channel); | |
6144 | ||
6145 | if (phba->sli_rev != LPFC_SLI_REV4) { | |
6146 | /* NVME only supported on SLI4 */ | |
6147 | phba->nvmet_support = 0; | |
6148 | phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP; | |
6149 | } else { | |
6150 | /* We MUST have FCP support */ | |
6151 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) | |
6152 | phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP; | |
6153 | } | |
6154 | ||
6155 | /* A value of 0 means use the number of CPUs found in the system */ | |
895427bd JS |
6156 | if (phba->cfg_fcp_io_channel == 0) |
6157 | phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu; | |
f358dd0c JS |
6158 | if (phba->cfg_nvme_io_channel == 0) |
6159 | phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu; | |
895427bd JS |
6160 | |
6161 | if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME) | |
6162 | phba->cfg_fcp_io_channel = 0; | |
6163 | ||
f358dd0c JS |
6164 | if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) |
6165 | phba->cfg_nvme_io_channel = 0; | |
6166 | ||
895427bd JS |
6167 | if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel) |
6168 | phba->io_channel_irqs = phba->cfg_fcp_io_channel; | |
6169 | else | |
6170 | phba->io_channel_irqs = phba->cfg_nvme_io_channel; | |
6171 | ||
352e5fd1 JS |
6172 | phba->cfg_soft_wwnn = 0L; |
6173 | phba->cfg_soft_wwpn = 0L; | |
895427bd | 6174 | lpfc_xri_split_init(phba, lpfc_xri_split); |
83108bd3 | 6175 | lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt); |
7054a606 | 6176 | lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth); |
6fb120a7 | 6177 | lpfc_hba_log_verbose_init(phba, lpfc_log_verbose); |
0d878419 | 6178 | lpfc_aer_support_init(phba, lpfc_aer_support); |
912e3acd | 6179 | lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn); |
c71ab861 | 6180 | lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade); |
84d1b006 | 6181 | lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up); |
2a9bf3d0 | 6182 | lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt); |
8eb8b960 | 6183 | lpfc_delay_discovery_init(phba, lpfc_delay_discovery); |
12247e81 | 6184 | lpfc_sli_mode_init(phba, lpfc_sli_mode); |
ab56dc2e | 6185 | phba->cfg_enable_dss = 1; |
7bdedb34 | 6186 | lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags); |
3de2a653 JS |
6187 | return; |
6188 | } | |
b28485ac | 6189 | |
895427bd JS |
6190 | /** |
6191 | * lpfc_nvme_mod_param_dep - Adjust module parameter value based on | |
6192 | * dependencies between protocols and roles. | |
6193 | * @phba: lpfc_hba pointer. | |
6194 | **/ | |
6195 | void | |
6196 | lpfc_nvme_mod_param_dep(struct lpfc_hba *phba) | |
6197 | { | |
895427bd JS |
6198 | if (phba->cfg_nvme_io_channel > phba->sli4_hba.num_present_cpu) |
6199 | phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu; | |
f358dd0c | 6200 | |
895427bd JS |
6201 | if (phba->cfg_fcp_io_channel > phba->sli4_hba.num_present_cpu) |
6202 | phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu; | |
6203 | ||
f358dd0c JS |
6204 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME && |
6205 | phba->nvmet_support) { | |
6206 | phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP; | |
6207 | phba->cfg_fcp_io_channel = 0; | |
6208 | } else | |
6209 | /* Not NVME Target mode. Turn off Target parameters. */ | |
6210 | phba->nvmet_support = 0; | |
6211 | ||
895427bd JS |
6212 | if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel) |
6213 | phba->io_channel_irqs = phba->cfg_fcp_io_channel; | |
6214 | else | |
6215 | phba->io_channel_irqs = phba->cfg_nvme_io_channel; | |
6216 | } | |
6217 | ||
e59058c4 | 6218 | /** |
3621a710 | 6219 | * lpfc_get_vport_cfgparam - Used during port create, init the vport structure |
e59058c4 JS |
6220 | * @vport: lpfc_vport pointer. |
6221 | **/ | |
3de2a653 JS |
6222 | void |
6223 | lpfc_get_vport_cfgparam(struct lpfc_vport *vport) | |
6224 | { | |
e8b62011 | 6225 | lpfc_log_verbose_init(vport, lpfc_log_verbose); |
3de2a653 | 6226 | lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth); |
7dc517df | 6227 | lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth); |
3de2a653 JS |
6228 | lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo); |
6229 | lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo); | |
6230 | lpfc_peer_port_login_init(vport, lpfc_peer_port_login); | |
6231 | lpfc_restrict_login_init(vport, lpfc_restrict_login); | |
6232 | lpfc_fcp_class_init(vport, lpfc_fcp_class); | |
6233 | lpfc_use_adisc_init(vport, lpfc_use_adisc); | |
3cb01c57 | 6234 | lpfc_first_burst_size_init(vport, lpfc_first_burst_size); |
977b5a0a | 6235 | lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time); |
3de2a653 JS |
6236 | lpfc_discovery_threads_init(vport, lpfc_discovery_threads); |
6237 | lpfc_max_luns_init(vport, lpfc_max_luns); | |
6238 | lpfc_scan_down_init(vport, lpfc_scan_down); | |
7ee5d43e | 6239 | lpfc_enable_da_id_init(vport, lpfc_enable_da_id); |
dea3101e JB |
6240 | return; |
6241 | } |