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