]>
Commit | Line | Data |
---|---|---|
dea3101e JB |
1 | /******************************************************************* |
2 | * This file is part of the Emulex Linux Device Driver for * | |
c44ce173 JSEC |
3 | * Fibre Channel Host Bus Adapters. * |
4 | * Copyright (C) 2004-2005 Emulex. All rights reserved. * | |
5 | * EMULEX and SLI are trademarks of Emulex. * | |
dea3101e | 6 | * www.emulex.com * |
c44ce173 | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
dea3101e JB |
8 | * * |
9 | * This program is free software; you can redistribute it and/or * | |
c44ce173 JSEC |
10 | * modify it under the terms of version 2 of the GNU General * |
11 | * Public License as published by the Free Software Foundation. * | |
12 | * This program is distributed in the hope that it will be useful. * | |
13 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * | |
14 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * | |
15 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * | |
16 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * | |
17 | * TO BE LEGALLY INVALID. See the GNU General Public License for * | |
18 | * more details, a copy of which can be found in the file COPYING * | |
19 | * included with this package. * | |
dea3101e JB |
20 | *******************************************************************/ |
21 | ||
dea3101e JB |
22 | #include <linux/ctype.h> |
23 | #include <linux/pci.h> | |
24 | #include <linux/interrupt.h> | |
25 | ||
91886523 | 26 | #include <scsi/scsi.h> |
dea3101e JB |
27 | #include <scsi/scsi_device.h> |
28 | #include <scsi/scsi_host.h> | |
29 | #include <scsi/scsi_tcq.h> | |
30 | #include <scsi/scsi_transport_fc.h> | |
31 | ||
32 | #include "lpfc_hw.h" | |
33 | #include "lpfc_sli.h" | |
34 | #include "lpfc_disc.h" | |
35 | #include "lpfc_scsi.h" | |
36 | #include "lpfc.h" | |
37 | #include "lpfc_logmsg.h" | |
38 | #include "lpfc_version.h" | |
39 | #include "lpfc_compat.h" | |
40 | #include "lpfc_crtn.h" | |
41 | ||
42 | ||
43 | static void | |
44 | lpfc_jedec_to_ascii(int incr, char hdw[]) | |
45 | { | |
46 | int i, j; | |
47 | for (i = 0; i < 8; i++) { | |
48 | j = (incr & 0xf); | |
49 | if (j <= 9) | |
50 | hdw[7 - i] = 0x30 + j; | |
51 | else | |
52 | hdw[7 - i] = 0x61 + j - 10; | |
53 | incr = (incr >> 4); | |
54 | } | |
55 | hdw[8] = 0; | |
56 | return; | |
57 | } | |
58 | ||
59 | static ssize_t | |
60 | lpfc_drvr_version_show(struct class_device *cdev, char *buf) | |
61 | { | |
62 | return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n"); | |
63 | } | |
64 | ||
65 | static ssize_t | |
66 | management_version_show(struct class_device *cdev, char *buf) | |
67 | { | |
68 | return snprintf(buf, PAGE_SIZE, DFC_API_VERSION "\n"); | |
69 | } | |
70 | ||
71 | static ssize_t | |
72 | lpfc_info_show(struct class_device *cdev, char *buf) | |
73 | { | |
74 | struct Scsi_Host *host = class_to_shost(cdev); | |
75 | return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host)); | |
76 | } | |
77 | ||
78 | static ssize_t | |
79 | lpfc_serialnum_show(struct class_device *cdev, char *buf) | |
80 | { | |
81 | struct Scsi_Host *host = class_to_shost(cdev); | |
82 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0]; | |
83 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber); | |
84 | } | |
85 | ||
86 | static ssize_t | |
87 | lpfc_modeldesc_show(struct class_device *cdev, char *buf) | |
88 | { | |
89 | struct Scsi_Host *host = class_to_shost(cdev); | |
90 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0]; | |
91 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc); | |
92 | } | |
93 | ||
94 | static ssize_t | |
95 | lpfc_modelname_show(struct class_device *cdev, char *buf) | |
96 | { | |
97 | struct Scsi_Host *host = class_to_shost(cdev); | |
98 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0]; | |
99 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName); | |
100 | } | |
101 | ||
102 | static ssize_t | |
103 | lpfc_programtype_show(struct class_device *cdev, char *buf) | |
104 | { | |
105 | struct Scsi_Host *host = class_to_shost(cdev); | |
106 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0]; | |
107 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType); | |
108 | } | |
109 | ||
110 | static ssize_t | |
111 | lpfc_portnum_show(struct class_device *cdev, char *buf) | |
112 | { | |
113 | struct Scsi_Host *host = class_to_shost(cdev); | |
114 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0]; | |
115 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port); | |
116 | } | |
117 | ||
118 | static ssize_t | |
119 | lpfc_fwrev_show(struct class_device *cdev, char *buf) | |
120 | { | |
121 | struct Scsi_Host *host = class_to_shost(cdev); | |
122 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0]; | |
123 | char fwrev[32]; | |
124 | lpfc_decode_firmware_rev(phba, fwrev, 1); | |
125 | return snprintf(buf, PAGE_SIZE, "%s\n",fwrev); | |
126 | } | |
127 | ||
128 | static ssize_t | |
129 | lpfc_hdw_show(struct class_device *cdev, char *buf) | |
130 | { | |
131 | char hdw[9]; | |
132 | struct Scsi_Host *host = class_to_shost(cdev); | |
133 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0]; | |
134 | lpfc_vpd_t *vp = &phba->vpd; | |
135 | lpfc_jedec_to_ascii(vp->rev.biuRev, hdw); | |
136 | return snprintf(buf, PAGE_SIZE, "%s\n", hdw); | |
137 | } | |
138 | static ssize_t | |
139 | lpfc_option_rom_version_show(struct class_device *cdev, char *buf) | |
140 | { | |
141 | struct Scsi_Host *host = class_to_shost(cdev); | |
142 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0]; | |
143 | return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion); | |
144 | } | |
145 | static ssize_t | |
146 | lpfc_state_show(struct class_device *cdev, char *buf) | |
147 | { | |
148 | struct Scsi_Host *host = class_to_shost(cdev); | |
149 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0]; | |
150 | int len = 0; | |
151 | switch (phba->hba_state) { | |
152 | case LPFC_INIT_START: | |
153 | case LPFC_INIT_MBX_CMDS: | |
154 | case LPFC_LINK_DOWN: | |
155 | len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n"); | |
156 | break; | |
157 | case LPFC_LINK_UP: | |
158 | case LPFC_LOCAL_CFG_LINK: | |
159 | len += snprintf(buf + len, PAGE_SIZE-len, "Link Up\n"); | |
160 | break; | |
161 | case LPFC_FLOGI: | |
162 | case LPFC_FABRIC_CFG_LINK: | |
163 | case LPFC_NS_REG: | |
164 | case LPFC_NS_QRY: | |
165 | case LPFC_BUILD_DISC_LIST: | |
166 | case LPFC_DISC_AUTH: | |
167 | case LPFC_CLEAR_LA: | |
168 | len += snprintf(buf + len, PAGE_SIZE-len, | |
169 | "Link Up - Discovery\n"); | |
170 | break; | |
171 | case LPFC_HBA_READY: | |
172 | len += snprintf(buf + len, PAGE_SIZE-len, | |
173 | "Link Up - Ready:\n"); | |
174 | if (phba->fc_topology == TOPOLOGY_LOOP) { | |
175 | if (phba->fc_flag & FC_PUBLIC_LOOP) | |
176 | len += snprintf(buf + len, PAGE_SIZE-len, | |
177 | " Public Loop\n"); | |
178 | else | |
179 | len += snprintf(buf + len, PAGE_SIZE-len, | |
180 | " Private Loop\n"); | |
181 | } else { | |
182 | if (phba->fc_flag & FC_FABRIC) | |
183 | len += snprintf(buf + len, PAGE_SIZE-len, | |
184 | " Fabric\n"); | |
185 | else | |
186 | len += snprintf(buf + len, PAGE_SIZE-len, | |
187 | " Point-2-Point\n"); | |
188 | } | |
189 | } | |
190 | return len; | |
191 | } | |
192 | ||
193 | static ssize_t | |
194 | lpfc_num_discovered_ports_show(struct class_device *cdev, char *buf) | |
195 | { | |
196 | struct Scsi_Host *host = class_to_shost(cdev); | |
197 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0]; | |
198 | return snprintf(buf, PAGE_SIZE, "%d\n", phba->fc_map_cnt + | |
199 | phba->fc_unmap_cnt); | |
200 | } | |
201 | ||
202 | ||
91ca7b01 AV |
203 | static int |
204 | lpfc_issue_lip(struct Scsi_Host *host) | |
dea3101e | 205 | { |
dea3101e | 206 | struct lpfc_hba *phba = (struct lpfc_hba *) host->hostdata[0]; |
dea3101e JB |
207 | LPFC_MBOXQ_t *pmboxq; |
208 | int mbxstatus = MBXERR_ERROR; | |
209 | ||
dea3101e JB |
210 | if ((phba->fc_flag & FC_OFFLINE_MODE) || |
211 | (phba->hba_state != LPFC_HBA_READY)) | |
212 | return -EPERM; | |
213 | ||
214 | pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL); | |
215 | ||
216 | if (!pmboxq) | |
217 | return -ENOMEM; | |
218 | ||
219 | memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t)); | |
220 | lpfc_init_link(phba, pmboxq, phba->cfg_topology, phba->cfg_link_speed); | |
221 | mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); | |
222 | ||
223 | if (mbxstatus == MBX_TIMEOUT) | |
224 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
225 | else | |
433c3579 | 226 | mempool_free(pmboxq, phba->mbox_mem_pool); |
dea3101e JB |
227 | |
228 | if (mbxstatus == MBXERR_ERROR) | |
229 | return -EIO; | |
230 | ||
91ca7b01 | 231 | return 0; |
dea3101e JB |
232 | } |
233 | ||
234 | static ssize_t | |
235 | lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf) | |
236 | { | |
237 | struct Scsi_Host *host = class_to_shost(cdev); | |
238 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0]; | |
239 | return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt); | |
240 | } | |
241 | ||
242 | static ssize_t | |
243 | lpfc_board_online_show(struct class_device *cdev, char *buf) | |
244 | { | |
245 | struct Scsi_Host *host = class_to_shost(cdev); | |
246 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0]; | |
247 | ||
248 | if (!phba) return 0; | |
249 | ||
250 | if (phba->fc_flag & FC_OFFLINE_MODE) | |
251 | return snprintf(buf, PAGE_SIZE, "0\n"); | |
252 | else | |
253 | return snprintf(buf, PAGE_SIZE, "1\n"); | |
254 | } | |
255 | ||
256 | static ssize_t | |
257 | lpfc_board_online_store(struct class_device *cdev, const char *buf, | |
258 | size_t count) | |
259 | { | |
260 | struct Scsi_Host *host = class_to_shost(cdev); | |
261 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0]; | |
262 | struct completion online_compl; | |
263 | int val=0, status=0; | |
264 | ||
265 | if (sscanf(buf, "%d", &val) != 1) | |
266 | return 0; | |
267 | ||
268 | init_completion(&online_compl); | |
269 | ||
270 | if (val) | |
271 | lpfc_workq_post_event(phba, &status, &online_compl, | |
272 | LPFC_EVT_ONLINE); | |
273 | else | |
274 | lpfc_workq_post_event(phba, &status, &online_compl, | |
275 | LPFC_EVT_OFFLINE); | |
276 | wait_for_completion(&online_compl); | |
277 | if (!status) | |
278 | return strlen(buf); | |
279 | else | |
280 | return 0; | |
281 | } | |
282 | ||
283 | ||
284 | #define lpfc_param_show(attr) \ | |
285 | static ssize_t \ | |
286 | lpfc_##attr##_show(struct class_device *cdev, char *buf) \ | |
287 | { \ | |
288 | struct Scsi_Host *host = class_to_shost(cdev);\ | |
289 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];\ | |
290 | int val = 0;\ | |
291 | if (phba){\ | |
292 | val = phba->cfg_##attr;\ | |
293 | return snprintf(buf, PAGE_SIZE, "%d\n",\ | |
294 | phba->cfg_##attr);\ | |
295 | }\ | |
296 | return 0;\ | |
297 | } | |
298 | ||
299 | #define lpfc_param_store(attr, minval, maxval) \ | |
300 | static ssize_t \ | |
301 | lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \ | |
302 | { \ | |
303 | struct Scsi_Host *host = class_to_shost(cdev);\ | |
304 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];\ | |
305 | int val = 0;\ | |
306 | if (!isdigit(buf[0]))\ | |
307 | return -EINVAL;\ | |
308 | if (sscanf(buf, "0x%x", &val) != 1)\ | |
309 | if (sscanf(buf, "%d", &val) != 1)\ | |
310 | return -EINVAL;\ | |
311 | if (phba){\ | |
312 | if (val >= minval && val <= maxval) {\ | |
313 | phba->cfg_##attr = val;\ | |
314 | return strlen(buf);\ | |
315 | }\ | |
316 | }\ | |
317 | return 0;\ | |
318 | } | |
319 | ||
320 | #define LPFC_ATTR_R_NOINIT(name, desc) \ | |
321 | extern int lpfc_##name;\ | |
322 | module_param(lpfc_##name, int, 0);\ | |
323 | MODULE_PARM_DESC(lpfc_##name, desc);\ | |
324 | lpfc_param_show(name)\ | |
325 | static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL) | |
326 | ||
327 | #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \ | |
328 | static int lpfc_##name = defval;\ | |
329 | module_param(lpfc_##name, int, 0);\ | |
330 | MODULE_PARM_DESC(lpfc_##name, desc);\ | |
331 | lpfc_param_show(name)\ | |
332 | static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL) | |
333 | ||
334 | #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \ | |
335 | static int lpfc_##name = defval;\ | |
336 | module_param(lpfc_##name, int, 0);\ | |
337 | MODULE_PARM_DESC(lpfc_##name, desc);\ | |
338 | lpfc_param_show(name)\ | |
339 | lpfc_param_store(name, minval, maxval)\ | |
340 | static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\ | |
341 | lpfc_##name##_show, lpfc_##name##_store) | |
342 | ||
343 | static CLASS_DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL); | |
344 | static CLASS_DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL); | |
345 | static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL); | |
346 | static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL); | |
347 | static CLASS_DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL); | |
348 | static CLASS_DEVICE_ATTR(portnum, S_IRUGO, lpfc_portnum_show, NULL); | |
349 | static CLASS_DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL); | |
350 | static CLASS_DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL); | |
351 | static CLASS_DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL); | |
352 | static CLASS_DEVICE_ATTR(option_rom_version, S_IRUGO, | |
353 | lpfc_option_rom_version_show, NULL); | |
354 | static CLASS_DEVICE_ATTR(num_discovered_ports, S_IRUGO, | |
355 | lpfc_num_discovered_ports_show, NULL); | |
356 | static CLASS_DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL); | |
357 | static CLASS_DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, | |
358 | NULL); | |
359 | static CLASS_DEVICE_ATTR(management_version, S_IRUGO, management_version_show, | |
360 | NULL); | |
dea3101e JB |
361 | static CLASS_DEVICE_ATTR(board_online, S_IRUGO | S_IWUSR, |
362 | lpfc_board_online_show, lpfc_board_online_store); | |
363 | ||
364 | ||
365 | /* | |
366 | # lpfc_log_verbose: Only turn this flag on if you are willing to risk being | |
367 | # deluged with LOTS of information. | |
368 | # You can set a bit mask to record specific types of verbose messages: | |
369 | # | |
370 | # LOG_ELS 0x1 ELS events | |
371 | # LOG_DISCOVERY 0x2 Link discovery events | |
372 | # LOG_MBOX 0x4 Mailbox events | |
373 | # LOG_INIT 0x8 Initialization events | |
374 | # LOG_LINK_EVENT 0x10 Link events | |
375 | # LOG_IP 0x20 IP traffic history | |
376 | # LOG_FCP 0x40 FCP traffic history | |
377 | # LOG_NODE 0x80 Node table events | |
378 | # LOG_MISC 0x400 Miscellaneous events | |
379 | # LOG_SLI 0x800 SLI events | |
380 | # LOG_CHK_COND 0x1000 FCP Check condition flag | |
381 | # LOG_LIBDFC 0x2000 LIBDFC events | |
382 | # LOG_ALL_MSG 0xffff LOG all messages | |
383 | */ | |
384 | LPFC_ATTR_RW(log_verbose, 0x0, 0x0, 0xffff, "Verbose logging bit-mask"); | |
385 | ||
386 | /* | |
387 | # lun_queue_depth: This parameter is used to limit the number of outstanding | |
388 | # commands per FCP LUN. Value range is [1,128]. Default value is 30. | |
389 | */ | |
390 | LPFC_ATTR_R(lun_queue_depth, 30, 1, 128, | |
391 | "Max number of FCP commands we can queue to a specific LUN"); | |
392 | ||
393 | /* | |
394 | # Some disk devices have a "select ID" or "select Target" capability. | |
395 | # From a protocol standpoint "select ID" usually means select the | |
396 | # Fibre channel "ALPA". In the FC-AL Profile there is an "informative | |
397 | # annex" which contains a table that maps a "select ID" (a number | |
398 | # between 0 and 7F) to an ALPA. By default, for compatibility with | |
399 | # older drivers, the lpfc driver scans this table from low ALPA to high | |
400 | # ALPA. | |
401 | # | |
402 | # Turning on the scan-down variable (on = 1, off = 0) will | |
403 | # cause the lpfc driver to use an inverted table, effectively | |
404 | # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1. | |
405 | # | |
406 | # (Note: This "select ID" functionality is a LOOP ONLY characteristic | |
407 | # and will not work across a fabric. Also this parameter will take | |
408 | # effect only in the case when ALPA map is not available.) | |
409 | */ | |
410 | LPFC_ATTR_R(scan_down, 1, 0, 1, | |
411 | "Start scanning for devices from highest ALPA to lowest"); | |
412 | ||
413 | /* | |
414 | # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear | |
415 | # until the timer expires. Value range is [0,255]. Default value is 20. | |
416 | # NOTE: this MUST be less then the SCSI Layer command timeout - 1. | |
417 | */ | |
418 | LPFC_ATTR_RW(nodev_tmo, 30, 0, 255, | |
419 | "Seconds driver will hold I/O waiting for a device to come back"); | |
420 | ||
421 | /* | |
422 | # lpfc_topology: link topology for init link | |
423 | # 0x0 = attempt loop mode then point-to-point | |
424 | # 0x02 = attempt point-to-point mode only | |
425 | # 0x04 = attempt loop mode only | |
426 | # 0x06 = attempt point-to-point mode then loop | |
427 | # Set point-to-point mode if you want to run as an N_Port. | |
428 | # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6]. | |
429 | # Default value is 0. | |
430 | */ | |
431 | LPFC_ATTR_R(topology, 0, 0, 6, "Select Fibre Channel topology"); | |
432 | ||
433 | /* | |
434 | # lpfc_link_speed: Link speed selection for initializing the Fibre Channel | |
435 | # connection. | |
436 | # 0 = auto select (default) | |
437 | # 1 = 1 Gigabaud | |
438 | # 2 = 2 Gigabaud | |
439 | # 4 = 4 Gigabaud | |
440 | # Value range is [0,4]. Default value is 0. | |
441 | */ | |
442 | LPFC_ATTR_R(link_speed, 0, 0, 4, "Select link speed"); | |
443 | ||
444 | /* | |
445 | # lpfc_fcp_class: Determines FC class to use for the FCP protocol. | |
446 | # Value range is [2,3]. Default value is 3. | |
447 | */ | |
448 | LPFC_ATTR_R(fcp_class, 3, 2, 3, | |
449 | "Select Fibre Channel class of service for FCP sequences"); | |
450 | ||
451 | /* | |
452 | # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range | |
453 | # is [0,1]. Default value is 0. | |
454 | */ | |
455 | LPFC_ATTR_RW(use_adisc, 0, 0, 1, | |
456 | "Use ADISC on rediscovery to authenticate FCP devices"); | |
457 | ||
458 | /* | |
459 | # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value | |
460 | # range is [0,1]. Default value is 0. | |
461 | */ | |
462 | LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support"); | |
463 | ||
464 | /* | |
465 | # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing | |
466 | # cr_delay (msec) or cr_count outstanding commands. cr_delay can take | |
467 | # value [0,63]. cr_count can take value [0,255]. Default value of cr_delay | |
468 | # is 0. Default value of cr_count is 1. The cr_count feature is disabled if | |
469 | # cr_delay is set to 0. | |
470 | */ | |
471 | static int lpfc_cr_delay = 0; | |
472 | module_param(lpfc_cr_delay, int , 0); | |
473 | MODULE_PARM_DESC(lpfc_cr_delay, "A count of milliseconds after which an " | |
474 | "interrupt response is generated"); | |
475 | ||
476 | static int lpfc_cr_count = 1; | |
477 | module_param(lpfc_cr_count, int, 0); | |
478 | MODULE_PARM_DESC(lpfc_cr_count, "A count of I/O completions after which an " | |
479 | "interrupt response is generated"); | |
480 | ||
481 | /* | |
482 | # lpfc_fdmi_on: controls FDMI support. | |
483 | # 0 = no FDMI support | |
484 | # 1 = support FDMI without attribute of hostname | |
485 | # 2 = support FDMI with attribute of hostname | |
486 | # Value range [0,2]. Default value is 0. | |
487 | */ | |
488 | LPFC_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support"); | |
489 | ||
490 | /* | |
491 | # Specifies the maximum number of ELS cmds we can have outstanding (for | |
492 | # discovery). Value range is [1,64]. Default value = 32. | |
493 | */ | |
494 | static int lpfc_discovery_threads = 32; | |
495 | module_param(lpfc_discovery_threads, int, 0); | |
496 | MODULE_PARM_DESC(lpfc_discovery_threads, "Maximum number of ELS commands " | |
497 | "during discovery"); | |
498 | ||
499 | /* | |
500 | # lpfc_max_luns: maximum number of LUNs per target driver will support | |
501 | # Value range is [1,32768]. Default value is 256. | |
502 | # NOTE: The SCSI layer will scan each target for this many luns | |
503 | */ | |
504 | LPFC_ATTR_R(max_luns, 256, 1, 32768, | |
505 | "Maximum number of LUNs per target driver will support"); | |
506 | ||
507 | struct class_device_attribute *lpfc_host_attrs[] = { | |
508 | &class_device_attr_info, | |
509 | &class_device_attr_serialnum, | |
510 | &class_device_attr_modeldesc, | |
511 | &class_device_attr_modelname, | |
512 | &class_device_attr_programtype, | |
513 | &class_device_attr_portnum, | |
514 | &class_device_attr_fwrev, | |
515 | &class_device_attr_hdw, | |
516 | &class_device_attr_option_rom_version, | |
517 | &class_device_attr_state, | |
518 | &class_device_attr_num_discovered_ports, | |
519 | &class_device_attr_lpfc_drvr_version, | |
520 | &class_device_attr_lpfc_log_verbose, | |
521 | &class_device_attr_lpfc_lun_queue_depth, | |
522 | &class_device_attr_lpfc_nodev_tmo, | |
523 | &class_device_attr_lpfc_fcp_class, | |
524 | &class_device_attr_lpfc_use_adisc, | |
525 | &class_device_attr_lpfc_ack0, | |
526 | &class_device_attr_lpfc_topology, | |
527 | &class_device_attr_lpfc_scan_down, | |
528 | &class_device_attr_lpfc_link_speed, | |
529 | &class_device_attr_lpfc_fdmi_on, | |
530 | &class_device_attr_lpfc_max_luns, | |
531 | &class_device_attr_nport_evt_cnt, | |
532 | &class_device_attr_management_version, | |
dea3101e JB |
533 | &class_device_attr_board_online, |
534 | NULL, | |
535 | }; | |
536 | ||
537 | static ssize_t | |
538 | sysfs_ctlreg_write(struct kobject *kobj, char *buf, loff_t off, size_t count) | |
539 | { | |
540 | size_t buf_off; | |
541 | struct Scsi_Host *host = class_to_shost(container_of(kobj, | |
542 | struct class_device, kobj)); | |
543 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0]; | |
544 | ||
545 | if ((off + count) > FF_REG_AREA_SIZE) | |
546 | return -ERANGE; | |
547 | ||
548 | if (count == 0) return 0; | |
549 | ||
550 | if (off % 4 || count % 4 || (unsigned long)buf % 4) | |
551 | return -EINVAL; | |
552 | ||
553 | spin_lock_irq(phba->host->host_lock); | |
554 | ||
555 | if (!(phba->fc_flag & FC_OFFLINE_MODE)) { | |
556 | spin_unlock_irq(phba->host->host_lock); | |
557 | return -EPERM; | |
558 | } | |
559 | ||
560 | for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) | |
561 | writel(*((uint32_t *)(buf + buf_off)), | |
562 | phba->ctrl_regs_memmap_p + off + buf_off); | |
563 | ||
564 | spin_unlock_irq(phba->host->host_lock); | |
565 | ||
566 | return count; | |
567 | } | |
568 | ||
569 | static ssize_t | |
570 | sysfs_ctlreg_read(struct kobject *kobj, char *buf, loff_t off, size_t count) | |
571 | { | |
572 | size_t buf_off; | |
573 | uint32_t * tmp_ptr; | |
574 | struct Scsi_Host *host = class_to_shost(container_of(kobj, | |
575 | struct class_device, kobj)); | |
576 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0]; | |
577 | ||
578 | if (off > FF_REG_AREA_SIZE) | |
579 | return -ERANGE; | |
580 | ||
581 | if ((off + count) > FF_REG_AREA_SIZE) | |
582 | count = FF_REG_AREA_SIZE - off; | |
583 | ||
584 | if (count == 0) return 0; | |
585 | ||
586 | if (off % 4 || count % 4 || (unsigned long)buf % 4) | |
587 | return -EINVAL; | |
588 | ||
589 | spin_lock_irq(phba->host->host_lock); | |
590 | ||
591 | for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) { | |
592 | tmp_ptr = (uint32_t *)(buf + buf_off); | |
593 | *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off); | |
594 | } | |
595 | ||
596 | spin_unlock_irq(phba->host->host_lock); | |
597 | ||
598 | return count; | |
599 | } | |
600 | ||
601 | static struct bin_attribute sysfs_ctlreg_attr = { | |
602 | .attr = { | |
603 | .name = "ctlreg", | |
604 | .mode = S_IRUSR | S_IWUSR, | |
605 | .owner = THIS_MODULE, | |
606 | }, | |
607 | .size = 256, | |
608 | .read = sysfs_ctlreg_read, | |
609 | .write = sysfs_ctlreg_write, | |
610 | }; | |
611 | ||
612 | ||
613 | static void | |
614 | sysfs_mbox_idle (struct lpfc_hba * phba) | |
615 | { | |
616 | phba->sysfs_mbox.state = SMBOX_IDLE; | |
617 | phba->sysfs_mbox.offset = 0; | |
618 | ||
619 | if (phba->sysfs_mbox.mbox) { | |
620 | mempool_free(phba->sysfs_mbox.mbox, | |
621 | phba->mbox_mem_pool); | |
622 | phba->sysfs_mbox.mbox = NULL; | |
623 | } | |
624 | } | |
625 | ||
626 | static ssize_t | |
627 | sysfs_mbox_write(struct kobject *kobj, char *buf, loff_t off, size_t count) | |
628 | { | |
629 | struct Scsi_Host * host = | |
630 | class_to_shost(container_of(kobj, struct class_device, kobj)); | |
631 | struct lpfc_hba * phba = (struct lpfc_hba*)host->hostdata[0]; | |
632 | struct lpfcMboxq * mbox = NULL; | |
633 | ||
634 | if ((count + off) > MAILBOX_CMD_SIZE) | |
635 | return -ERANGE; | |
636 | ||
637 | if (off % 4 || count % 4 || (unsigned long)buf % 4) | |
638 | return -EINVAL; | |
639 | ||
640 | if (count == 0) | |
641 | return 0; | |
642 | ||
643 | if (off == 0) { | |
644 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
645 | if (!mbox) | |
646 | return -ENOMEM; | |
647 | ||
648 | } | |
649 | ||
650 | spin_lock_irq(host->host_lock); | |
651 | ||
652 | if (off == 0) { | |
653 | if (phba->sysfs_mbox.mbox) | |
654 | mempool_free(mbox, phba->mbox_mem_pool); | |
655 | else | |
656 | phba->sysfs_mbox.mbox = mbox; | |
657 | phba->sysfs_mbox.state = SMBOX_WRITING; | |
658 | } else { | |
659 | if (phba->sysfs_mbox.state != SMBOX_WRITING || | |
660 | phba->sysfs_mbox.offset != off || | |
661 | phba->sysfs_mbox.mbox == NULL ) { | |
662 | sysfs_mbox_idle(phba); | |
663 | spin_unlock_irq(host->host_lock); | |
664 | return -EINVAL; | |
665 | } | |
666 | } | |
667 | ||
668 | memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off, | |
669 | buf, count); | |
670 | ||
671 | phba->sysfs_mbox.offset = off + count; | |
672 | ||
673 | spin_unlock_irq(host->host_lock); | |
674 | ||
675 | return count; | |
676 | } | |
677 | ||
678 | static ssize_t | |
679 | sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count) | |
680 | { | |
681 | struct Scsi_Host *host = | |
682 | class_to_shost(container_of(kobj, struct class_device, | |
683 | kobj)); | |
684 | struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0]; | |
685 | int rc; | |
686 | ||
687 | if (off > sizeof(MAILBOX_t)) | |
688 | return -ERANGE; | |
689 | ||
690 | if ((count + off) > sizeof(MAILBOX_t)) | |
691 | count = sizeof(MAILBOX_t) - off; | |
692 | ||
693 | if (off % 4 || count % 4 || (unsigned long)buf % 4) | |
694 | return -EINVAL; | |
695 | ||
696 | if (off && count == 0) | |
697 | return 0; | |
698 | ||
699 | spin_lock_irq(phba->host->host_lock); | |
700 | ||
701 | if (off == 0 && | |
702 | phba->sysfs_mbox.state == SMBOX_WRITING && | |
703 | phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) { | |
704 | ||
705 | switch (phba->sysfs_mbox.mbox->mb.mbxCommand) { | |
706 | /* Offline only */ | |
707 | case MBX_WRITE_NV: | |
708 | case MBX_INIT_LINK: | |
709 | case MBX_DOWN_LINK: | |
710 | case MBX_CONFIG_LINK: | |
711 | case MBX_CONFIG_RING: | |
712 | case MBX_RESET_RING: | |
713 | case MBX_UNREG_LOGIN: | |
714 | case MBX_CLEAR_LA: | |
715 | case MBX_DUMP_CONTEXT: | |
716 | case MBX_RUN_DIAGS: | |
717 | case MBX_RESTART: | |
718 | case MBX_FLASH_WR_ULA: | |
719 | case MBX_SET_MASK: | |
720 | case MBX_SET_SLIM: | |
721 | case MBX_SET_DEBUG: | |
722 | if (!(phba->fc_flag & FC_OFFLINE_MODE)) { | |
723 | printk(KERN_WARNING "mbox_read:Command 0x%x " | |
724 | "is illegal in on-line state\n", | |
725 | phba->sysfs_mbox.mbox->mb.mbxCommand); | |
726 | sysfs_mbox_idle(phba); | |
727 | spin_unlock_irq(phba->host->host_lock); | |
728 | return -EPERM; | |
729 | } | |
730 | case MBX_LOAD_SM: | |
731 | case MBX_READ_NV: | |
732 | case MBX_READ_CONFIG: | |
733 | case MBX_READ_RCONFIG: | |
734 | case MBX_READ_STATUS: | |
735 | case MBX_READ_XRI: | |
736 | case MBX_READ_REV: | |
737 | case MBX_READ_LNK_STAT: | |
738 | case MBX_DUMP_MEMORY: | |
739 | case MBX_DOWN_LOAD: | |
740 | case MBX_UPDATE_CFG: | |
741 | case MBX_LOAD_AREA: | |
742 | case MBX_LOAD_EXP_ROM: | |
743 | break; | |
744 | case MBX_READ_SPARM64: | |
745 | case MBX_READ_LA: | |
746 | case MBX_READ_LA64: | |
747 | case MBX_REG_LOGIN: | |
748 | case MBX_REG_LOGIN64: | |
749 | case MBX_CONFIG_PORT: | |
750 | case MBX_RUN_BIU_DIAG: | |
751 | printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n", | |
752 | phba->sysfs_mbox.mbox->mb.mbxCommand); | |
753 | sysfs_mbox_idle(phba); | |
754 | spin_unlock_irq(phba->host->host_lock); | |
755 | return -EPERM; | |
756 | default: | |
757 | printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n", | |
758 | phba->sysfs_mbox.mbox->mb.mbxCommand); | |
759 | sysfs_mbox_idle(phba); | |
760 | spin_unlock_irq(phba->host->host_lock); | |
761 | return -EPERM; | |
762 | } | |
763 | ||
764 | if ((phba->fc_flag & FC_OFFLINE_MODE) || | |
765 | (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){ | |
766 | ||
767 | spin_unlock_irq(phba->host->host_lock); | |
768 | rc = lpfc_sli_issue_mbox (phba, | |
769 | phba->sysfs_mbox.mbox, | |
770 | MBX_POLL); | |
771 | spin_lock_irq(phba->host->host_lock); | |
772 | ||
773 | } else { | |
774 | spin_unlock_irq(phba->host->host_lock); | |
775 | rc = lpfc_sli_issue_mbox_wait (phba, | |
776 | phba->sysfs_mbox.mbox, | |
777 | phba->fc_ratov * 2); | |
778 | spin_lock_irq(phba->host->host_lock); | |
779 | } | |
780 | ||
781 | if (rc != MBX_SUCCESS) { | |
782 | sysfs_mbox_idle(phba); | |
783 | spin_unlock_irq(host->host_lock); | |
784 | return -ENODEV; | |
785 | } | |
786 | phba->sysfs_mbox.state = SMBOX_READING; | |
787 | } | |
788 | else if (phba->sysfs_mbox.offset != off || | |
789 | phba->sysfs_mbox.state != SMBOX_READING) { | |
790 | printk(KERN_WARNING "mbox_read: Bad State\n"); | |
791 | sysfs_mbox_idle(phba); | |
792 | spin_unlock_irq(host->host_lock); | |
793 | return -EINVAL; | |
794 | } | |
795 | ||
796 | memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count); | |
797 | ||
798 | phba->sysfs_mbox.offset = off + count; | |
799 | ||
800 | if (phba->sysfs_mbox.offset == sizeof(MAILBOX_t)) | |
801 | sysfs_mbox_idle(phba); | |
802 | ||
803 | spin_unlock_irq(phba->host->host_lock); | |
804 | ||
805 | return count; | |
806 | } | |
807 | ||
808 | static struct bin_attribute sysfs_mbox_attr = { | |
809 | .attr = { | |
810 | .name = "mbox", | |
811 | .mode = S_IRUSR | S_IWUSR, | |
812 | .owner = THIS_MODULE, | |
813 | }, | |
814 | .size = sizeof(MAILBOX_t), | |
815 | .read = sysfs_mbox_read, | |
816 | .write = sysfs_mbox_write, | |
817 | }; | |
818 | ||
819 | int | |
820 | lpfc_alloc_sysfs_attr(struct lpfc_hba *phba) | |
821 | { | |
822 | struct Scsi_Host *host = phba->host; | |
823 | int error; | |
824 | ||
825 | error = sysfs_create_bin_file(&host->shost_classdev.kobj, | |
826 | &sysfs_ctlreg_attr); | |
827 | if (error) | |
828 | goto out; | |
829 | ||
830 | error = sysfs_create_bin_file(&host->shost_classdev.kobj, | |
831 | &sysfs_mbox_attr); | |
832 | if (error) | |
833 | goto out_remove_ctlreg_attr; | |
834 | ||
835 | return 0; | |
836 | out_remove_ctlreg_attr: | |
837 | sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr); | |
838 | out: | |
839 | return error; | |
840 | } | |
841 | ||
842 | void | |
843 | lpfc_free_sysfs_attr(struct lpfc_hba *phba) | |
844 | { | |
845 | struct Scsi_Host *host = phba->host; | |
846 | ||
847 | sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_mbox_attr); | |
848 | sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr); | |
849 | } | |
850 | ||
851 | ||
852 | /* | |
853 | * Dynamic FC Host Attributes Support | |
854 | */ | |
855 | ||
856 | static void | |
857 | lpfc_get_host_port_id(struct Scsi_Host *shost) | |
858 | { | |
859 | struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata[0]; | |
860 | /* note: fc_myDID already in cpu endianness */ | |
861 | fc_host_port_id(shost) = phba->fc_myDID; | |
862 | } | |
863 | ||
864 | static void | |
865 | lpfc_get_host_port_type(struct Scsi_Host *shost) | |
866 | { | |
867 | struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata[0]; | |
868 | ||
869 | spin_lock_irq(shost->host_lock); | |
870 | ||
871 | if (phba->hba_state == LPFC_HBA_READY) { | |
872 | if (phba->fc_topology == TOPOLOGY_LOOP) { | |
873 | if (phba->fc_flag & FC_PUBLIC_LOOP) | |
874 | fc_host_port_type(shost) = FC_PORTTYPE_NLPORT; | |
875 | else | |
876 | fc_host_port_type(shost) = FC_PORTTYPE_LPORT; | |
877 | } else { | |
878 | if (phba->fc_flag & FC_FABRIC) | |
879 | fc_host_port_type(shost) = FC_PORTTYPE_NPORT; | |
880 | else | |
881 | fc_host_port_type(shost) = FC_PORTTYPE_PTP; | |
882 | } | |
883 | } else | |
884 | fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN; | |
885 | ||
886 | spin_unlock_irq(shost->host_lock); | |
887 | } | |
888 | ||
889 | static void | |
890 | lpfc_get_host_port_state(struct Scsi_Host *shost) | |
891 | { | |
892 | struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata[0]; | |
893 | ||
894 | spin_lock_irq(shost->host_lock); | |
895 | ||
896 | if (phba->fc_flag & FC_OFFLINE_MODE) | |
897 | fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE; | |
898 | else { | |
899 | switch (phba->hba_state) { | |
900 | case LPFC_INIT_START: | |
901 | case LPFC_INIT_MBX_CMDS: | |
902 | case LPFC_LINK_DOWN: | |
903 | fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN; | |
904 | break; | |
905 | case LPFC_LINK_UP: | |
906 | case LPFC_LOCAL_CFG_LINK: | |
907 | case LPFC_FLOGI: | |
908 | case LPFC_FABRIC_CFG_LINK: | |
909 | case LPFC_NS_REG: | |
910 | case LPFC_NS_QRY: | |
911 | case LPFC_BUILD_DISC_LIST: | |
912 | case LPFC_DISC_AUTH: | |
913 | case LPFC_CLEAR_LA: | |
914 | case LPFC_HBA_READY: | |
915 | /* Links up, beyond this port_type reports state */ | |
916 | fc_host_port_state(shost) = FC_PORTSTATE_ONLINE; | |
917 | break; | |
918 | case LPFC_HBA_ERROR: | |
919 | fc_host_port_state(shost) = FC_PORTSTATE_ERROR; | |
920 | break; | |
921 | default: | |
922 | fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN; | |
923 | break; | |
924 | } | |
925 | } | |
926 | ||
927 | spin_unlock_irq(shost->host_lock); | |
928 | } | |
929 | ||
930 | static void | |
931 | lpfc_get_host_speed(struct Scsi_Host *shost) | |
932 | { | |
933 | struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata[0]; | |
934 | ||
935 | spin_lock_irq(shost->host_lock); | |
936 | ||
937 | if (phba->hba_state == LPFC_HBA_READY) { | |
938 | switch(phba->fc_linkspeed) { | |
939 | case LA_1GHZ_LINK: | |
940 | fc_host_speed(shost) = FC_PORTSPEED_1GBIT; | |
941 | break; | |
942 | case LA_2GHZ_LINK: | |
943 | fc_host_speed(shost) = FC_PORTSPEED_2GBIT; | |
944 | break; | |
945 | case LA_4GHZ_LINK: | |
946 | fc_host_speed(shost) = FC_PORTSPEED_4GBIT; | |
947 | break; | |
948 | default: | |
949 | fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN; | |
950 | break; | |
951 | } | |
952 | } | |
953 | ||
954 | spin_unlock_irq(shost->host_lock); | |
955 | } | |
956 | ||
957 | static void | |
958 | lpfc_get_host_fabric_name (struct Scsi_Host *shost) | |
959 | { | |
960 | struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata[0]; | |
f631b4be | 961 | u64 node_name; |
dea3101e JB |
962 | |
963 | spin_lock_irq(shost->host_lock); | |
964 | ||
965 | if ((phba->fc_flag & FC_FABRIC) || | |
966 | ((phba->fc_topology == TOPOLOGY_LOOP) && | |
967 | (phba->fc_flag & FC_PUBLIC_LOOP))) | |
68ce1eb5 | 968 | node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn); |
dea3101e JB |
969 | else |
970 | /* fabric is local port if there is no F/FL_Port */ | |
68ce1eb5 | 971 | node_name = wwn_to_u64(phba->fc_nodename.u.wwn); |
dea3101e JB |
972 | |
973 | spin_unlock_irq(shost->host_lock); | |
974 | ||
f631b4be | 975 | fc_host_fabric_name(shost) = node_name; |
dea3101e JB |
976 | } |
977 | ||
978 | ||
979 | static struct fc_host_statistics * | |
980 | lpfc_get_stats(struct Scsi_Host *shost) | |
981 | { | |
982 | struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata[0]; | |
983 | struct lpfc_sli *psli = &phba->sli; | |
f888ba3c | 984 | struct fc_host_statistics *hs = &phba->link_stats; |
dea3101e JB |
985 | LPFC_MBOXQ_t *pmboxq; |
986 | MAILBOX_t *pmb; | |
433c3579 | 987 | int rc = 0; |
dea3101e JB |
988 | |
989 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
990 | if (!pmboxq) | |
991 | return NULL; | |
992 | memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t)); | |
993 | ||
994 | pmb = &pmboxq->mb; | |
995 | pmb->mbxCommand = MBX_READ_STATUS; | |
996 | pmb->mbxOwner = OWN_HOST; | |
997 | pmboxq->context1 = NULL; | |
998 | ||
999 | if ((phba->fc_flag & FC_OFFLINE_MODE) || | |
433c3579 | 1000 | (!(psli->sli_flag & LPFC_SLI2_ACTIVE))) |
dea3101e | 1001 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); |
433c3579 | 1002 | else |
dea3101e JB |
1003 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); |
1004 | ||
1005 | if (rc != MBX_SUCCESS) { | |
433c3579 JSEC |
1006 | if (rc == MBX_TIMEOUT) |
1007 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
1008 | else | |
1009 | mempool_free(pmboxq, phba->mbox_mem_pool); | |
dea3101e JB |
1010 | return NULL; |
1011 | } | |
1012 | ||
f888ba3c JSEC |
1013 | memset(hs, 0, sizeof (struct fc_host_statistics)); |
1014 | ||
dea3101e JB |
1015 | hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt; |
1016 | hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256); | |
1017 | hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt; | |
1018 | hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256); | |
1019 | ||
433c3579 | 1020 | memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t)); |
dea3101e JB |
1021 | pmb->mbxCommand = MBX_READ_LNK_STAT; |
1022 | pmb->mbxOwner = OWN_HOST; | |
1023 | pmboxq->context1 = NULL; | |
1024 | ||
1025 | if ((phba->fc_flag & FC_OFFLINE_MODE) || | |
433c3579 | 1026 | (!(psli->sli_flag & LPFC_SLI2_ACTIVE))) |
dea3101e | 1027 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); |
433c3579 | 1028 | else |
dea3101e JB |
1029 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); |
1030 | ||
1031 | if (rc != MBX_SUCCESS) { | |
433c3579 JSEC |
1032 | if (rc == MBX_TIMEOUT) |
1033 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
1034 | else | |
1035 | mempool_free( pmboxq, phba->mbox_mem_pool); | |
dea3101e JB |
1036 | return NULL; |
1037 | } | |
1038 | ||
1039 | hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt; | |
1040 | hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt; | |
1041 | hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt; | |
1042 | hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt; | |
1043 | hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord; | |
1044 | hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt; | |
1045 | hs->error_frames = pmb->un.varRdLnk.crcCnt; | |
1046 | ||
1047 | if (phba->fc_topology == TOPOLOGY_LOOP) { | |
1048 | hs->lip_count = (phba->fc_eventTag >> 1); | |
1049 | hs->nos_count = -1; | |
1050 | } else { | |
1051 | hs->lip_count = -1; | |
1052 | hs->nos_count = (phba->fc_eventTag >> 1); | |
1053 | } | |
1054 | ||
1055 | hs->dumped_frames = -1; | |
1056 | ||
1057 | /* FIX ME */ | |
1058 | /*hs->SecondsSinceLastReset = (jiffies - lpfc_loadtime) / HZ;*/ | |
1059 | ||
1060 | return hs; | |
1061 | } | |
1062 | ||
1063 | ||
1064 | /* | |
1065 | * The LPFC driver treats linkdown handling as target loss events so there | |
1066 | * are no sysfs handlers for link_down_tmo. | |
1067 | */ | |
1068 | static void | |
1069 | lpfc_get_starget_port_id(struct scsi_target *starget) | |
1070 | { | |
1071 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); | |
1072 | struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata[0]; | |
1073 | uint32_t did = -1; | |
1074 | struct lpfc_nodelist *ndlp = NULL; | |
1075 | ||
1076 | spin_lock_irq(shost->host_lock); | |
1077 | /* Search the mapped list for this target ID */ | |
1078 | list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) { | |
1079 | if (starget->id == ndlp->nlp_sid) { | |
1080 | did = ndlp->nlp_DID; | |
1081 | break; | |
1082 | } | |
1083 | } | |
1084 | spin_unlock_irq(shost->host_lock); | |
1085 | ||
1086 | fc_starget_port_id(starget) = did; | |
1087 | } | |
1088 | ||
1089 | static void | |
1090 | lpfc_get_starget_node_name(struct scsi_target *starget) | |
1091 | { | |
1092 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); | |
1093 | struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata[0]; | |
f631b4be | 1094 | u64 node_name = 0; |
dea3101e JB |
1095 | struct lpfc_nodelist *ndlp = NULL; |
1096 | ||
1097 | spin_lock_irq(shost->host_lock); | |
1098 | /* Search the mapped list for this target ID */ | |
1099 | list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) { | |
1100 | if (starget->id == ndlp->nlp_sid) { | |
68ce1eb5 | 1101 | node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn); |
dea3101e JB |
1102 | break; |
1103 | } | |
1104 | } | |
1105 | spin_unlock_irq(shost->host_lock); | |
1106 | ||
f631b4be | 1107 | fc_starget_node_name(starget) = node_name; |
dea3101e JB |
1108 | } |
1109 | ||
1110 | static void | |
1111 | lpfc_get_starget_port_name(struct scsi_target *starget) | |
1112 | { | |
1113 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); | |
1114 | struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata[0]; | |
f631b4be | 1115 | u64 port_name = 0; |
dea3101e JB |
1116 | struct lpfc_nodelist *ndlp = NULL; |
1117 | ||
1118 | spin_lock_irq(shost->host_lock); | |
1119 | /* Search the mapped list for this target ID */ | |
1120 | list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) { | |
1121 | if (starget->id == ndlp->nlp_sid) { | |
68ce1eb5 | 1122 | port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn); |
dea3101e JB |
1123 | break; |
1124 | } | |
1125 | } | |
1126 | spin_unlock_irq(shost->host_lock); | |
1127 | ||
f631b4be | 1128 | fc_starget_port_name(starget) = port_name; |
dea3101e JB |
1129 | } |
1130 | ||
1131 | static void | |
1132 | lpfc_get_rport_loss_tmo(struct fc_rport *rport) | |
1133 | { | |
1134 | /* | |
1135 | * Return the driver's global value for device loss timeout plus | |
1136 | * five seconds to allow the driver's nodev timer to run. | |
1137 | */ | |
1138 | rport->dev_loss_tmo = lpfc_nodev_tmo + 5; | |
1139 | } | |
1140 | ||
1141 | static void | |
1142 | lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout) | |
1143 | { | |
1144 | /* | |
1145 | * The driver doesn't have a per-target timeout setting. Set | |
1146 | * this value globally. lpfc_nodev_tmo should be greater then 0. | |
1147 | */ | |
1148 | if (timeout) | |
1149 | lpfc_nodev_tmo = timeout; | |
1150 | else | |
1151 | lpfc_nodev_tmo = 1; | |
1152 | rport->dev_loss_tmo = lpfc_nodev_tmo + 5; | |
1153 | } | |
1154 | ||
1155 | ||
1156 | #define lpfc_rport_show_function(field, format_string, sz, cast) \ | |
1157 | static ssize_t \ | |
1158 | lpfc_show_rport_##field (struct class_device *cdev, char *buf) \ | |
1159 | { \ | |
1160 | struct fc_rport *rport = transport_class_to_rport(cdev); \ | |
1161 | struct lpfc_rport_data *rdata = rport->hostdata; \ | |
1162 | return snprintf(buf, sz, format_string, \ | |
1163 | (rdata->target) ? cast rdata->target->field : 0); \ | |
1164 | } | |
1165 | ||
1166 | #define lpfc_rport_rd_attr(field, format_string, sz) \ | |
1167 | lpfc_rport_show_function(field, format_string, sz, ) \ | |
1168 | static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL) | |
1169 | ||
1170 | ||
1171 | struct fc_function_template lpfc_transport_functions = { | |
1172 | /* fixed attributes the driver supports */ | |
1173 | .show_host_node_name = 1, | |
1174 | .show_host_port_name = 1, | |
1175 | .show_host_supported_classes = 1, | |
1176 | .show_host_supported_fc4s = 1, | |
1177 | .show_host_symbolic_name = 1, | |
1178 | .show_host_supported_speeds = 1, | |
1179 | .show_host_maxframe_size = 1, | |
1180 | ||
1181 | /* dynamic attributes the driver supports */ | |
1182 | .get_host_port_id = lpfc_get_host_port_id, | |
1183 | .show_host_port_id = 1, | |
1184 | ||
1185 | .get_host_port_type = lpfc_get_host_port_type, | |
1186 | .show_host_port_type = 1, | |
1187 | ||
1188 | .get_host_port_state = lpfc_get_host_port_state, | |
1189 | .show_host_port_state = 1, | |
1190 | ||
1191 | /* active_fc4s is shown but doesn't change (thus no get function) */ | |
1192 | .show_host_active_fc4s = 1, | |
1193 | ||
1194 | .get_host_speed = lpfc_get_host_speed, | |
1195 | .show_host_speed = 1, | |
1196 | ||
1197 | .get_host_fabric_name = lpfc_get_host_fabric_name, | |
1198 | .show_host_fabric_name = 1, | |
1199 | ||
1200 | /* | |
1201 | * The LPFC driver treats linkdown handling as target loss events | |
1202 | * so there are no sysfs handlers for link_down_tmo. | |
1203 | */ | |
1204 | ||
1205 | .get_fc_host_stats = lpfc_get_stats, | |
1206 | ||
1207 | /* the LPFC driver doesn't support resetting stats yet */ | |
1208 | ||
1209 | .dd_fcrport_size = sizeof(struct lpfc_rport_data), | |
1210 | .show_rport_maxframe_size = 1, | |
1211 | .show_rport_supported_classes = 1, | |
1212 | ||
1213 | .get_rport_dev_loss_tmo = lpfc_get_rport_loss_tmo, | |
1214 | .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo, | |
1215 | .show_rport_dev_loss_tmo = 1, | |
1216 | ||
1217 | .get_starget_port_id = lpfc_get_starget_port_id, | |
1218 | .show_starget_port_id = 1, | |
1219 | ||
1220 | .get_starget_node_name = lpfc_get_starget_node_name, | |
1221 | .show_starget_node_name = 1, | |
1222 | ||
1223 | .get_starget_port_name = lpfc_get_starget_port_name, | |
1224 | .show_starget_port_name = 1, | |
91ca7b01 AV |
1225 | |
1226 | .issue_fc_host_lip = lpfc_issue_lip, | |
dea3101e JB |
1227 | }; |
1228 | ||
1229 | void | |
1230 | lpfc_get_cfgparam(struct lpfc_hba *phba) | |
1231 | { | |
1232 | phba->cfg_log_verbose = lpfc_log_verbose; | |
1233 | phba->cfg_cr_delay = lpfc_cr_delay; | |
1234 | phba->cfg_cr_count = lpfc_cr_count; | |
1235 | phba->cfg_lun_queue_depth = lpfc_lun_queue_depth; | |
1236 | phba->cfg_fcp_class = lpfc_fcp_class; | |
1237 | phba->cfg_use_adisc = lpfc_use_adisc; | |
1238 | phba->cfg_ack0 = lpfc_ack0; | |
1239 | phba->cfg_topology = lpfc_topology; | |
1240 | phba->cfg_scan_down = lpfc_scan_down; | |
1241 | phba->cfg_nodev_tmo = lpfc_nodev_tmo; | |
1242 | phba->cfg_link_speed = lpfc_link_speed; | |
1243 | phba->cfg_fdmi_on = lpfc_fdmi_on; | |
1244 | phba->cfg_discovery_threads = lpfc_discovery_threads; | |
1245 | phba->cfg_max_luns = lpfc_max_luns; | |
1246 | ||
1247 | /* | |
1248 | * The total number of segments is the configuration value plus 2 | |
1249 | * since the IOCB need a command and response bde. | |
1250 | */ | |
1251 | phba->cfg_sg_seg_cnt = LPFC_SG_SEG_CNT + 2; | |
1252 | ||
1253 | /* | |
1254 | * Since the sg_tablesize is module parameter, the sg_dma_buf_size | |
1255 | * used to create the sg_dma_buf_pool must be dynamically calculated | |
1256 | */ | |
1257 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + | |
1258 | sizeof(struct fcp_rsp) + | |
1259 | (phba->cfg_sg_seg_cnt * sizeof(struct ulp_bde64)); | |
1260 | ||
1261 | switch (phba->pcidev->device) { | |
1262 | case PCI_DEVICE_ID_LP101: | |
1263 | case PCI_DEVICE_ID_BSMB: | |
1264 | case PCI_DEVICE_ID_ZSMB: | |
1265 | phba->cfg_hba_queue_depth = LPFC_LP101_HBA_Q_DEPTH; | |
1266 | break; | |
1267 | case PCI_DEVICE_ID_RFLY: | |
1268 | case PCI_DEVICE_ID_PFLY: | |
1269 | case PCI_DEVICE_ID_BMID: | |
1270 | case PCI_DEVICE_ID_ZMID: | |
1271 | case PCI_DEVICE_ID_TFLY: | |
1272 | phba->cfg_hba_queue_depth = LPFC_LC_HBA_Q_DEPTH; | |
1273 | break; | |
1274 | default: | |
1275 | phba->cfg_hba_queue_depth = LPFC_DFT_HBA_Q_DEPTH; | |
1276 | } | |
1277 | return; | |
1278 | } |