qla_attr.c 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2014 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include "qla_target.h"
  9. #include <linux/kthread.h>
  10. #include <linux/vmalloc.h>
  11. #include <linux/slab.h>
  12. #include <linux/delay.h>
  13. static int qla24xx_vport_disable(struct fc_vport *, bool);
  14. /* SYSFS attributes --------------------------------------------------------- */
  15. static ssize_t
  16. qla2x00_sysfs_read_fw_dump(struct file *filp, struct kobject *kobj,
  17. struct bin_attribute *bin_attr,
  18. char *buf, loff_t off, size_t count)
  19. {
  20. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  21. struct device, kobj)));
  22. struct qla_hw_data *ha = vha->hw;
  23. int rval = 0;
  24. if (!(ha->fw_dump_reading || ha->mctp_dump_reading))
  25. return 0;
  26. if (IS_P3P_TYPE(ha)) {
  27. if (off < ha->md_template_size) {
  28. rval = memory_read_from_buffer(buf, count,
  29. &off, ha->md_tmplt_hdr, ha->md_template_size);
  30. return rval;
  31. }
  32. off -= ha->md_template_size;
  33. rval = memory_read_from_buffer(buf, count,
  34. &off, ha->md_dump, ha->md_dump_size);
  35. return rval;
  36. } else if (ha->mctp_dumped && ha->mctp_dump_reading)
  37. return memory_read_from_buffer(buf, count, &off, ha->mctp_dump,
  38. MCTP_DUMP_SIZE);
  39. else if (ha->fw_dump_reading)
  40. return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
  41. ha->fw_dump_len);
  42. else
  43. return 0;
  44. }
  45. static ssize_t
  46. qla2x00_sysfs_write_fw_dump(struct file *filp, struct kobject *kobj,
  47. struct bin_attribute *bin_attr,
  48. char *buf, loff_t off, size_t count)
  49. {
  50. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  51. struct device, kobj)));
  52. struct qla_hw_data *ha = vha->hw;
  53. int reading;
  54. if (off != 0)
  55. return (0);
  56. reading = simple_strtol(buf, NULL, 10);
  57. switch (reading) {
  58. case 0:
  59. if (!ha->fw_dump_reading)
  60. break;
  61. ql_log(ql_log_info, vha, 0x705d,
  62. "Firmware dump cleared on (%ld).\n", vha->host_no);
  63. if (IS_P3P_TYPE(ha)) {
  64. qla82xx_md_free(vha);
  65. qla82xx_md_prep(vha);
  66. }
  67. ha->fw_dump_reading = 0;
  68. ha->fw_dumped = 0;
  69. break;
  70. case 1:
  71. if (ha->fw_dumped && !ha->fw_dump_reading) {
  72. ha->fw_dump_reading = 1;
  73. ql_log(ql_log_info, vha, 0x705e,
  74. "Raw firmware dump ready for read on (%ld).\n",
  75. vha->host_no);
  76. }
  77. break;
  78. case 2:
  79. qla2x00_alloc_fw_dump(vha);
  80. break;
  81. case 3:
  82. if (IS_QLA82XX(ha)) {
  83. qla82xx_idc_lock(ha);
  84. qla82xx_set_reset_owner(vha);
  85. qla82xx_idc_unlock(ha);
  86. } else if (IS_QLA8044(ha)) {
  87. qla8044_idc_lock(ha);
  88. qla82xx_set_reset_owner(vha);
  89. qla8044_idc_unlock(ha);
  90. } else
  91. qla2x00_system_error(vha);
  92. break;
  93. case 4:
  94. if (IS_P3P_TYPE(ha)) {
  95. if (ha->md_tmplt_hdr)
  96. ql_dbg(ql_dbg_user, vha, 0x705b,
  97. "MiniDump supported with this firmware.\n");
  98. else
  99. ql_dbg(ql_dbg_user, vha, 0x709d,
  100. "MiniDump not supported with this firmware.\n");
  101. }
  102. break;
  103. case 5:
  104. if (IS_P3P_TYPE(ha))
  105. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  106. break;
  107. case 6:
  108. if (!ha->mctp_dump_reading)
  109. break;
  110. ql_log(ql_log_info, vha, 0x70c1,
  111. "MCTP dump cleared on (%ld).\n", vha->host_no);
  112. ha->mctp_dump_reading = 0;
  113. ha->mctp_dumped = 0;
  114. break;
  115. case 7:
  116. if (ha->mctp_dumped && !ha->mctp_dump_reading) {
  117. ha->mctp_dump_reading = 1;
  118. ql_log(ql_log_info, vha, 0x70c2,
  119. "Raw mctp dump ready for read on (%ld).\n",
  120. vha->host_no);
  121. }
  122. break;
  123. }
  124. return count;
  125. }
  126. static struct bin_attribute sysfs_fw_dump_attr = {
  127. .attr = {
  128. .name = "fw_dump",
  129. .mode = S_IRUSR | S_IWUSR,
  130. },
  131. .size = 0,
  132. .read = qla2x00_sysfs_read_fw_dump,
  133. .write = qla2x00_sysfs_write_fw_dump,
  134. };
  135. static ssize_t
  136. qla2x00_sysfs_read_nvram(struct file *filp, struct kobject *kobj,
  137. struct bin_attribute *bin_attr,
  138. char *buf, loff_t off, size_t count)
  139. {
  140. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  141. struct device, kobj)));
  142. struct qla_hw_data *ha = vha->hw;
  143. if (!capable(CAP_SYS_ADMIN))
  144. return 0;
  145. if (IS_NOCACHE_VPD_TYPE(ha))
  146. ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
  147. ha->nvram_size);
  148. return memory_read_from_buffer(buf, count, &off, ha->nvram,
  149. ha->nvram_size);
  150. }
  151. static ssize_t
  152. qla2x00_sysfs_write_nvram(struct file *filp, struct kobject *kobj,
  153. struct bin_attribute *bin_attr,
  154. char *buf, loff_t off, size_t count)
  155. {
  156. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  157. struct device, kobj)));
  158. struct qla_hw_data *ha = vha->hw;
  159. uint16_t cnt;
  160. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
  161. !ha->isp_ops->write_nvram)
  162. return -EINVAL;
  163. /* Checksum NVRAM. */
  164. if (IS_FWI2_CAPABLE(ha)) {
  165. uint32_t *iter;
  166. uint32_t chksum;
  167. iter = (uint32_t *)buf;
  168. chksum = 0;
  169. for (cnt = 0; cnt < ((count >> 2) - 1); cnt++, iter++)
  170. chksum += le32_to_cpu(*iter);
  171. chksum = ~chksum + 1;
  172. *iter = cpu_to_le32(chksum);
  173. } else {
  174. uint8_t *iter;
  175. uint8_t chksum;
  176. iter = (uint8_t *)buf;
  177. chksum = 0;
  178. for (cnt = 0; cnt < count - 1; cnt++)
  179. chksum += *iter++;
  180. chksum = ~chksum + 1;
  181. *iter = chksum;
  182. }
  183. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  184. ql_log(ql_log_warn, vha, 0x705f,
  185. "HBA not online, failing NVRAM update.\n");
  186. return -EAGAIN;
  187. }
  188. /* Write NVRAM. */
  189. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
  190. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
  191. count);
  192. ql_dbg(ql_dbg_user, vha, 0x7060,
  193. "Setting ISP_ABORT_NEEDED\n");
  194. /* NVRAM settings take effect immediately. */
  195. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  196. qla2xxx_wake_dpc(vha);
  197. qla2x00_wait_for_chip_reset(vha);
  198. return count;
  199. }
  200. static struct bin_attribute sysfs_nvram_attr = {
  201. .attr = {
  202. .name = "nvram",
  203. .mode = S_IRUSR | S_IWUSR,
  204. },
  205. .size = 512,
  206. .read = qla2x00_sysfs_read_nvram,
  207. .write = qla2x00_sysfs_write_nvram,
  208. };
  209. static ssize_t
  210. qla2x00_sysfs_read_optrom(struct file *filp, struct kobject *kobj,
  211. struct bin_attribute *bin_attr,
  212. char *buf, loff_t off, size_t count)
  213. {
  214. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  215. struct device, kobj)));
  216. struct qla_hw_data *ha = vha->hw;
  217. ssize_t rval = 0;
  218. mutex_lock(&ha->optrom_mutex);
  219. if (ha->optrom_state != QLA_SREADING)
  220. goto out;
  221. rval = memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
  222. ha->optrom_region_size);
  223. out:
  224. mutex_unlock(&ha->optrom_mutex);
  225. return rval;
  226. }
  227. static ssize_t
  228. qla2x00_sysfs_write_optrom(struct file *filp, struct kobject *kobj,
  229. struct bin_attribute *bin_attr,
  230. char *buf, loff_t off, size_t count)
  231. {
  232. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  233. struct device, kobj)));
  234. struct qla_hw_data *ha = vha->hw;
  235. mutex_lock(&ha->optrom_mutex);
  236. if (ha->optrom_state != QLA_SWRITING) {
  237. mutex_unlock(&ha->optrom_mutex);
  238. return -EINVAL;
  239. }
  240. if (off > ha->optrom_region_size) {
  241. mutex_unlock(&ha->optrom_mutex);
  242. return -ERANGE;
  243. }
  244. if (off + count > ha->optrom_region_size)
  245. count = ha->optrom_region_size - off;
  246. memcpy(&ha->optrom_buffer[off], buf, count);
  247. mutex_unlock(&ha->optrom_mutex);
  248. return count;
  249. }
  250. static struct bin_attribute sysfs_optrom_attr = {
  251. .attr = {
  252. .name = "optrom",
  253. .mode = S_IRUSR | S_IWUSR,
  254. },
  255. .size = 0,
  256. .read = qla2x00_sysfs_read_optrom,
  257. .write = qla2x00_sysfs_write_optrom,
  258. };
  259. static ssize_t
  260. qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
  261. struct bin_attribute *bin_attr,
  262. char *buf, loff_t off, size_t count)
  263. {
  264. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  265. struct device, kobj)));
  266. struct qla_hw_data *ha = vha->hw;
  267. uint32_t start = 0;
  268. uint32_t size = ha->optrom_size;
  269. int val, valid;
  270. ssize_t rval = count;
  271. if (off)
  272. return -EINVAL;
  273. if (unlikely(pci_channel_offline(ha->pdev)))
  274. return -EAGAIN;
  275. if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
  276. return -EINVAL;
  277. if (start > ha->optrom_size)
  278. return -EINVAL;
  279. if (size > ha->optrom_size - start)
  280. size = ha->optrom_size - start;
  281. mutex_lock(&ha->optrom_mutex);
  282. switch (val) {
  283. case 0:
  284. if (ha->optrom_state != QLA_SREADING &&
  285. ha->optrom_state != QLA_SWRITING) {
  286. rval = -EINVAL;
  287. goto out;
  288. }
  289. ha->optrom_state = QLA_SWAITING;
  290. ql_dbg(ql_dbg_user, vha, 0x7061,
  291. "Freeing flash region allocation -- 0x%x bytes.\n",
  292. ha->optrom_region_size);
  293. vfree(ha->optrom_buffer);
  294. ha->optrom_buffer = NULL;
  295. break;
  296. case 1:
  297. if (ha->optrom_state != QLA_SWAITING) {
  298. rval = -EINVAL;
  299. goto out;
  300. }
  301. ha->optrom_region_start = start;
  302. ha->optrom_region_size = size;
  303. ha->optrom_state = QLA_SREADING;
  304. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  305. if (ha->optrom_buffer == NULL) {
  306. ql_log(ql_log_warn, vha, 0x7062,
  307. "Unable to allocate memory for optrom retrieval "
  308. "(%x).\n", ha->optrom_region_size);
  309. ha->optrom_state = QLA_SWAITING;
  310. rval = -ENOMEM;
  311. goto out;
  312. }
  313. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  314. ql_log(ql_log_warn, vha, 0x7063,
  315. "HBA not online, failing NVRAM update.\n");
  316. rval = -EAGAIN;
  317. goto out;
  318. }
  319. ql_dbg(ql_dbg_user, vha, 0x7064,
  320. "Reading flash region -- 0x%x/0x%x.\n",
  321. ha->optrom_region_start, ha->optrom_region_size);
  322. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  323. ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
  324. ha->optrom_region_start, ha->optrom_region_size);
  325. break;
  326. case 2:
  327. if (ha->optrom_state != QLA_SWAITING) {
  328. rval = -EINVAL;
  329. goto out;
  330. }
  331. /*
  332. * We need to be more restrictive on which FLASH regions are
  333. * allowed to be updated via user-space. Regions accessible
  334. * via this method include:
  335. *
  336. * ISP21xx/ISP22xx/ISP23xx type boards:
  337. *
  338. * 0x000000 -> 0x020000 -- Boot code.
  339. *
  340. * ISP2322/ISP24xx type boards:
  341. *
  342. * 0x000000 -> 0x07ffff -- Boot code.
  343. * 0x080000 -> 0x0fffff -- Firmware.
  344. *
  345. * ISP25xx type boards:
  346. *
  347. * 0x000000 -> 0x07ffff -- Boot code.
  348. * 0x080000 -> 0x0fffff -- Firmware.
  349. * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
  350. */
  351. valid = 0;
  352. if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
  353. valid = 1;
  354. else if (start == (ha->flt_region_boot * 4) ||
  355. start == (ha->flt_region_fw * 4))
  356. valid = 1;
  357. else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)
  358. || IS_CNA_CAPABLE(ha) || IS_QLA2031(ha)
  359. || IS_QLA27XX(ha))
  360. valid = 1;
  361. if (!valid) {
  362. ql_log(ql_log_warn, vha, 0x7065,
  363. "Invalid start region 0x%x/0x%x.\n", start, size);
  364. rval = -EINVAL;
  365. goto out;
  366. }
  367. ha->optrom_region_start = start;
  368. ha->optrom_region_size = size;
  369. ha->optrom_state = QLA_SWRITING;
  370. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  371. if (ha->optrom_buffer == NULL) {
  372. ql_log(ql_log_warn, vha, 0x7066,
  373. "Unable to allocate memory for optrom update "
  374. "(%x)\n", ha->optrom_region_size);
  375. ha->optrom_state = QLA_SWAITING;
  376. rval = -ENOMEM;
  377. goto out;
  378. }
  379. ql_dbg(ql_dbg_user, vha, 0x7067,
  380. "Staging flash region write -- 0x%x/0x%x.\n",
  381. ha->optrom_region_start, ha->optrom_region_size);
  382. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  383. break;
  384. case 3:
  385. if (ha->optrom_state != QLA_SWRITING) {
  386. rval = -EINVAL;
  387. goto out;
  388. }
  389. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  390. ql_log(ql_log_warn, vha, 0x7068,
  391. "HBA not online, failing flash update.\n");
  392. rval = -EAGAIN;
  393. goto out;
  394. }
  395. ql_dbg(ql_dbg_user, vha, 0x7069,
  396. "Writing flash region -- 0x%x/0x%x.\n",
  397. ha->optrom_region_start, ha->optrom_region_size);
  398. ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
  399. ha->optrom_region_start, ha->optrom_region_size);
  400. break;
  401. default:
  402. rval = -EINVAL;
  403. }
  404. out:
  405. mutex_unlock(&ha->optrom_mutex);
  406. return rval;
  407. }
  408. static struct bin_attribute sysfs_optrom_ctl_attr = {
  409. .attr = {
  410. .name = "optrom_ctl",
  411. .mode = S_IWUSR,
  412. },
  413. .size = 0,
  414. .write = qla2x00_sysfs_write_optrom_ctl,
  415. };
  416. static ssize_t
  417. qla2x00_sysfs_read_vpd(struct file *filp, struct kobject *kobj,
  418. struct bin_attribute *bin_attr,
  419. char *buf, loff_t off, size_t count)
  420. {
  421. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  422. struct device, kobj)));
  423. struct qla_hw_data *ha = vha->hw;
  424. uint32_t faddr;
  425. if (unlikely(pci_channel_offline(ha->pdev)))
  426. return -EAGAIN;
  427. if (!capable(CAP_SYS_ADMIN))
  428. return -EINVAL;
  429. if (IS_NOCACHE_VPD_TYPE(ha)) {
  430. faddr = ha->flt_region_vpd << 2;
  431. if (IS_QLA27XX(ha) &&
  432. qla27xx_find_valid_image(vha) == QLA27XX_SECONDARY_IMAGE)
  433. faddr = ha->flt_region_vpd_sec << 2;
  434. ha->isp_ops->read_optrom(vha, ha->vpd, faddr,
  435. ha->vpd_size);
  436. }
  437. return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
  438. }
  439. static ssize_t
  440. qla2x00_sysfs_write_vpd(struct file *filp, struct kobject *kobj,
  441. struct bin_attribute *bin_attr,
  442. char *buf, loff_t off, size_t count)
  443. {
  444. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  445. struct device, kobj)));
  446. struct qla_hw_data *ha = vha->hw;
  447. uint8_t *tmp_data;
  448. if (unlikely(pci_channel_offline(ha->pdev)))
  449. return 0;
  450. if (qla2x00_chip_is_down(vha))
  451. return 0;
  452. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
  453. !ha->isp_ops->write_nvram)
  454. return 0;
  455. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  456. ql_log(ql_log_warn, vha, 0x706a,
  457. "HBA not online, failing VPD update.\n");
  458. return -EAGAIN;
  459. }
  460. /* Write NVRAM. */
  461. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
  462. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
  463. /* Update flash version information for 4Gb & above. */
  464. if (!IS_FWI2_CAPABLE(ha))
  465. return -EINVAL;
  466. tmp_data = vmalloc(256);
  467. if (!tmp_data) {
  468. ql_log(ql_log_warn, vha, 0x706b,
  469. "Unable to allocate memory for VPD information update.\n");
  470. return -ENOMEM;
  471. }
  472. ha->isp_ops->get_flash_version(vha, tmp_data);
  473. vfree(tmp_data);
  474. return count;
  475. }
  476. static struct bin_attribute sysfs_vpd_attr = {
  477. .attr = {
  478. .name = "vpd",
  479. .mode = S_IRUSR | S_IWUSR,
  480. },
  481. .size = 0,
  482. .read = qla2x00_sysfs_read_vpd,
  483. .write = qla2x00_sysfs_write_vpd,
  484. };
  485. static ssize_t
  486. qla2x00_sysfs_read_sfp(struct file *filp, struct kobject *kobj,
  487. struct bin_attribute *bin_attr,
  488. char *buf, loff_t off, size_t count)
  489. {
  490. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  491. struct device, kobj)));
  492. int rval;
  493. if (!capable(CAP_SYS_ADMIN) || off != 0 || count < SFP_DEV_SIZE)
  494. return 0;
  495. if (qla2x00_chip_is_down(vha))
  496. return 0;
  497. rval = qla2x00_read_sfp_dev(vha, buf, count);
  498. if (rval)
  499. return -EIO;
  500. return count;
  501. }
  502. static struct bin_attribute sysfs_sfp_attr = {
  503. .attr = {
  504. .name = "sfp",
  505. .mode = S_IRUSR | S_IWUSR,
  506. },
  507. .size = SFP_DEV_SIZE,
  508. .read = qla2x00_sysfs_read_sfp,
  509. };
  510. static ssize_t
  511. qla2x00_sysfs_write_reset(struct file *filp, struct kobject *kobj,
  512. struct bin_attribute *bin_attr,
  513. char *buf, loff_t off, size_t count)
  514. {
  515. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  516. struct device, kobj)));
  517. struct qla_hw_data *ha = vha->hw;
  518. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  519. int type;
  520. uint32_t idc_control;
  521. uint8_t *tmp_data = NULL;
  522. if (off != 0)
  523. return -EINVAL;
  524. type = simple_strtol(buf, NULL, 10);
  525. switch (type) {
  526. case 0x2025c:
  527. ql_log(ql_log_info, vha, 0x706e,
  528. "Issuing ISP reset.\n");
  529. scsi_block_requests(vha->host);
  530. if (IS_QLA82XX(ha)) {
  531. ha->flags.isp82xx_no_md_cap = 1;
  532. qla82xx_idc_lock(ha);
  533. qla82xx_set_reset_owner(vha);
  534. qla82xx_idc_unlock(ha);
  535. } else if (IS_QLA8044(ha)) {
  536. qla8044_idc_lock(ha);
  537. idc_control = qla8044_rd_reg(ha,
  538. QLA8044_IDC_DRV_CTRL);
  539. qla8044_wr_reg(ha, QLA8044_IDC_DRV_CTRL,
  540. (idc_control | GRACEFUL_RESET_BIT1));
  541. qla82xx_set_reset_owner(vha);
  542. qla8044_idc_unlock(ha);
  543. } else {
  544. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  545. qla2xxx_wake_dpc(vha);
  546. }
  547. qla2x00_wait_for_chip_reset(vha);
  548. scsi_unblock_requests(vha->host);
  549. break;
  550. case 0x2025d:
  551. if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha))
  552. return -EPERM;
  553. ql_log(ql_log_info, vha, 0x706f,
  554. "Issuing MPI reset.\n");
  555. if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
  556. uint32_t idc_control;
  557. qla83xx_idc_lock(vha, 0);
  558. __qla83xx_get_idc_control(vha, &idc_control);
  559. idc_control |= QLA83XX_IDC_GRACEFUL_RESET;
  560. __qla83xx_set_idc_control(vha, idc_control);
  561. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
  562. QLA8XXX_DEV_NEED_RESET);
  563. qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
  564. qla83xx_idc_unlock(vha, 0);
  565. break;
  566. } else {
  567. /* Make sure FC side is not in reset */
  568. qla2x00_wait_for_hba_online(vha);
  569. /* Issue MPI reset */
  570. scsi_block_requests(vha->host);
  571. if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
  572. ql_log(ql_log_warn, vha, 0x7070,
  573. "MPI reset failed.\n");
  574. scsi_unblock_requests(vha->host);
  575. break;
  576. }
  577. case 0x2025e:
  578. if (!IS_P3P_TYPE(ha) || vha != base_vha) {
  579. ql_log(ql_log_info, vha, 0x7071,
  580. "FCoE ctx reset not supported.\n");
  581. return -EPERM;
  582. }
  583. ql_log(ql_log_info, vha, 0x7072,
  584. "Issuing FCoE ctx reset.\n");
  585. set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
  586. qla2xxx_wake_dpc(vha);
  587. qla2x00_wait_for_fcoe_ctx_reset(vha);
  588. break;
  589. case 0x2025f:
  590. if (!IS_QLA8031(ha))
  591. return -EPERM;
  592. ql_log(ql_log_info, vha, 0x70bc,
  593. "Disabling Reset by IDC control\n");
  594. qla83xx_idc_lock(vha, 0);
  595. __qla83xx_get_idc_control(vha, &idc_control);
  596. idc_control |= QLA83XX_IDC_RESET_DISABLED;
  597. __qla83xx_set_idc_control(vha, idc_control);
  598. qla83xx_idc_unlock(vha, 0);
  599. break;
  600. case 0x20260:
  601. if (!IS_QLA8031(ha))
  602. return -EPERM;
  603. ql_log(ql_log_info, vha, 0x70bd,
  604. "Enabling Reset by IDC control\n");
  605. qla83xx_idc_lock(vha, 0);
  606. __qla83xx_get_idc_control(vha, &idc_control);
  607. idc_control &= ~QLA83XX_IDC_RESET_DISABLED;
  608. __qla83xx_set_idc_control(vha, idc_control);
  609. qla83xx_idc_unlock(vha, 0);
  610. break;
  611. case 0x20261:
  612. ql_dbg(ql_dbg_user, vha, 0x70e0,
  613. "Updating cache versions without reset ");
  614. tmp_data = vmalloc(256);
  615. if (!tmp_data) {
  616. ql_log(ql_log_warn, vha, 0x70e1,
  617. "Unable to allocate memory for VPD information update.\n");
  618. return -ENOMEM;
  619. }
  620. ha->isp_ops->get_flash_version(vha, tmp_data);
  621. vfree(tmp_data);
  622. break;
  623. }
  624. return count;
  625. }
  626. static struct bin_attribute sysfs_reset_attr = {
  627. .attr = {
  628. .name = "reset",
  629. .mode = S_IWUSR,
  630. },
  631. .size = 0,
  632. .write = qla2x00_sysfs_write_reset,
  633. };
  634. static ssize_t
  635. qla2x00_issue_logo(struct file *filp, struct kobject *kobj,
  636. struct bin_attribute *bin_attr,
  637. char *buf, loff_t off, size_t count)
  638. {
  639. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  640. struct device, kobj)));
  641. int type;
  642. port_id_t did;
  643. if (!capable(CAP_SYS_ADMIN))
  644. return 0;
  645. if (unlikely(pci_channel_offline(vha->hw->pdev)))
  646. return 0;
  647. if (qla2x00_chip_is_down(vha))
  648. return 0;
  649. type = simple_strtol(buf, NULL, 10);
  650. did.b.domain = (type & 0x00ff0000) >> 16;
  651. did.b.area = (type & 0x0000ff00) >> 8;
  652. did.b.al_pa = (type & 0x000000ff);
  653. ql_log(ql_log_info, vha, 0xd04d, "portid=%02x%02x%02x done\n",
  654. did.b.domain, did.b.area, did.b.al_pa);
  655. ql_log(ql_log_info, vha, 0x70e4, "%s: %d\n", __func__, type);
  656. qla24xx_els_dcmd_iocb(vha, ELS_DCMD_LOGO, did);
  657. return count;
  658. }
  659. static struct bin_attribute sysfs_issue_logo_attr = {
  660. .attr = {
  661. .name = "issue_logo",
  662. .mode = S_IWUSR,
  663. },
  664. .size = 0,
  665. .write = qla2x00_issue_logo,
  666. };
  667. static ssize_t
  668. qla2x00_sysfs_read_xgmac_stats(struct file *filp, struct kobject *kobj,
  669. struct bin_attribute *bin_attr,
  670. char *buf, loff_t off, size_t count)
  671. {
  672. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  673. struct device, kobj)));
  674. struct qla_hw_data *ha = vha->hw;
  675. int rval;
  676. uint16_t actual_size;
  677. if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
  678. return 0;
  679. if (unlikely(pci_channel_offline(ha->pdev)))
  680. return 0;
  681. if (qla2x00_chip_is_down(vha))
  682. return 0;
  683. if (ha->xgmac_data)
  684. goto do_read;
  685. ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
  686. &ha->xgmac_data_dma, GFP_KERNEL);
  687. if (!ha->xgmac_data) {
  688. ql_log(ql_log_warn, vha, 0x7076,
  689. "Unable to allocate memory for XGMAC read-data.\n");
  690. return 0;
  691. }
  692. do_read:
  693. actual_size = 0;
  694. memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
  695. rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
  696. XGMAC_DATA_SIZE, &actual_size);
  697. if (rval != QLA_SUCCESS) {
  698. ql_log(ql_log_warn, vha, 0x7077,
  699. "Unable to read XGMAC data (%x).\n", rval);
  700. count = 0;
  701. }
  702. count = actual_size > count ? count: actual_size;
  703. memcpy(buf, ha->xgmac_data, count);
  704. return count;
  705. }
  706. static struct bin_attribute sysfs_xgmac_stats_attr = {
  707. .attr = {
  708. .name = "xgmac_stats",
  709. .mode = S_IRUSR,
  710. },
  711. .size = 0,
  712. .read = qla2x00_sysfs_read_xgmac_stats,
  713. };
  714. static ssize_t
  715. qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj,
  716. struct bin_attribute *bin_attr,
  717. char *buf, loff_t off, size_t count)
  718. {
  719. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  720. struct device, kobj)));
  721. struct qla_hw_data *ha = vha->hw;
  722. int rval;
  723. if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
  724. return 0;
  725. if (ha->dcbx_tlv)
  726. goto do_read;
  727. if (qla2x00_chip_is_down(vha))
  728. return 0;
  729. ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
  730. &ha->dcbx_tlv_dma, GFP_KERNEL);
  731. if (!ha->dcbx_tlv) {
  732. ql_log(ql_log_warn, vha, 0x7078,
  733. "Unable to allocate memory for DCBX TLV read-data.\n");
  734. return -ENOMEM;
  735. }
  736. do_read:
  737. memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
  738. rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
  739. DCBX_TLV_DATA_SIZE);
  740. if (rval != QLA_SUCCESS) {
  741. ql_log(ql_log_warn, vha, 0x7079,
  742. "Unable to read DCBX TLV (%x).\n", rval);
  743. return -EIO;
  744. }
  745. memcpy(buf, ha->dcbx_tlv, count);
  746. return count;
  747. }
  748. static struct bin_attribute sysfs_dcbx_tlv_attr = {
  749. .attr = {
  750. .name = "dcbx_tlv",
  751. .mode = S_IRUSR,
  752. },
  753. .size = 0,
  754. .read = qla2x00_sysfs_read_dcbx_tlv,
  755. };
  756. static struct sysfs_entry {
  757. char *name;
  758. struct bin_attribute *attr;
  759. int is4GBp_only;
  760. } bin_file_entries[] = {
  761. { "fw_dump", &sysfs_fw_dump_attr, },
  762. { "nvram", &sysfs_nvram_attr, },
  763. { "optrom", &sysfs_optrom_attr, },
  764. { "optrom_ctl", &sysfs_optrom_ctl_attr, },
  765. { "vpd", &sysfs_vpd_attr, 1 },
  766. { "sfp", &sysfs_sfp_attr, 1 },
  767. { "reset", &sysfs_reset_attr, },
  768. { "issue_logo", &sysfs_issue_logo_attr, },
  769. { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
  770. { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
  771. { NULL },
  772. };
  773. void
  774. qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
  775. {
  776. struct Scsi_Host *host = vha->host;
  777. struct sysfs_entry *iter;
  778. int ret;
  779. for (iter = bin_file_entries; iter->name; iter++) {
  780. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
  781. continue;
  782. if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
  783. continue;
  784. if (iter->is4GBp_only == 3 && !(IS_CNA_CAPABLE(vha->hw)))
  785. continue;
  786. ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
  787. iter->attr);
  788. if (ret)
  789. ql_log(ql_log_warn, vha, 0x00f3,
  790. "Unable to create sysfs %s binary attribute (%d).\n",
  791. iter->name, ret);
  792. else
  793. ql_dbg(ql_dbg_init, vha, 0x00f4,
  794. "Successfully created sysfs %s binary attribute.\n",
  795. iter->name);
  796. }
  797. }
  798. void
  799. qla2x00_free_sysfs_attr(scsi_qla_host_t *vha, bool stop_beacon)
  800. {
  801. struct Scsi_Host *host = vha->host;
  802. struct sysfs_entry *iter;
  803. struct qla_hw_data *ha = vha->hw;
  804. for (iter = bin_file_entries; iter->name; iter++) {
  805. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
  806. continue;
  807. if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
  808. continue;
  809. if (iter->is4GBp_only == 3 && !(IS_CNA_CAPABLE(vha->hw)))
  810. continue;
  811. if (iter->is4GBp_only == 0x27 && !IS_QLA27XX(vha->hw))
  812. continue;
  813. sysfs_remove_bin_file(&host->shost_gendev.kobj,
  814. iter->attr);
  815. }
  816. if (stop_beacon && ha->beacon_blink_led == 1)
  817. ha->isp_ops->beacon_off(vha);
  818. }
  819. /* Scsi_Host attributes. */
  820. static ssize_t
  821. qla2x00_drvr_version_show(struct device *dev,
  822. struct device_attribute *attr, char *buf)
  823. {
  824. return scnprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
  825. }
  826. static ssize_t
  827. qla2x00_fw_version_show(struct device *dev,
  828. struct device_attribute *attr, char *buf)
  829. {
  830. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  831. struct qla_hw_data *ha = vha->hw;
  832. char fw_str[128];
  833. return scnprintf(buf, PAGE_SIZE, "%s\n",
  834. ha->isp_ops->fw_version_str(vha, fw_str, sizeof(fw_str)));
  835. }
  836. static ssize_t
  837. qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
  838. char *buf)
  839. {
  840. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  841. struct qla_hw_data *ha = vha->hw;
  842. uint32_t sn;
  843. if (IS_QLAFX00(vha->hw)) {
  844. return scnprintf(buf, PAGE_SIZE, "%s\n",
  845. vha->hw->mr.serial_num);
  846. } else if (IS_FWI2_CAPABLE(ha)) {
  847. qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE - 1);
  848. return strlen(strcat(buf, "\n"));
  849. }
  850. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  851. return scnprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
  852. sn % 100000);
  853. }
  854. static ssize_t
  855. qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
  856. char *buf)
  857. {
  858. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  859. return scnprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
  860. }
  861. static ssize_t
  862. qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
  863. char *buf)
  864. {
  865. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  866. struct qla_hw_data *ha = vha->hw;
  867. if (IS_QLAFX00(vha->hw))
  868. return scnprintf(buf, PAGE_SIZE, "%s\n",
  869. vha->hw->mr.hw_version);
  870. return scnprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
  871. ha->product_id[0], ha->product_id[1], ha->product_id[2],
  872. ha->product_id[3]);
  873. }
  874. static ssize_t
  875. qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
  876. char *buf)
  877. {
  878. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  879. return scnprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
  880. }
  881. static ssize_t
  882. qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
  883. char *buf)
  884. {
  885. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  886. return scnprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_desc);
  887. }
  888. static ssize_t
  889. qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
  890. char *buf)
  891. {
  892. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  893. char pci_info[30];
  894. return scnprintf(buf, PAGE_SIZE, "%s\n",
  895. vha->hw->isp_ops->pci_info_str(vha, pci_info));
  896. }
  897. static ssize_t
  898. qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
  899. char *buf)
  900. {
  901. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  902. struct qla_hw_data *ha = vha->hw;
  903. int len = 0;
  904. if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
  905. atomic_read(&vha->loop_state) == LOOP_DEAD ||
  906. vha->device_flags & DFLG_NO_CABLE)
  907. len = scnprintf(buf, PAGE_SIZE, "Link Down\n");
  908. else if (atomic_read(&vha->loop_state) != LOOP_READY ||
  909. qla2x00_chip_is_down(vha))
  910. len = scnprintf(buf, PAGE_SIZE, "Unknown Link State\n");
  911. else {
  912. len = scnprintf(buf, PAGE_SIZE, "Link Up - ");
  913. switch (ha->current_topology) {
  914. case ISP_CFG_NL:
  915. len += scnprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  916. break;
  917. case ISP_CFG_FL:
  918. len += scnprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
  919. break;
  920. case ISP_CFG_N:
  921. len += scnprintf(buf + len, PAGE_SIZE-len,
  922. "N_Port to N_Port\n");
  923. break;
  924. case ISP_CFG_F:
  925. len += scnprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
  926. break;
  927. default:
  928. len += scnprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  929. break;
  930. }
  931. }
  932. return len;
  933. }
  934. static ssize_t
  935. qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
  936. char *buf)
  937. {
  938. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  939. int len = 0;
  940. switch (vha->hw->zio_mode) {
  941. case QLA_ZIO_MODE_6:
  942. len += scnprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
  943. break;
  944. case QLA_ZIO_DISABLED:
  945. len += scnprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  946. break;
  947. }
  948. return len;
  949. }
  950. static ssize_t
  951. qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
  952. const char *buf, size_t count)
  953. {
  954. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  955. struct qla_hw_data *ha = vha->hw;
  956. int val = 0;
  957. uint16_t zio_mode;
  958. if (!IS_ZIO_SUPPORTED(ha))
  959. return -ENOTSUPP;
  960. if (sscanf(buf, "%d", &val) != 1)
  961. return -EINVAL;
  962. if (val)
  963. zio_mode = QLA_ZIO_MODE_6;
  964. else
  965. zio_mode = QLA_ZIO_DISABLED;
  966. /* Update per-hba values and queue a reset. */
  967. if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
  968. ha->zio_mode = zio_mode;
  969. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  970. }
  971. return strlen(buf);
  972. }
  973. static ssize_t
  974. qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
  975. char *buf)
  976. {
  977. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  978. return scnprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
  979. }
  980. static ssize_t
  981. qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
  982. const char *buf, size_t count)
  983. {
  984. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  985. int val = 0;
  986. uint16_t zio_timer;
  987. if (sscanf(buf, "%d", &val) != 1)
  988. return -EINVAL;
  989. if (val > 25500 || val < 100)
  990. return -ERANGE;
  991. zio_timer = (uint16_t)(val / 100);
  992. vha->hw->zio_timer = zio_timer;
  993. return strlen(buf);
  994. }
  995. static ssize_t
  996. qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
  997. char *buf)
  998. {
  999. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1000. int len = 0;
  1001. if (vha->hw->beacon_blink_led)
  1002. len += scnprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
  1003. else
  1004. len += scnprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  1005. return len;
  1006. }
  1007. static ssize_t
  1008. qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
  1009. const char *buf, size_t count)
  1010. {
  1011. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1012. struct qla_hw_data *ha = vha->hw;
  1013. int val = 0;
  1014. int rval;
  1015. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  1016. return -EPERM;
  1017. if (qla2x00_chip_is_down(vha)) {
  1018. ql_log(ql_log_warn, vha, 0x707a,
  1019. "Abort ISP active -- ignoring beacon request.\n");
  1020. return -EBUSY;
  1021. }
  1022. if (sscanf(buf, "%d", &val) != 1)
  1023. return -EINVAL;
  1024. if (val)
  1025. rval = ha->isp_ops->beacon_on(vha);
  1026. else
  1027. rval = ha->isp_ops->beacon_off(vha);
  1028. if (rval != QLA_SUCCESS)
  1029. count = 0;
  1030. return count;
  1031. }
  1032. static ssize_t
  1033. qla2x00_optrom_bios_version_show(struct device *dev,
  1034. struct device_attribute *attr, char *buf)
  1035. {
  1036. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1037. struct qla_hw_data *ha = vha->hw;
  1038. return scnprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
  1039. ha->bios_revision[0]);
  1040. }
  1041. static ssize_t
  1042. qla2x00_optrom_efi_version_show(struct device *dev,
  1043. struct device_attribute *attr, char *buf)
  1044. {
  1045. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1046. struct qla_hw_data *ha = vha->hw;
  1047. return scnprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
  1048. ha->efi_revision[0]);
  1049. }
  1050. static ssize_t
  1051. qla2x00_optrom_fcode_version_show(struct device *dev,
  1052. struct device_attribute *attr, char *buf)
  1053. {
  1054. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1055. struct qla_hw_data *ha = vha->hw;
  1056. return scnprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
  1057. ha->fcode_revision[0]);
  1058. }
  1059. static ssize_t
  1060. qla2x00_optrom_fw_version_show(struct device *dev,
  1061. struct device_attribute *attr, char *buf)
  1062. {
  1063. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1064. struct qla_hw_data *ha = vha->hw;
  1065. return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
  1066. ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
  1067. ha->fw_revision[3]);
  1068. }
  1069. static ssize_t
  1070. qla2x00_optrom_gold_fw_version_show(struct device *dev,
  1071. struct device_attribute *attr, char *buf)
  1072. {
  1073. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1074. struct qla_hw_data *ha = vha->hw;
  1075. if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha) && !IS_QLA27XX(ha))
  1076. return scnprintf(buf, PAGE_SIZE, "\n");
  1077. return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%d)\n",
  1078. ha->gold_fw_version[0], ha->gold_fw_version[1],
  1079. ha->gold_fw_version[2], ha->gold_fw_version[3]);
  1080. }
  1081. static ssize_t
  1082. qla2x00_total_isp_aborts_show(struct device *dev,
  1083. struct device_attribute *attr, char *buf)
  1084. {
  1085. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1086. return scnprintf(buf, PAGE_SIZE, "%d\n",
  1087. vha->qla_stats.total_isp_aborts);
  1088. }
  1089. static ssize_t
  1090. qla24xx_84xx_fw_version_show(struct device *dev,
  1091. struct device_attribute *attr, char *buf)
  1092. {
  1093. int rval = QLA_SUCCESS;
  1094. uint16_t status[2] = {0, 0};
  1095. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1096. struct qla_hw_data *ha = vha->hw;
  1097. if (!IS_QLA84XX(ha))
  1098. return scnprintf(buf, PAGE_SIZE, "\n");
  1099. if (ha->cs84xx->op_fw_version == 0)
  1100. rval = qla84xx_verify_chip(vha, status);
  1101. if ((rval == QLA_SUCCESS) && (status[0] == 0))
  1102. return scnprintf(buf, PAGE_SIZE, "%u\n",
  1103. (uint32_t)ha->cs84xx->op_fw_version);
  1104. return scnprintf(buf, PAGE_SIZE, "\n");
  1105. }
  1106. static ssize_t
  1107. qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
  1108. char *buf)
  1109. {
  1110. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1111. struct qla_hw_data *ha = vha->hw;
  1112. if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha) &&
  1113. !IS_QLA27XX(ha))
  1114. return scnprintf(buf, PAGE_SIZE, "\n");
  1115. return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
  1116. ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
  1117. ha->mpi_capabilities);
  1118. }
  1119. static ssize_t
  1120. qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
  1121. char *buf)
  1122. {
  1123. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1124. struct qla_hw_data *ha = vha->hw;
  1125. if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
  1126. return scnprintf(buf, PAGE_SIZE, "\n");
  1127. return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
  1128. ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
  1129. }
  1130. static ssize_t
  1131. qla2x00_flash_block_size_show(struct device *dev,
  1132. struct device_attribute *attr, char *buf)
  1133. {
  1134. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1135. struct qla_hw_data *ha = vha->hw;
  1136. return scnprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
  1137. }
  1138. static ssize_t
  1139. qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
  1140. char *buf)
  1141. {
  1142. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1143. if (!IS_CNA_CAPABLE(vha->hw))
  1144. return scnprintf(buf, PAGE_SIZE, "\n");
  1145. return scnprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
  1146. }
  1147. static ssize_t
  1148. qla2x00_vn_port_mac_address_show(struct device *dev,
  1149. struct device_attribute *attr, char *buf)
  1150. {
  1151. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1152. if (!IS_CNA_CAPABLE(vha->hw))
  1153. return scnprintf(buf, PAGE_SIZE, "\n");
  1154. return scnprintf(buf, PAGE_SIZE, "%pMR\n", vha->fcoe_vn_port_mac);
  1155. }
  1156. static ssize_t
  1157. qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
  1158. char *buf)
  1159. {
  1160. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1161. return scnprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
  1162. }
  1163. static ssize_t
  1164. qla2x00_thermal_temp_show(struct device *dev,
  1165. struct device_attribute *attr, char *buf)
  1166. {
  1167. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1168. uint16_t temp = 0;
  1169. if (qla2x00_chip_is_down(vha)) {
  1170. ql_log(ql_log_warn, vha, 0x70dc, "ISP reset active.\n");
  1171. goto done;
  1172. }
  1173. if (vha->hw->flags.eeh_busy) {
  1174. ql_log(ql_log_warn, vha, 0x70dd, "PCI EEH busy.\n");
  1175. goto done;
  1176. }
  1177. if (qla2x00_get_thermal_temp(vha, &temp) == QLA_SUCCESS)
  1178. return scnprintf(buf, PAGE_SIZE, "%d\n", temp);
  1179. done:
  1180. return scnprintf(buf, PAGE_SIZE, "\n");
  1181. }
  1182. static ssize_t
  1183. qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
  1184. char *buf)
  1185. {
  1186. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1187. int rval = QLA_FUNCTION_FAILED;
  1188. uint16_t state[6];
  1189. uint32_t pstate;
  1190. if (IS_QLAFX00(vha->hw)) {
  1191. pstate = qlafx00_fw_state_show(dev, attr, buf);
  1192. return scnprintf(buf, PAGE_SIZE, "0x%x\n", pstate);
  1193. }
  1194. if (qla2x00_chip_is_down(vha))
  1195. ql_log(ql_log_warn, vha, 0x707c,
  1196. "ISP reset active.\n");
  1197. else if (!vha->hw->flags.eeh_busy)
  1198. rval = qla2x00_get_firmware_state(vha, state);
  1199. if (rval != QLA_SUCCESS)
  1200. memset(state, -1, sizeof(state));
  1201. return scnprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
  1202. state[0], state[1], state[2], state[3], state[4], state[5]);
  1203. }
  1204. static ssize_t
  1205. qla2x00_diag_requests_show(struct device *dev,
  1206. struct device_attribute *attr, char *buf)
  1207. {
  1208. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1209. if (!IS_BIDI_CAPABLE(vha->hw))
  1210. return scnprintf(buf, PAGE_SIZE, "\n");
  1211. return scnprintf(buf, PAGE_SIZE, "%llu\n", vha->bidi_stats.io_count);
  1212. }
  1213. static ssize_t
  1214. qla2x00_diag_megabytes_show(struct device *dev,
  1215. struct device_attribute *attr, char *buf)
  1216. {
  1217. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1218. if (!IS_BIDI_CAPABLE(vha->hw))
  1219. return scnprintf(buf, PAGE_SIZE, "\n");
  1220. return scnprintf(buf, PAGE_SIZE, "%llu\n",
  1221. vha->bidi_stats.transfer_bytes >> 20);
  1222. }
  1223. static ssize_t
  1224. qla2x00_fw_dump_size_show(struct device *dev, struct device_attribute *attr,
  1225. char *buf)
  1226. {
  1227. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1228. struct qla_hw_data *ha = vha->hw;
  1229. uint32_t size;
  1230. if (!ha->fw_dumped)
  1231. size = 0;
  1232. else if (IS_P3P_TYPE(ha))
  1233. size = ha->md_template_size + ha->md_dump_size;
  1234. else
  1235. size = ha->fw_dump_len;
  1236. return scnprintf(buf, PAGE_SIZE, "%d\n", size);
  1237. }
  1238. static ssize_t
  1239. qla2x00_allow_cna_fw_dump_show(struct device *dev,
  1240. struct device_attribute *attr, char *buf)
  1241. {
  1242. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1243. if (!IS_P3P_TYPE(vha->hw))
  1244. return scnprintf(buf, PAGE_SIZE, "\n");
  1245. else
  1246. return scnprintf(buf, PAGE_SIZE, "%s\n",
  1247. vha->hw->allow_cna_fw_dump ? "true" : "false");
  1248. }
  1249. static ssize_t
  1250. qla2x00_allow_cna_fw_dump_store(struct device *dev,
  1251. struct device_attribute *attr, const char *buf, size_t count)
  1252. {
  1253. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1254. int val = 0;
  1255. if (!IS_P3P_TYPE(vha->hw))
  1256. return -EINVAL;
  1257. if (sscanf(buf, "%d", &val) != 1)
  1258. return -EINVAL;
  1259. vha->hw->allow_cna_fw_dump = val != 0;
  1260. return strlen(buf);
  1261. }
  1262. static ssize_t
  1263. qla2x00_pep_version_show(struct device *dev, struct device_attribute *attr,
  1264. char *buf)
  1265. {
  1266. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1267. struct qla_hw_data *ha = vha->hw;
  1268. if (!IS_QLA27XX(ha))
  1269. return scnprintf(buf, PAGE_SIZE, "\n");
  1270. return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
  1271. ha->pep_version[0], ha->pep_version[1], ha->pep_version[2]);
  1272. }
  1273. static ssize_t
  1274. qla2x00_min_link_speed_show(struct device *dev, struct device_attribute *attr,
  1275. char *buf)
  1276. {
  1277. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1278. struct qla_hw_data *ha = vha->hw;
  1279. if (!IS_QLA27XX(ha))
  1280. return scnprintf(buf, PAGE_SIZE, "\n");
  1281. return scnprintf(buf, PAGE_SIZE, "%s\n",
  1282. ha->min_link_speed == 5 ? "32Gps" :
  1283. ha->min_link_speed == 4 ? "16Gps" :
  1284. ha->min_link_speed == 3 ? "8Gps" :
  1285. ha->min_link_speed == 2 ? "4Gps" :
  1286. ha->min_link_speed != 0 ? "unknown" : "");
  1287. }
  1288. static ssize_t
  1289. qla2x00_max_speed_sup_show(struct device *dev, struct device_attribute *attr,
  1290. char *buf)
  1291. {
  1292. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1293. struct qla_hw_data *ha = vha->hw;
  1294. if (!IS_QLA27XX(ha))
  1295. return scnprintf(buf, PAGE_SIZE, "\n");
  1296. return scnprintf(buf, PAGE_SIZE, "%s\n",
  1297. ha->max_speed_sup ? "32Gps" : "16Gps");
  1298. }
  1299. static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
  1300. static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
  1301. static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
  1302. static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
  1303. static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
  1304. static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
  1305. static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
  1306. static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
  1307. static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
  1308. static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
  1309. static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
  1310. qla2x00_zio_timer_store);
  1311. static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
  1312. qla2x00_beacon_store);
  1313. static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
  1314. qla2x00_optrom_bios_version_show, NULL);
  1315. static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
  1316. qla2x00_optrom_efi_version_show, NULL);
  1317. static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
  1318. qla2x00_optrom_fcode_version_show, NULL);
  1319. static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
  1320. NULL);
  1321. static DEVICE_ATTR(optrom_gold_fw_version, S_IRUGO,
  1322. qla2x00_optrom_gold_fw_version_show, NULL);
  1323. static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
  1324. NULL);
  1325. static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
  1326. NULL);
  1327. static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
  1328. static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
  1329. static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
  1330. NULL);
  1331. static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
  1332. static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
  1333. qla2x00_vn_port_mac_address_show, NULL);
  1334. static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
  1335. static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
  1336. static DEVICE_ATTR(thermal_temp, S_IRUGO, qla2x00_thermal_temp_show, NULL);
  1337. static DEVICE_ATTR(diag_requests, S_IRUGO, qla2x00_diag_requests_show, NULL);
  1338. static DEVICE_ATTR(diag_megabytes, S_IRUGO, qla2x00_diag_megabytes_show, NULL);
  1339. static DEVICE_ATTR(fw_dump_size, S_IRUGO, qla2x00_fw_dump_size_show, NULL);
  1340. static DEVICE_ATTR(allow_cna_fw_dump, S_IRUGO | S_IWUSR,
  1341. qla2x00_allow_cna_fw_dump_show,
  1342. qla2x00_allow_cna_fw_dump_store);
  1343. static DEVICE_ATTR(pep_version, S_IRUGO, qla2x00_pep_version_show, NULL);
  1344. static DEVICE_ATTR(min_link_speed, S_IRUGO, qla2x00_min_link_speed_show, NULL);
  1345. static DEVICE_ATTR(max_speed_sup, S_IRUGO, qla2x00_max_speed_sup_show, NULL);
  1346. struct device_attribute *qla2x00_host_attrs[] = {
  1347. &dev_attr_driver_version,
  1348. &dev_attr_fw_version,
  1349. &dev_attr_serial_num,
  1350. &dev_attr_isp_name,
  1351. &dev_attr_isp_id,
  1352. &dev_attr_model_name,
  1353. &dev_attr_model_desc,
  1354. &dev_attr_pci_info,
  1355. &dev_attr_link_state,
  1356. &dev_attr_zio,
  1357. &dev_attr_zio_timer,
  1358. &dev_attr_beacon,
  1359. &dev_attr_optrom_bios_version,
  1360. &dev_attr_optrom_efi_version,
  1361. &dev_attr_optrom_fcode_version,
  1362. &dev_attr_optrom_fw_version,
  1363. &dev_attr_84xx_fw_version,
  1364. &dev_attr_total_isp_aborts,
  1365. &dev_attr_mpi_version,
  1366. &dev_attr_phy_version,
  1367. &dev_attr_flash_block_size,
  1368. &dev_attr_vlan_id,
  1369. &dev_attr_vn_port_mac_address,
  1370. &dev_attr_fabric_param,
  1371. &dev_attr_fw_state,
  1372. &dev_attr_optrom_gold_fw_version,
  1373. &dev_attr_thermal_temp,
  1374. &dev_attr_diag_requests,
  1375. &dev_attr_diag_megabytes,
  1376. &dev_attr_fw_dump_size,
  1377. &dev_attr_allow_cna_fw_dump,
  1378. &dev_attr_pep_version,
  1379. &dev_attr_min_link_speed,
  1380. &dev_attr_max_speed_sup,
  1381. NULL,
  1382. };
  1383. /* Host attributes. */
  1384. static void
  1385. qla2x00_get_host_port_id(struct Scsi_Host *shost)
  1386. {
  1387. scsi_qla_host_t *vha = shost_priv(shost);
  1388. fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
  1389. vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
  1390. }
  1391. static void
  1392. qla2x00_get_host_speed(struct Scsi_Host *shost)
  1393. {
  1394. struct qla_hw_data *ha = ((struct scsi_qla_host *)
  1395. (shost_priv(shost)))->hw;
  1396. u32 speed = FC_PORTSPEED_UNKNOWN;
  1397. if (IS_QLAFX00(ha)) {
  1398. qlafx00_get_host_speed(shost);
  1399. return;
  1400. }
  1401. switch (ha->link_data_rate) {
  1402. case PORT_SPEED_1GB:
  1403. speed = FC_PORTSPEED_1GBIT;
  1404. break;
  1405. case PORT_SPEED_2GB:
  1406. speed = FC_PORTSPEED_2GBIT;
  1407. break;
  1408. case PORT_SPEED_4GB:
  1409. speed = FC_PORTSPEED_4GBIT;
  1410. break;
  1411. case PORT_SPEED_8GB:
  1412. speed = FC_PORTSPEED_8GBIT;
  1413. break;
  1414. case PORT_SPEED_10GB:
  1415. speed = FC_PORTSPEED_10GBIT;
  1416. break;
  1417. case PORT_SPEED_16GB:
  1418. speed = FC_PORTSPEED_16GBIT;
  1419. break;
  1420. case PORT_SPEED_32GB:
  1421. speed = FC_PORTSPEED_32GBIT;
  1422. break;
  1423. }
  1424. fc_host_speed(shost) = speed;
  1425. }
  1426. static void
  1427. qla2x00_get_host_port_type(struct Scsi_Host *shost)
  1428. {
  1429. scsi_qla_host_t *vha = shost_priv(shost);
  1430. uint32_t port_type = FC_PORTTYPE_UNKNOWN;
  1431. if (vha->vp_idx) {
  1432. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  1433. return;
  1434. }
  1435. switch (vha->hw->current_topology) {
  1436. case ISP_CFG_NL:
  1437. port_type = FC_PORTTYPE_LPORT;
  1438. break;
  1439. case ISP_CFG_FL:
  1440. port_type = FC_PORTTYPE_NLPORT;
  1441. break;
  1442. case ISP_CFG_N:
  1443. port_type = FC_PORTTYPE_PTP;
  1444. break;
  1445. case ISP_CFG_F:
  1446. port_type = FC_PORTTYPE_NPORT;
  1447. break;
  1448. }
  1449. fc_host_port_type(shost) = port_type;
  1450. }
  1451. static void
  1452. qla2x00_get_starget_node_name(struct scsi_target *starget)
  1453. {
  1454. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1455. scsi_qla_host_t *vha = shost_priv(host);
  1456. fc_port_t *fcport;
  1457. u64 node_name = 0;
  1458. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1459. if (fcport->rport &&
  1460. starget->id == fcport->rport->scsi_target_id) {
  1461. node_name = wwn_to_u64(fcport->node_name);
  1462. break;
  1463. }
  1464. }
  1465. fc_starget_node_name(starget) = node_name;
  1466. }
  1467. static void
  1468. qla2x00_get_starget_port_name(struct scsi_target *starget)
  1469. {
  1470. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1471. scsi_qla_host_t *vha = shost_priv(host);
  1472. fc_port_t *fcport;
  1473. u64 port_name = 0;
  1474. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1475. if (fcport->rport &&
  1476. starget->id == fcport->rport->scsi_target_id) {
  1477. port_name = wwn_to_u64(fcport->port_name);
  1478. break;
  1479. }
  1480. }
  1481. fc_starget_port_name(starget) = port_name;
  1482. }
  1483. static void
  1484. qla2x00_get_starget_port_id(struct scsi_target *starget)
  1485. {
  1486. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1487. scsi_qla_host_t *vha = shost_priv(host);
  1488. fc_port_t *fcport;
  1489. uint32_t port_id = ~0U;
  1490. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1491. if (fcport->rport &&
  1492. starget->id == fcport->rport->scsi_target_id) {
  1493. port_id = fcport->d_id.b.domain << 16 |
  1494. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  1495. break;
  1496. }
  1497. }
  1498. fc_starget_port_id(starget) = port_id;
  1499. }
  1500. static void
  1501. qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  1502. {
  1503. if (timeout)
  1504. rport->dev_loss_tmo = timeout;
  1505. else
  1506. rport->dev_loss_tmo = 1;
  1507. }
  1508. static void
  1509. qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
  1510. {
  1511. struct Scsi_Host *host = rport_to_shost(rport);
  1512. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1513. unsigned long flags;
  1514. if (!fcport)
  1515. return;
  1516. /* Now that the rport has been deleted, set the fcport state to
  1517. FCS_DEVICE_DEAD */
  1518. qla2x00_set_fcport_state(fcport, FCS_DEVICE_DEAD);
  1519. /*
  1520. * Transport has effectively 'deleted' the rport, clear
  1521. * all local references.
  1522. */
  1523. spin_lock_irqsave(host->host_lock, flags);
  1524. fcport->rport = fcport->drport = NULL;
  1525. *((fc_port_t **)rport->dd_data) = NULL;
  1526. spin_unlock_irqrestore(host->host_lock, flags);
  1527. if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
  1528. return;
  1529. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1530. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1531. return;
  1532. }
  1533. }
  1534. static void
  1535. qla2x00_terminate_rport_io(struct fc_rport *rport)
  1536. {
  1537. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1538. if (!fcport)
  1539. return;
  1540. if (test_bit(UNLOADING, &fcport->vha->dpc_flags))
  1541. return;
  1542. if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
  1543. return;
  1544. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1545. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1546. return;
  1547. }
  1548. /*
  1549. * At this point all fcport's software-states are cleared. Perform any
  1550. * final cleanup of firmware resources (PCBs and XCBs).
  1551. */
  1552. if (fcport->loop_id != FC_NO_LOOP_ID) {
  1553. if (IS_FWI2_CAPABLE(fcport->vha->hw))
  1554. fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
  1555. fcport->loop_id, fcport->d_id.b.domain,
  1556. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  1557. else
  1558. qla2x00_port_logout(fcport->vha, fcport);
  1559. }
  1560. }
  1561. static int
  1562. qla2x00_issue_lip(struct Scsi_Host *shost)
  1563. {
  1564. scsi_qla_host_t *vha = shost_priv(shost);
  1565. if (IS_QLAFX00(vha->hw))
  1566. return 0;
  1567. qla2x00_loop_reset(vha);
  1568. return 0;
  1569. }
  1570. static struct fc_host_statistics *
  1571. qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
  1572. {
  1573. scsi_qla_host_t *vha = shost_priv(shost);
  1574. struct qla_hw_data *ha = vha->hw;
  1575. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  1576. int rval;
  1577. struct link_statistics *stats;
  1578. dma_addr_t stats_dma;
  1579. struct fc_host_statistics *p = &vha->fc_host_stat;
  1580. memset(p, -1, sizeof(*p));
  1581. if (IS_QLAFX00(vha->hw))
  1582. goto done;
  1583. if (test_bit(UNLOADING, &vha->dpc_flags))
  1584. goto done;
  1585. if (unlikely(pci_channel_offline(ha->pdev)))
  1586. goto done;
  1587. if (qla2x00_chip_is_down(vha))
  1588. goto done;
  1589. stats = dma_zalloc_coherent(&ha->pdev->dev, sizeof(*stats),
  1590. &stats_dma, GFP_KERNEL);
  1591. if (!stats) {
  1592. ql_log(ql_log_warn, vha, 0x707d,
  1593. "Failed to allocate memory for stats.\n");
  1594. goto done;
  1595. }
  1596. rval = QLA_FUNCTION_FAILED;
  1597. if (IS_FWI2_CAPABLE(ha)) {
  1598. rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma, 0);
  1599. } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
  1600. !ha->dpc_active) {
  1601. /* Must be in a 'READY' state for statistics retrieval. */
  1602. rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
  1603. stats, stats_dma);
  1604. }
  1605. if (rval != QLA_SUCCESS)
  1606. goto done_free;
  1607. p->link_failure_count = stats->link_fail_cnt;
  1608. p->loss_of_sync_count = stats->loss_sync_cnt;
  1609. p->loss_of_signal_count = stats->loss_sig_cnt;
  1610. p->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
  1611. p->invalid_tx_word_count = stats->inval_xmit_word_cnt;
  1612. p->invalid_crc_count = stats->inval_crc_cnt;
  1613. if (IS_FWI2_CAPABLE(ha)) {
  1614. p->lip_count = stats->lip_cnt;
  1615. p->tx_frames = stats->tx_frames;
  1616. p->rx_frames = stats->rx_frames;
  1617. p->dumped_frames = stats->discarded_frames;
  1618. p->nos_count = stats->nos_rcvd;
  1619. p->error_frames =
  1620. stats->dropped_frames + stats->discarded_frames;
  1621. p->rx_words = vha->qla_stats.input_bytes;
  1622. p->tx_words = vha->qla_stats.output_bytes;
  1623. }
  1624. p->fcp_control_requests = vha->qla_stats.control_requests;
  1625. p->fcp_input_requests = vha->qla_stats.input_requests;
  1626. p->fcp_output_requests = vha->qla_stats.output_requests;
  1627. p->fcp_input_megabytes = vha->qla_stats.input_bytes >> 20;
  1628. p->fcp_output_megabytes = vha->qla_stats.output_bytes >> 20;
  1629. p->seconds_since_last_reset =
  1630. get_jiffies_64() - vha->qla_stats.jiffies_at_last_reset;
  1631. do_div(p->seconds_since_last_reset, HZ);
  1632. done_free:
  1633. dma_free_coherent(&ha->pdev->dev, sizeof(struct link_statistics),
  1634. stats, stats_dma);
  1635. done:
  1636. return p;
  1637. }
  1638. static void
  1639. qla2x00_reset_host_stats(struct Scsi_Host *shost)
  1640. {
  1641. scsi_qla_host_t *vha = shost_priv(shost);
  1642. struct qla_hw_data *ha = vha->hw;
  1643. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  1644. struct link_statistics *stats;
  1645. dma_addr_t stats_dma;
  1646. memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
  1647. memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
  1648. vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
  1649. if (IS_FWI2_CAPABLE(ha)) {
  1650. stats = dma_alloc_coherent(&ha->pdev->dev,
  1651. sizeof(*stats), &stats_dma, GFP_KERNEL);
  1652. if (!stats) {
  1653. ql_log(ql_log_warn, vha, 0x70d7,
  1654. "Failed to allocate memory for stats.\n");
  1655. return;
  1656. }
  1657. /* reset firmware statistics */
  1658. qla24xx_get_isp_stats(base_vha, stats, stats_dma, BIT_0);
  1659. dma_free_coherent(&ha->pdev->dev, sizeof(*stats),
  1660. stats, stats_dma);
  1661. }
  1662. }
  1663. static void
  1664. qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
  1665. {
  1666. scsi_qla_host_t *vha = shost_priv(shost);
  1667. qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost),
  1668. sizeof(fc_host_symbolic_name(shost)));
  1669. }
  1670. static void
  1671. qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
  1672. {
  1673. scsi_qla_host_t *vha = shost_priv(shost);
  1674. set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
  1675. }
  1676. static void
  1677. qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
  1678. {
  1679. scsi_qla_host_t *vha = shost_priv(shost);
  1680. uint8_t node_name[WWN_SIZE] = { 0xFF, 0xFF, 0xFF, 0xFF, \
  1681. 0xFF, 0xFF, 0xFF, 0xFF};
  1682. u64 fabric_name = wwn_to_u64(node_name);
  1683. if (vha->device_flags & SWITCH_FOUND)
  1684. fabric_name = wwn_to_u64(vha->fabric_node_name);
  1685. fc_host_fabric_name(shost) = fabric_name;
  1686. }
  1687. static void
  1688. qla2x00_get_host_port_state(struct Scsi_Host *shost)
  1689. {
  1690. scsi_qla_host_t *vha = shost_priv(shost);
  1691. struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
  1692. if (!base_vha->flags.online) {
  1693. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  1694. return;
  1695. }
  1696. switch (atomic_read(&base_vha->loop_state)) {
  1697. case LOOP_UPDATE:
  1698. fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
  1699. break;
  1700. case LOOP_DOWN:
  1701. if (test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags))
  1702. fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
  1703. else
  1704. fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
  1705. break;
  1706. case LOOP_DEAD:
  1707. fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
  1708. break;
  1709. case LOOP_READY:
  1710. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  1711. break;
  1712. default:
  1713. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  1714. break;
  1715. }
  1716. }
  1717. static int
  1718. qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
  1719. {
  1720. int ret = 0;
  1721. uint8_t qos = 0;
  1722. scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
  1723. scsi_qla_host_t *vha = NULL;
  1724. struct qla_hw_data *ha = base_vha->hw;
  1725. int cnt;
  1726. struct req_que *req = ha->req_q_map[0];
  1727. struct qla_qpair *qpair;
  1728. ret = qla24xx_vport_create_req_sanity_check(fc_vport);
  1729. if (ret) {
  1730. ql_log(ql_log_warn, vha, 0x707e,
  1731. "Vport sanity check failed, status %x\n", ret);
  1732. return (ret);
  1733. }
  1734. vha = qla24xx_create_vhost(fc_vport);
  1735. if (vha == NULL) {
  1736. ql_log(ql_log_warn, vha, 0x707f, "Vport create host failed.\n");
  1737. return FC_VPORT_FAILED;
  1738. }
  1739. if (disable) {
  1740. atomic_set(&vha->vp_state, VP_OFFLINE);
  1741. fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
  1742. } else
  1743. atomic_set(&vha->vp_state, VP_FAILED);
  1744. /* ready to create vport */
  1745. ql_log(ql_log_info, vha, 0x7080,
  1746. "VP entry id %d assigned.\n", vha->vp_idx);
  1747. /* initialized vport states */
  1748. atomic_set(&vha->loop_state, LOOP_DOWN);
  1749. vha->vp_err_state= VP_ERR_PORTDWN;
  1750. vha->vp_prev_err_state= VP_ERR_UNKWN;
  1751. /* Check if physical ha port is Up */
  1752. if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
  1753. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  1754. /* Don't retry or attempt login of this virtual port */
  1755. ql_dbg(ql_dbg_user, vha, 0x7081,
  1756. "Vport loop state is not UP.\n");
  1757. atomic_set(&vha->loop_state, LOOP_DEAD);
  1758. if (!disable)
  1759. fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
  1760. }
  1761. if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
  1762. if (ha->fw_attributes & BIT_4) {
  1763. int prot = 0, guard;
  1764. vha->flags.difdix_supported = 1;
  1765. ql_dbg(ql_dbg_user, vha, 0x7082,
  1766. "Registered for DIF/DIX type 1 and 3 protection.\n");
  1767. if (ql2xenabledif == 1)
  1768. prot = SHOST_DIX_TYPE0_PROTECTION;
  1769. scsi_host_set_prot(vha->host,
  1770. prot | SHOST_DIF_TYPE1_PROTECTION
  1771. | SHOST_DIF_TYPE2_PROTECTION
  1772. | SHOST_DIF_TYPE3_PROTECTION
  1773. | SHOST_DIX_TYPE1_PROTECTION
  1774. | SHOST_DIX_TYPE2_PROTECTION
  1775. | SHOST_DIX_TYPE3_PROTECTION);
  1776. guard = SHOST_DIX_GUARD_CRC;
  1777. if (IS_PI_IPGUARD_CAPABLE(ha) &&
  1778. (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
  1779. guard |= SHOST_DIX_GUARD_IP;
  1780. scsi_host_set_guard(vha->host, guard);
  1781. } else
  1782. vha->flags.difdix_supported = 0;
  1783. }
  1784. if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
  1785. &ha->pdev->dev)) {
  1786. ql_dbg(ql_dbg_user, vha, 0x7083,
  1787. "scsi_add_host failure for VP[%d].\n", vha->vp_idx);
  1788. goto vport_create_failed_2;
  1789. }
  1790. /* initialize attributes */
  1791. fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
  1792. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1793. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1794. fc_host_supported_classes(vha->host) =
  1795. fc_host_supported_classes(base_vha->host);
  1796. fc_host_supported_speeds(vha->host) =
  1797. fc_host_supported_speeds(base_vha->host);
  1798. qlt_vport_create(vha, ha);
  1799. qla24xx_vport_disable(fc_vport, disable);
  1800. if (!ql2xmqsupport || !ha->npiv_info)
  1801. goto vport_queue;
  1802. /* Create a request queue in QoS mode for the vport */
  1803. for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
  1804. if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
  1805. && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
  1806. 8) == 0) {
  1807. qos = ha->npiv_info[cnt].q_qos;
  1808. break;
  1809. }
  1810. }
  1811. if (qos) {
  1812. qpair = qla2xxx_create_qpair(vha, qos, vha->vp_idx, true);
  1813. if (!qpair)
  1814. ql_log(ql_log_warn, vha, 0x7084,
  1815. "Can't create qpair for VP[%d]\n",
  1816. vha->vp_idx);
  1817. else {
  1818. ql_dbg(ql_dbg_multiq, vha, 0xc001,
  1819. "Queue pair: %d Qos: %d) created for VP[%d]\n",
  1820. qpair->id, qos, vha->vp_idx);
  1821. ql_dbg(ql_dbg_user, vha, 0x7085,
  1822. "Queue Pair: %d Qos: %d) created for VP[%d]\n",
  1823. qpair->id, qos, vha->vp_idx);
  1824. req = qpair->req;
  1825. vha->qpair = qpair;
  1826. }
  1827. }
  1828. vport_queue:
  1829. vha->req = req;
  1830. return 0;
  1831. vport_create_failed_2:
  1832. qla24xx_disable_vp(vha);
  1833. qla24xx_deallocate_vp_id(vha);
  1834. scsi_host_put(vha->host);
  1835. return FC_VPORT_FAILED;
  1836. }
  1837. static int
  1838. qla24xx_vport_delete(struct fc_vport *fc_vport)
  1839. {
  1840. scsi_qla_host_t *vha = fc_vport->dd_data;
  1841. struct qla_hw_data *ha = vha->hw;
  1842. uint16_t id = vha->vp_idx;
  1843. while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
  1844. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
  1845. msleep(1000);
  1846. qla24xx_disable_vp(vha);
  1847. qla2x00_wait_for_sess_deletion(vha);
  1848. vha->flags.delete_progress = 1;
  1849. qlt_remove_target(ha, vha);
  1850. fc_remove_host(vha->host);
  1851. scsi_remove_host(vha->host);
  1852. /* Allow timer to run to drain queued items, when removing vp */
  1853. qla24xx_deallocate_vp_id(vha);
  1854. if (vha->timer_active) {
  1855. qla2x00_vp_stop_timer(vha);
  1856. ql_dbg(ql_dbg_user, vha, 0x7086,
  1857. "Timer for the VP[%d] has stopped\n", vha->vp_idx);
  1858. }
  1859. qla2x00_free_fcports(vha);
  1860. mutex_lock(&ha->vport_lock);
  1861. ha->cur_vport_count--;
  1862. clear_bit(vha->vp_idx, ha->vp_idx_map);
  1863. mutex_unlock(&ha->vport_lock);
  1864. dma_free_coherent(&ha->pdev->dev, vha->gnl.size, vha->gnl.l,
  1865. vha->gnl.ldma);
  1866. vha->gnl.l = NULL;
  1867. vfree(vha->scan.l);
  1868. if (vha->qpair && vha->qpair->vp_idx == vha->vp_idx) {
  1869. if (qla2xxx_delete_qpair(vha, vha->qpair) != QLA_SUCCESS)
  1870. ql_log(ql_log_warn, vha, 0x7087,
  1871. "Queue Pair delete failed.\n");
  1872. }
  1873. ql_log(ql_log_info, vha, 0x7088, "VP[%d] deleted.\n", id);
  1874. scsi_host_put(vha->host);
  1875. return 0;
  1876. }
  1877. static int
  1878. qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
  1879. {
  1880. scsi_qla_host_t *vha = fc_vport->dd_data;
  1881. if (disable)
  1882. qla24xx_disable_vp(vha);
  1883. else
  1884. qla24xx_enable_vp(vha);
  1885. return 0;
  1886. }
  1887. struct fc_function_template qla2xxx_transport_functions = {
  1888. .show_host_node_name = 1,
  1889. .show_host_port_name = 1,
  1890. .show_host_supported_classes = 1,
  1891. .show_host_supported_speeds = 1,
  1892. .get_host_port_id = qla2x00_get_host_port_id,
  1893. .show_host_port_id = 1,
  1894. .get_host_speed = qla2x00_get_host_speed,
  1895. .show_host_speed = 1,
  1896. .get_host_port_type = qla2x00_get_host_port_type,
  1897. .show_host_port_type = 1,
  1898. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1899. .show_host_symbolic_name = 1,
  1900. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1901. .show_host_system_hostname = 1,
  1902. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1903. .show_host_fabric_name = 1,
  1904. .get_host_port_state = qla2x00_get_host_port_state,
  1905. .show_host_port_state = 1,
  1906. .dd_fcrport_size = sizeof(struct fc_port *),
  1907. .show_rport_supported_classes = 1,
  1908. .get_starget_node_name = qla2x00_get_starget_node_name,
  1909. .show_starget_node_name = 1,
  1910. .get_starget_port_name = qla2x00_get_starget_port_name,
  1911. .show_starget_port_name = 1,
  1912. .get_starget_port_id = qla2x00_get_starget_port_id,
  1913. .show_starget_port_id = 1,
  1914. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1915. .show_rport_dev_loss_tmo = 1,
  1916. .issue_fc_host_lip = qla2x00_issue_lip,
  1917. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  1918. .terminate_rport_io = qla2x00_terminate_rport_io,
  1919. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1920. .reset_fc_host_stats = qla2x00_reset_host_stats,
  1921. .vport_create = qla24xx_vport_create,
  1922. .vport_disable = qla24xx_vport_disable,
  1923. .vport_delete = qla24xx_vport_delete,
  1924. .bsg_request = qla24xx_bsg_request,
  1925. .bsg_timeout = qla24xx_bsg_timeout,
  1926. };
  1927. struct fc_function_template qla2xxx_transport_vport_functions = {
  1928. .show_host_node_name = 1,
  1929. .show_host_port_name = 1,
  1930. .show_host_supported_classes = 1,
  1931. .get_host_port_id = qla2x00_get_host_port_id,
  1932. .show_host_port_id = 1,
  1933. .get_host_speed = qla2x00_get_host_speed,
  1934. .show_host_speed = 1,
  1935. .get_host_port_type = qla2x00_get_host_port_type,
  1936. .show_host_port_type = 1,
  1937. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1938. .show_host_symbolic_name = 1,
  1939. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1940. .show_host_system_hostname = 1,
  1941. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1942. .show_host_fabric_name = 1,
  1943. .get_host_port_state = qla2x00_get_host_port_state,
  1944. .show_host_port_state = 1,
  1945. .dd_fcrport_size = sizeof(struct fc_port *),
  1946. .show_rport_supported_classes = 1,
  1947. .get_starget_node_name = qla2x00_get_starget_node_name,
  1948. .show_starget_node_name = 1,
  1949. .get_starget_port_name = qla2x00_get_starget_port_name,
  1950. .show_starget_port_name = 1,
  1951. .get_starget_port_id = qla2x00_get_starget_port_id,
  1952. .show_starget_port_id = 1,
  1953. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1954. .show_rport_dev_loss_tmo = 1,
  1955. .issue_fc_host_lip = qla2x00_issue_lip,
  1956. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  1957. .terminate_rport_io = qla2x00_terminate_rport_io,
  1958. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1959. .reset_fc_host_stats = qla2x00_reset_host_stats,
  1960. .bsg_request = qla24xx_bsg_request,
  1961. .bsg_timeout = qla24xx_bsg_timeout,
  1962. };
  1963. void
  1964. qla2x00_init_host_attr(scsi_qla_host_t *vha)
  1965. {
  1966. struct qla_hw_data *ha = vha->hw;
  1967. u32 speed = FC_PORTSPEED_UNKNOWN;
  1968. fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
  1969. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1970. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1971. fc_host_supported_classes(vha->host) = ha->base_qpair->enable_class_2 ?
  1972. (FC_COS_CLASS2|FC_COS_CLASS3) : FC_COS_CLASS3;
  1973. fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
  1974. fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
  1975. if (IS_CNA_CAPABLE(ha))
  1976. speed = FC_PORTSPEED_10GBIT;
  1977. else if (IS_QLA2031(ha))
  1978. speed = FC_PORTSPEED_16GBIT | FC_PORTSPEED_8GBIT |
  1979. FC_PORTSPEED_4GBIT;
  1980. else if (IS_QLA25XX(ha))
  1981. speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
  1982. FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1983. else if (IS_QLA24XX_TYPE(ha))
  1984. speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
  1985. FC_PORTSPEED_1GBIT;
  1986. else if (IS_QLA23XX(ha))
  1987. speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1988. else if (IS_QLAFX00(ha))
  1989. speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
  1990. FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1991. else if (IS_QLA27XX(ha))
  1992. speed = FC_PORTSPEED_32GBIT | FC_PORTSPEED_16GBIT |
  1993. FC_PORTSPEED_8GBIT;
  1994. else
  1995. speed = FC_PORTSPEED_1GBIT;
  1996. fc_host_supported_speeds(vha->host) = speed;
  1997. }