qla_attr.c 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323
  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 = start + 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 = start + 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 (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
  451. !ha->isp_ops->write_nvram)
  452. return 0;
  453. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  454. ql_log(ql_log_warn, vha, 0x706a,
  455. "HBA not online, failing VPD update.\n");
  456. return -EAGAIN;
  457. }
  458. /* Write NVRAM. */
  459. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
  460. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
  461. /* Update flash version information for 4Gb & above. */
  462. if (!IS_FWI2_CAPABLE(ha))
  463. return -EINVAL;
  464. tmp_data = vmalloc(256);
  465. if (!tmp_data) {
  466. ql_log(ql_log_warn, vha, 0x706b,
  467. "Unable to allocate memory for VPD information update.\n");
  468. return -ENOMEM;
  469. }
  470. ha->isp_ops->get_flash_version(vha, tmp_data);
  471. vfree(tmp_data);
  472. return count;
  473. }
  474. static struct bin_attribute sysfs_vpd_attr = {
  475. .attr = {
  476. .name = "vpd",
  477. .mode = S_IRUSR | S_IWUSR,
  478. },
  479. .size = 0,
  480. .read = qla2x00_sysfs_read_vpd,
  481. .write = qla2x00_sysfs_write_vpd,
  482. };
  483. static ssize_t
  484. qla2x00_sysfs_read_sfp(struct file *filp, struct kobject *kobj,
  485. struct bin_attribute *bin_attr,
  486. char *buf, loff_t off, size_t count)
  487. {
  488. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  489. struct device, kobj)));
  490. struct qla_hw_data *ha = vha->hw;
  491. uint16_t iter, addr, offset;
  492. int rval;
  493. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
  494. return 0;
  495. if (ha->sfp_data)
  496. goto do_read;
  497. ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  498. &ha->sfp_data_dma);
  499. if (!ha->sfp_data) {
  500. ql_log(ql_log_warn, vha, 0x706c,
  501. "Unable to allocate memory for SFP read-data.\n");
  502. return 0;
  503. }
  504. do_read:
  505. memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
  506. addr = 0xa0;
  507. for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
  508. iter++, offset += SFP_BLOCK_SIZE) {
  509. if (iter == 4) {
  510. /* Skip to next device address. */
  511. addr = 0xa2;
  512. offset = 0;
  513. }
  514. rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, ha->sfp_data,
  515. addr, offset, SFP_BLOCK_SIZE, BIT_1);
  516. if (rval != QLA_SUCCESS) {
  517. ql_log(ql_log_warn, vha, 0x706d,
  518. "Unable to read SFP data (%x/%x/%x).\n", rval,
  519. addr, offset);
  520. return -EIO;
  521. }
  522. memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
  523. buf += SFP_BLOCK_SIZE;
  524. }
  525. return count;
  526. }
  527. static struct bin_attribute sysfs_sfp_attr = {
  528. .attr = {
  529. .name = "sfp",
  530. .mode = S_IRUSR | S_IWUSR,
  531. },
  532. .size = SFP_DEV_SIZE * 2,
  533. .read = qla2x00_sysfs_read_sfp,
  534. };
  535. static ssize_t
  536. qla2x00_sysfs_write_reset(struct file *filp, struct kobject *kobj,
  537. struct bin_attribute *bin_attr,
  538. char *buf, loff_t off, size_t count)
  539. {
  540. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  541. struct device, kobj)));
  542. struct qla_hw_data *ha = vha->hw;
  543. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  544. int type;
  545. uint32_t idc_control;
  546. uint8_t *tmp_data = NULL;
  547. if (off != 0)
  548. return -EINVAL;
  549. type = simple_strtol(buf, NULL, 10);
  550. switch (type) {
  551. case 0x2025c:
  552. ql_log(ql_log_info, vha, 0x706e,
  553. "Issuing ISP reset.\n");
  554. scsi_block_requests(vha->host);
  555. if (IS_QLA82XX(ha)) {
  556. ha->flags.isp82xx_no_md_cap = 1;
  557. qla82xx_idc_lock(ha);
  558. qla82xx_set_reset_owner(vha);
  559. qla82xx_idc_unlock(ha);
  560. } else if (IS_QLA8044(ha)) {
  561. qla8044_idc_lock(ha);
  562. idc_control = qla8044_rd_reg(ha,
  563. QLA8044_IDC_DRV_CTRL);
  564. qla8044_wr_reg(ha, QLA8044_IDC_DRV_CTRL,
  565. (idc_control | GRACEFUL_RESET_BIT1));
  566. qla82xx_set_reset_owner(vha);
  567. qla8044_idc_unlock(ha);
  568. } else {
  569. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  570. qla2xxx_wake_dpc(vha);
  571. }
  572. qla2x00_wait_for_chip_reset(vha);
  573. scsi_unblock_requests(vha->host);
  574. break;
  575. case 0x2025d:
  576. if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha))
  577. return -EPERM;
  578. ql_log(ql_log_info, vha, 0x706f,
  579. "Issuing MPI reset.\n");
  580. if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
  581. uint32_t idc_control;
  582. qla83xx_idc_lock(vha, 0);
  583. __qla83xx_get_idc_control(vha, &idc_control);
  584. idc_control |= QLA83XX_IDC_GRACEFUL_RESET;
  585. __qla83xx_set_idc_control(vha, idc_control);
  586. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
  587. QLA8XXX_DEV_NEED_RESET);
  588. qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
  589. qla83xx_idc_unlock(vha, 0);
  590. break;
  591. } else {
  592. /* Make sure FC side is not in reset */
  593. qla2x00_wait_for_hba_online(vha);
  594. /* Issue MPI reset */
  595. scsi_block_requests(vha->host);
  596. if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
  597. ql_log(ql_log_warn, vha, 0x7070,
  598. "MPI reset failed.\n");
  599. scsi_unblock_requests(vha->host);
  600. break;
  601. }
  602. case 0x2025e:
  603. if (!IS_P3P_TYPE(ha) || vha != base_vha) {
  604. ql_log(ql_log_info, vha, 0x7071,
  605. "FCoE ctx reset no supported.\n");
  606. return -EPERM;
  607. }
  608. ql_log(ql_log_info, vha, 0x7072,
  609. "Issuing FCoE ctx reset.\n");
  610. set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
  611. qla2xxx_wake_dpc(vha);
  612. qla2x00_wait_for_fcoe_ctx_reset(vha);
  613. break;
  614. case 0x2025f:
  615. if (!IS_QLA8031(ha))
  616. return -EPERM;
  617. ql_log(ql_log_info, vha, 0x70bc,
  618. "Disabling Reset by IDC control\n");
  619. qla83xx_idc_lock(vha, 0);
  620. __qla83xx_get_idc_control(vha, &idc_control);
  621. idc_control |= QLA83XX_IDC_RESET_DISABLED;
  622. __qla83xx_set_idc_control(vha, idc_control);
  623. qla83xx_idc_unlock(vha, 0);
  624. break;
  625. case 0x20260:
  626. if (!IS_QLA8031(ha))
  627. return -EPERM;
  628. ql_log(ql_log_info, vha, 0x70bd,
  629. "Enabling Reset by IDC control\n");
  630. qla83xx_idc_lock(vha, 0);
  631. __qla83xx_get_idc_control(vha, &idc_control);
  632. idc_control &= ~QLA83XX_IDC_RESET_DISABLED;
  633. __qla83xx_set_idc_control(vha, idc_control);
  634. qla83xx_idc_unlock(vha, 0);
  635. break;
  636. case 0x20261:
  637. ql_dbg(ql_dbg_user, vha, 0x70e0,
  638. "Updating cache versions without reset ");
  639. tmp_data = vmalloc(256);
  640. if (!tmp_data) {
  641. ql_log(ql_log_warn, vha, 0x70e1,
  642. "Unable to allocate memory for VPD information update.\n");
  643. return -ENOMEM;
  644. }
  645. ha->isp_ops->get_flash_version(vha, tmp_data);
  646. vfree(tmp_data);
  647. break;
  648. }
  649. return count;
  650. }
  651. static struct bin_attribute sysfs_reset_attr = {
  652. .attr = {
  653. .name = "reset",
  654. .mode = S_IWUSR,
  655. },
  656. .size = 0,
  657. .write = qla2x00_sysfs_write_reset,
  658. };
  659. static ssize_t
  660. qla2x00_issue_logo(struct file *filp, struct kobject *kobj,
  661. struct bin_attribute *bin_attr,
  662. char *buf, loff_t off, size_t count)
  663. {
  664. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  665. struct device, kobj)));
  666. int type;
  667. int rval = 0;
  668. port_id_t did;
  669. type = simple_strtol(buf, NULL, 10);
  670. did.b.domain = (type & 0x00ff0000) >> 16;
  671. did.b.area = (type & 0x0000ff00) >> 8;
  672. did.b.al_pa = (type & 0x000000ff);
  673. ql_log(ql_log_info, vha, 0x70e3, "portid=%02x%02x%02x done\n",
  674. did.b.domain, did.b.area, did.b.al_pa);
  675. ql_log(ql_log_info, vha, 0x70e4, "%s: %d\n", __func__, type);
  676. rval = qla24xx_els_dcmd_iocb(vha, ELS_DCMD_LOGO, did);
  677. return count;
  678. }
  679. static struct bin_attribute sysfs_issue_logo_attr = {
  680. .attr = {
  681. .name = "issue_logo",
  682. .mode = S_IWUSR,
  683. },
  684. .size = 0,
  685. .write = qla2x00_issue_logo,
  686. };
  687. static ssize_t
  688. qla2x00_sysfs_read_xgmac_stats(struct file *filp, struct kobject *kobj,
  689. struct bin_attribute *bin_attr,
  690. char *buf, loff_t off, size_t count)
  691. {
  692. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  693. struct device, kobj)));
  694. struct qla_hw_data *ha = vha->hw;
  695. int rval;
  696. uint16_t actual_size;
  697. if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
  698. return 0;
  699. if (ha->xgmac_data)
  700. goto do_read;
  701. ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
  702. &ha->xgmac_data_dma, GFP_KERNEL);
  703. if (!ha->xgmac_data) {
  704. ql_log(ql_log_warn, vha, 0x7076,
  705. "Unable to allocate memory for XGMAC read-data.\n");
  706. return 0;
  707. }
  708. do_read:
  709. actual_size = 0;
  710. memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
  711. rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
  712. XGMAC_DATA_SIZE, &actual_size);
  713. if (rval != QLA_SUCCESS) {
  714. ql_log(ql_log_warn, vha, 0x7077,
  715. "Unable to read XGMAC data (%x).\n", rval);
  716. count = 0;
  717. }
  718. count = actual_size > count ? count: actual_size;
  719. memcpy(buf, ha->xgmac_data, count);
  720. return count;
  721. }
  722. static struct bin_attribute sysfs_xgmac_stats_attr = {
  723. .attr = {
  724. .name = "xgmac_stats",
  725. .mode = S_IRUSR,
  726. },
  727. .size = 0,
  728. .read = qla2x00_sysfs_read_xgmac_stats,
  729. };
  730. static ssize_t
  731. qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj,
  732. struct bin_attribute *bin_attr,
  733. char *buf, loff_t off, size_t count)
  734. {
  735. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  736. struct device, kobj)));
  737. struct qla_hw_data *ha = vha->hw;
  738. int rval;
  739. if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
  740. return 0;
  741. if (ha->dcbx_tlv)
  742. goto do_read;
  743. ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
  744. &ha->dcbx_tlv_dma, GFP_KERNEL);
  745. if (!ha->dcbx_tlv) {
  746. ql_log(ql_log_warn, vha, 0x7078,
  747. "Unable to allocate memory for DCBX TLV read-data.\n");
  748. return -ENOMEM;
  749. }
  750. do_read:
  751. memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
  752. rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
  753. DCBX_TLV_DATA_SIZE);
  754. if (rval != QLA_SUCCESS) {
  755. ql_log(ql_log_warn, vha, 0x7079,
  756. "Unable to read DCBX TLV (%x).\n", rval);
  757. return -EIO;
  758. }
  759. memcpy(buf, ha->dcbx_tlv, count);
  760. return count;
  761. }
  762. static struct bin_attribute sysfs_dcbx_tlv_attr = {
  763. .attr = {
  764. .name = "dcbx_tlv",
  765. .mode = S_IRUSR,
  766. },
  767. .size = 0,
  768. .read = qla2x00_sysfs_read_dcbx_tlv,
  769. };
  770. static struct sysfs_entry {
  771. char *name;
  772. struct bin_attribute *attr;
  773. int is4GBp_only;
  774. } bin_file_entries[] = {
  775. { "fw_dump", &sysfs_fw_dump_attr, },
  776. { "nvram", &sysfs_nvram_attr, },
  777. { "optrom", &sysfs_optrom_attr, },
  778. { "optrom_ctl", &sysfs_optrom_ctl_attr, },
  779. { "vpd", &sysfs_vpd_attr, 1 },
  780. { "sfp", &sysfs_sfp_attr, 1 },
  781. { "reset", &sysfs_reset_attr, },
  782. { "issue_logo", &sysfs_issue_logo_attr, },
  783. { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
  784. { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
  785. { NULL },
  786. };
  787. void
  788. qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
  789. {
  790. struct Scsi_Host *host = vha->host;
  791. struct sysfs_entry *iter;
  792. int ret;
  793. for (iter = bin_file_entries; iter->name; iter++) {
  794. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
  795. continue;
  796. if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
  797. continue;
  798. if (iter->is4GBp_only == 3 && !(IS_CNA_CAPABLE(vha->hw)))
  799. continue;
  800. ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
  801. iter->attr);
  802. if (ret)
  803. ql_log(ql_log_warn, vha, 0x00f3,
  804. "Unable to create sysfs %s binary attribute (%d).\n",
  805. iter->name, ret);
  806. else
  807. ql_dbg(ql_dbg_init, vha, 0x00f4,
  808. "Successfully created sysfs %s binary attribure.\n",
  809. iter->name);
  810. }
  811. }
  812. void
  813. qla2x00_free_sysfs_attr(scsi_qla_host_t *vha, bool stop_beacon)
  814. {
  815. struct Scsi_Host *host = vha->host;
  816. struct sysfs_entry *iter;
  817. struct qla_hw_data *ha = vha->hw;
  818. for (iter = bin_file_entries; iter->name; iter++) {
  819. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
  820. continue;
  821. if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
  822. continue;
  823. if (iter->is4GBp_only == 3 && !(IS_CNA_CAPABLE(vha->hw)))
  824. continue;
  825. if (iter->is4GBp_only == 0x27 && !IS_QLA27XX(vha->hw))
  826. continue;
  827. sysfs_remove_bin_file(&host->shost_gendev.kobj,
  828. iter->attr);
  829. }
  830. if (stop_beacon && ha->beacon_blink_led == 1)
  831. ha->isp_ops->beacon_off(vha);
  832. }
  833. /* Scsi_Host attributes. */
  834. static ssize_t
  835. qla2x00_drvr_version_show(struct device *dev,
  836. struct device_attribute *attr, char *buf)
  837. {
  838. return scnprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
  839. }
  840. static ssize_t
  841. qla2x00_fw_version_show(struct device *dev,
  842. struct device_attribute *attr, char *buf)
  843. {
  844. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  845. struct qla_hw_data *ha = vha->hw;
  846. char fw_str[128];
  847. return scnprintf(buf, PAGE_SIZE, "%s\n",
  848. ha->isp_ops->fw_version_str(vha, fw_str, sizeof(fw_str)));
  849. }
  850. static ssize_t
  851. qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
  852. char *buf)
  853. {
  854. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  855. struct qla_hw_data *ha = vha->hw;
  856. uint32_t sn;
  857. if (IS_QLAFX00(vha->hw)) {
  858. return scnprintf(buf, PAGE_SIZE, "%s\n",
  859. vha->hw->mr.serial_num);
  860. } else if (IS_FWI2_CAPABLE(ha)) {
  861. qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE - 1);
  862. return strlen(strcat(buf, "\n"));
  863. }
  864. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  865. return scnprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
  866. sn % 100000);
  867. }
  868. static ssize_t
  869. qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
  870. char *buf)
  871. {
  872. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  873. return scnprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
  874. }
  875. static ssize_t
  876. qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
  877. char *buf)
  878. {
  879. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  880. struct qla_hw_data *ha = vha->hw;
  881. if (IS_QLAFX00(vha->hw))
  882. return scnprintf(buf, PAGE_SIZE, "%s\n",
  883. vha->hw->mr.hw_version);
  884. return scnprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
  885. ha->product_id[0], ha->product_id[1], ha->product_id[2],
  886. ha->product_id[3]);
  887. }
  888. static ssize_t
  889. qla2x00_model_name_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. return scnprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
  894. }
  895. static ssize_t
  896. qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
  897. char *buf)
  898. {
  899. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  900. return scnprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_desc);
  901. }
  902. static ssize_t
  903. qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
  904. char *buf)
  905. {
  906. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  907. char pci_info[30];
  908. return scnprintf(buf, PAGE_SIZE, "%s\n",
  909. vha->hw->isp_ops->pci_info_str(vha, pci_info));
  910. }
  911. static ssize_t
  912. qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
  913. char *buf)
  914. {
  915. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  916. struct qla_hw_data *ha = vha->hw;
  917. int len = 0;
  918. if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
  919. atomic_read(&vha->loop_state) == LOOP_DEAD ||
  920. vha->device_flags & DFLG_NO_CABLE)
  921. len = scnprintf(buf, PAGE_SIZE, "Link Down\n");
  922. else if (atomic_read(&vha->loop_state) != LOOP_READY ||
  923. qla2x00_reset_active(vha))
  924. len = scnprintf(buf, PAGE_SIZE, "Unknown Link State\n");
  925. else {
  926. len = scnprintf(buf, PAGE_SIZE, "Link Up - ");
  927. switch (ha->current_topology) {
  928. case ISP_CFG_NL:
  929. len += scnprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  930. break;
  931. case ISP_CFG_FL:
  932. len += scnprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
  933. break;
  934. case ISP_CFG_N:
  935. len += scnprintf(buf + len, PAGE_SIZE-len,
  936. "N_Port to N_Port\n");
  937. break;
  938. case ISP_CFG_F:
  939. len += scnprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
  940. break;
  941. default:
  942. len += scnprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  943. break;
  944. }
  945. }
  946. return len;
  947. }
  948. static ssize_t
  949. qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
  950. char *buf)
  951. {
  952. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  953. int len = 0;
  954. switch (vha->hw->zio_mode) {
  955. case QLA_ZIO_MODE_6:
  956. len += scnprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
  957. break;
  958. case QLA_ZIO_DISABLED:
  959. len += scnprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  960. break;
  961. }
  962. return len;
  963. }
  964. static ssize_t
  965. qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
  966. const char *buf, size_t count)
  967. {
  968. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  969. struct qla_hw_data *ha = vha->hw;
  970. int val = 0;
  971. uint16_t zio_mode;
  972. if (!IS_ZIO_SUPPORTED(ha))
  973. return -ENOTSUPP;
  974. if (sscanf(buf, "%d", &val) != 1)
  975. return -EINVAL;
  976. if (val)
  977. zio_mode = QLA_ZIO_MODE_6;
  978. else
  979. zio_mode = QLA_ZIO_DISABLED;
  980. /* Update per-hba values and queue a reset. */
  981. if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
  982. ha->zio_mode = zio_mode;
  983. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  984. }
  985. return strlen(buf);
  986. }
  987. static ssize_t
  988. qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
  989. char *buf)
  990. {
  991. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  992. return scnprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
  993. }
  994. static ssize_t
  995. qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
  996. const char *buf, size_t count)
  997. {
  998. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  999. int val = 0;
  1000. uint16_t zio_timer;
  1001. if (sscanf(buf, "%d", &val) != 1)
  1002. return -EINVAL;
  1003. if (val > 25500 || val < 100)
  1004. return -ERANGE;
  1005. zio_timer = (uint16_t)(val / 100);
  1006. vha->hw->zio_timer = zio_timer;
  1007. return strlen(buf);
  1008. }
  1009. static ssize_t
  1010. qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
  1011. char *buf)
  1012. {
  1013. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1014. int len = 0;
  1015. if (vha->hw->beacon_blink_led)
  1016. len += scnprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
  1017. else
  1018. len += scnprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  1019. return len;
  1020. }
  1021. static ssize_t
  1022. qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
  1023. const char *buf, size_t count)
  1024. {
  1025. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1026. struct qla_hw_data *ha = vha->hw;
  1027. int val = 0;
  1028. int rval;
  1029. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  1030. return -EPERM;
  1031. if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
  1032. ql_log(ql_log_warn, vha, 0x707a,
  1033. "Abort ISP active -- ignoring beacon request.\n");
  1034. return -EBUSY;
  1035. }
  1036. if (sscanf(buf, "%d", &val) != 1)
  1037. return -EINVAL;
  1038. if (val)
  1039. rval = ha->isp_ops->beacon_on(vha);
  1040. else
  1041. rval = ha->isp_ops->beacon_off(vha);
  1042. if (rval != QLA_SUCCESS)
  1043. count = 0;
  1044. return count;
  1045. }
  1046. static ssize_t
  1047. qla2x00_optrom_bios_version_show(struct device *dev,
  1048. struct device_attribute *attr, char *buf)
  1049. {
  1050. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1051. struct qla_hw_data *ha = vha->hw;
  1052. return scnprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
  1053. ha->bios_revision[0]);
  1054. }
  1055. static ssize_t
  1056. qla2x00_optrom_efi_version_show(struct device *dev,
  1057. struct device_attribute *attr, char *buf)
  1058. {
  1059. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1060. struct qla_hw_data *ha = vha->hw;
  1061. return scnprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
  1062. ha->efi_revision[0]);
  1063. }
  1064. static ssize_t
  1065. qla2x00_optrom_fcode_version_show(struct device *dev,
  1066. struct device_attribute *attr, char *buf)
  1067. {
  1068. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1069. struct qla_hw_data *ha = vha->hw;
  1070. return scnprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
  1071. ha->fcode_revision[0]);
  1072. }
  1073. static ssize_t
  1074. qla2x00_optrom_fw_version_show(struct device *dev,
  1075. struct device_attribute *attr, char *buf)
  1076. {
  1077. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1078. struct qla_hw_data *ha = vha->hw;
  1079. return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
  1080. ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
  1081. ha->fw_revision[3]);
  1082. }
  1083. static ssize_t
  1084. qla2x00_optrom_gold_fw_version_show(struct device *dev,
  1085. struct device_attribute *attr, char *buf)
  1086. {
  1087. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1088. struct qla_hw_data *ha = vha->hw;
  1089. if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha) && !IS_QLA27XX(ha))
  1090. return scnprintf(buf, PAGE_SIZE, "\n");
  1091. return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%d)\n",
  1092. ha->gold_fw_version[0], ha->gold_fw_version[1],
  1093. ha->gold_fw_version[2], ha->gold_fw_version[3]);
  1094. }
  1095. static ssize_t
  1096. qla2x00_total_isp_aborts_show(struct device *dev,
  1097. struct device_attribute *attr, char *buf)
  1098. {
  1099. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1100. return scnprintf(buf, PAGE_SIZE, "%d\n",
  1101. vha->qla_stats.total_isp_aborts);
  1102. }
  1103. static ssize_t
  1104. qla24xx_84xx_fw_version_show(struct device *dev,
  1105. struct device_attribute *attr, char *buf)
  1106. {
  1107. int rval = QLA_SUCCESS;
  1108. uint16_t status[2] = {0, 0};
  1109. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1110. struct qla_hw_data *ha = vha->hw;
  1111. if (!IS_QLA84XX(ha))
  1112. return scnprintf(buf, PAGE_SIZE, "\n");
  1113. if (ha->cs84xx->op_fw_version == 0)
  1114. rval = qla84xx_verify_chip(vha, status);
  1115. if ((rval == QLA_SUCCESS) && (status[0] == 0))
  1116. return scnprintf(buf, PAGE_SIZE, "%u\n",
  1117. (uint32_t)ha->cs84xx->op_fw_version);
  1118. return scnprintf(buf, PAGE_SIZE, "\n");
  1119. }
  1120. static ssize_t
  1121. qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
  1122. char *buf)
  1123. {
  1124. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1125. struct qla_hw_data *ha = vha->hw;
  1126. if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha) &&
  1127. !IS_QLA27XX(ha))
  1128. return scnprintf(buf, PAGE_SIZE, "\n");
  1129. return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
  1130. ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
  1131. ha->mpi_capabilities);
  1132. }
  1133. static ssize_t
  1134. qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
  1135. char *buf)
  1136. {
  1137. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1138. struct qla_hw_data *ha = vha->hw;
  1139. if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
  1140. return scnprintf(buf, PAGE_SIZE, "\n");
  1141. return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
  1142. ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
  1143. }
  1144. static ssize_t
  1145. qla2x00_flash_block_size_show(struct device *dev,
  1146. struct device_attribute *attr, char *buf)
  1147. {
  1148. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1149. struct qla_hw_data *ha = vha->hw;
  1150. return scnprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
  1151. }
  1152. static ssize_t
  1153. qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
  1154. char *buf)
  1155. {
  1156. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1157. if (!IS_CNA_CAPABLE(vha->hw))
  1158. return scnprintf(buf, PAGE_SIZE, "\n");
  1159. return scnprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
  1160. }
  1161. static ssize_t
  1162. qla2x00_vn_port_mac_address_show(struct device *dev,
  1163. struct device_attribute *attr, char *buf)
  1164. {
  1165. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1166. if (!IS_CNA_CAPABLE(vha->hw))
  1167. return scnprintf(buf, PAGE_SIZE, "\n");
  1168. return scnprintf(buf, PAGE_SIZE, "%pMR\n", vha->fcoe_vn_port_mac);
  1169. }
  1170. static ssize_t
  1171. qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
  1172. char *buf)
  1173. {
  1174. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1175. return scnprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
  1176. }
  1177. static ssize_t
  1178. qla2x00_thermal_temp_show(struct device *dev,
  1179. struct device_attribute *attr, char *buf)
  1180. {
  1181. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1182. uint16_t temp = 0;
  1183. if (qla2x00_reset_active(vha)) {
  1184. ql_log(ql_log_warn, vha, 0x70dc, "ISP reset active.\n");
  1185. goto done;
  1186. }
  1187. if (vha->hw->flags.eeh_busy) {
  1188. ql_log(ql_log_warn, vha, 0x70dd, "PCI EEH busy.\n");
  1189. goto done;
  1190. }
  1191. if (qla2x00_get_thermal_temp(vha, &temp) == QLA_SUCCESS)
  1192. return scnprintf(buf, PAGE_SIZE, "%d\n", temp);
  1193. done:
  1194. return scnprintf(buf, PAGE_SIZE, "\n");
  1195. }
  1196. static ssize_t
  1197. qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
  1198. char *buf)
  1199. {
  1200. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1201. int rval = QLA_FUNCTION_FAILED;
  1202. uint16_t state[6];
  1203. uint32_t pstate;
  1204. if (IS_QLAFX00(vha->hw)) {
  1205. pstate = qlafx00_fw_state_show(dev, attr, buf);
  1206. return scnprintf(buf, PAGE_SIZE, "0x%x\n", pstate);
  1207. }
  1208. if (qla2x00_reset_active(vha))
  1209. ql_log(ql_log_warn, vha, 0x707c,
  1210. "ISP reset active.\n");
  1211. else if (!vha->hw->flags.eeh_busy)
  1212. rval = qla2x00_get_firmware_state(vha, state);
  1213. if (rval != QLA_SUCCESS)
  1214. memset(state, -1, sizeof(state));
  1215. return scnprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
  1216. state[0], state[1], state[2], state[3], state[4], state[5]);
  1217. }
  1218. static ssize_t
  1219. qla2x00_diag_requests_show(struct device *dev,
  1220. struct device_attribute *attr, char *buf)
  1221. {
  1222. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1223. if (!IS_BIDI_CAPABLE(vha->hw))
  1224. return scnprintf(buf, PAGE_SIZE, "\n");
  1225. return scnprintf(buf, PAGE_SIZE, "%llu\n", vha->bidi_stats.io_count);
  1226. }
  1227. static ssize_t
  1228. qla2x00_diag_megabytes_show(struct device *dev,
  1229. struct device_attribute *attr, char *buf)
  1230. {
  1231. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1232. if (!IS_BIDI_CAPABLE(vha->hw))
  1233. return scnprintf(buf, PAGE_SIZE, "\n");
  1234. return scnprintf(buf, PAGE_SIZE, "%llu\n",
  1235. vha->bidi_stats.transfer_bytes >> 20);
  1236. }
  1237. static ssize_t
  1238. qla2x00_fw_dump_size_show(struct device *dev, struct device_attribute *attr,
  1239. char *buf)
  1240. {
  1241. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1242. struct qla_hw_data *ha = vha->hw;
  1243. uint32_t size;
  1244. if (!ha->fw_dumped)
  1245. size = 0;
  1246. else if (IS_P3P_TYPE(ha))
  1247. size = ha->md_template_size + ha->md_dump_size;
  1248. else
  1249. size = ha->fw_dump_len;
  1250. return scnprintf(buf, PAGE_SIZE, "%d\n", size);
  1251. }
  1252. static ssize_t
  1253. qla2x00_allow_cna_fw_dump_show(struct device *dev,
  1254. struct device_attribute *attr, char *buf)
  1255. {
  1256. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1257. if (!IS_P3P_TYPE(vha->hw))
  1258. return scnprintf(buf, PAGE_SIZE, "\n");
  1259. else
  1260. return scnprintf(buf, PAGE_SIZE, "%s\n",
  1261. vha->hw->allow_cna_fw_dump ? "true" : "false");
  1262. }
  1263. static ssize_t
  1264. qla2x00_allow_cna_fw_dump_store(struct device *dev,
  1265. struct device_attribute *attr, const char *buf, size_t count)
  1266. {
  1267. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1268. int val = 0;
  1269. if (!IS_P3P_TYPE(vha->hw))
  1270. return -EINVAL;
  1271. if (sscanf(buf, "%d", &val) != 1)
  1272. return -EINVAL;
  1273. vha->hw->allow_cna_fw_dump = val != 0;
  1274. return strlen(buf);
  1275. }
  1276. static ssize_t
  1277. qla2x00_pep_version_show(struct device *dev, struct device_attribute *attr,
  1278. char *buf)
  1279. {
  1280. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1281. struct qla_hw_data *ha = vha->hw;
  1282. if (!IS_QLA27XX(ha))
  1283. return scnprintf(buf, PAGE_SIZE, "\n");
  1284. return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
  1285. ha->pep_version[0], ha->pep_version[1], ha->pep_version[2]);
  1286. }
  1287. static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
  1288. static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
  1289. static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
  1290. static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
  1291. static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
  1292. static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
  1293. static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
  1294. static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
  1295. static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
  1296. static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
  1297. static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
  1298. qla2x00_zio_timer_store);
  1299. static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
  1300. qla2x00_beacon_store);
  1301. static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
  1302. qla2x00_optrom_bios_version_show, NULL);
  1303. static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
  1304. qla2x00_optrom_efi_version_show, NULL);
  1305. static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
  1306. qla2x00_optrom_fcode_version_show, NULL);
  1307. static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
  1308. NULL);
  1309. static DEVICE_ATTR(optrom_gold_fw_version, S_IRUGO,
  1310. qla2x00_optrom_gold_fw_version_show, NULL);
  1311. static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
  1312. NULL);
  1313. static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
  1314. NULL);
  1315. static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
  1316. static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
  1317. static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
  1318. NULL);
  1319. static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
  1320. static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
  1321. qla2x00_vn_port_mac_address_show, NULL);
  1322. static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
  1323. static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
  1324. static DEVICE_ATTR(thermal_temp, S_IRUGO, qla2x00_thermal_temp_show, NULL);
  1325. static DEVICE_ATTR(diag_requests, S_IRUGO, qla2x00_diag_requests_show, NULL);
  1326. static DEVICE_ATTR(diag_megabytes, S_IRUGO, qla2x00_diag_megabytes_show, NULL);
  1327. static DEVICE_ATTR(fw_dump_size, S_IRUGO, qla2x00_fw_dump_size_show, NULL);
  1328. static DEVICE_ATTR(allow_cna_fw_dump, S_IRUGO | S_IWUSR,
  1329. qla2x00_allow_cna_fw_dump_show,
  1330. qla2x00_allow_cna_fw_dump_store);
  1331. static DEVICE_ATTR(pep_version, S_IRUGO, qla2x00_pep_version_show, NULL);
  1332. struct device_attribute *qla2x00_host_attrs[] = {
  1333. &dev_attr_driver_version,
  1334. &dev_attr_fw_version,
  1335. &dev_attr_serial_num,
  1336. &dev_attr_isp_name,
  1337. &dev_attr_isp_id,
  1338. &dev_attr_model_name,
  1339. &dev_attr_model_desc,
  1340. &dev_attr_pci_info,
  1341. &dev_attr_link_state,
  1342. &dev_attr_zio,
  1343. &dev_attr_zio_timer,
  1344. &dev_attr_beacon,
  1345. &dev_attr_optrom_bios_version,
  1346. &dev_attr_optrom_efi_version,
  1347. &dev_attr_optrom_fcode_version,
  1348. &dev_attr_optrom_fw_version,
  1349. &dev_attr_84xx_fw_version,
  1350. &dev_attr_total_isp_aborts,
  1351. &dev_attr_mpi_version,
  1352. &dev_attr_phy_version,
  1353. &dev_attr_flash_block_size,
  1354. &dev_attr_vlan_id,
  1355. &dev_attr_vn_port_mac_address,
  1356. &dev_attr_fabric_param,
  1357. &dev_attr_fw_state,
  1358. &dev_attr_optrom_gold_fw_version,
  1359. &dev_attr_thermal_temp,
  1360. &dev_attr_diag_requests,
  1361. &dev_attr_diag_megabytes,
  1362. &dev_attr_fw_dump_size,
  1363. &dev_attr_allow_cna_fw_dump,
  1364. &dev_attr_pep_version,
  1365. NULL,
  1366. };
  1367. /* Host attributes. */
  1368. static void
  1369. qla2x00_get_host_port_id(struct Scsi_Host *shost)
  1370. {
  1371. scsi_qla_host_t *vha = shost_priv(shost);
  1372. fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
  1373. vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
  1374. }
  1375. static void
  1376. qla2x00_get_host_speed(struct Scsi_Host *shost)
  1377. {
  1378. struct qla_hw_data *ha = ((struct scsi_qla_host *)
  1379. (shost_priv(shost)))->hw;
  1380. u32 speed = FC_PORTSPEED_UNKNOWN;
  1381. if (IS_QLAFX00(ha)) {
  1382. qlafx00_get_host_speed(shost);
  1383. return;
  1384. }
  1385. switch (ha->link_data_rate) {
  1386. case PORT_SPEED_1GB:
  1387. speed = FC_PORTSPEED_1GBIT;
  1388. break;
  1389. case PORT_SPEED_2GB:
  1390. speed = FC_PORTSPEED_2GBIT;
  1391. break;
  1392. case PORT_SPEED_4GB:
  1393. speed = FC_PORTSPEED_4GBIT;
  1394. break;
  1395. case PORT_SPEED_8GB:
  1396. speed = FC_PORTSPEED_8GBIT;
  1397. break;
  1398. case PORT_SPEED_10GB:
  1399. speed = FC_PORTSPEED_10GBIT;
  1400. break;
  1401. case PORT_SPEED_16GB:
  1402. speed = FC_PORTSPEED_16GBIT;
  1403. break;
  1404. case PORT_SPEED_32GB:
  1405. speed = FC_PORTSPEED_32GBIT;
  1406. break;
  1407. }
  1408. fc_host_speed(shost) = speed;
  1409. }
  1410. static void
  1411. qla2x00_get_host_port_type(struct Scsi_Host *shost)
  1412. {
  1413. scsi_qla_host_t *vha = shost_priv(shost);
  1414. uint32_t port_type = FC_PORTTYPE_UNKNOWN;
  1415. if (vha->vp_idx) {
  1416. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  1417. return;
  1418. }
  1419. switch (vha->hw->current_topology) {
  1420. case ISP_CFG_NL:
  1421. port_type = FC_PORTTYPE_LPORT;
  1422. break;
  1423. case ISP_CFG_FL:
  1424. port_type = FC_PORTTYPE_NLPORT;
  1425. break;
  1426. case ISP_CFG_N:
  1427. port_type = FC_PORTTYPE_PTP;
  1428. break;
  1429. case ISP_CFG_F:
  1430. port_type = FC_PORTTYPE_NPORT;
  1431. break;
  1432. }
  1433. fc_host_port_type(shost) = port_type;
  1434. }
  1435. static void
  1436. qla2x00_get_starget_node_name(struct scsi_target *starget)
  1437. {
  1438. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1439. scsi_qla_host_t *vha = shost_priv(host);
  1440. fc_port_t *fcport;
  1441. u64 node_name = 0;
  1442. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1443. if (fcport->rport &&
  1444. starget->id == fcport->rport->scsi_target_id) {
  1445. node_name = wwn_to_u64(fcport->node_name);
  1446. break;
  1447. }
  1448. }
  1449. fc_starget_node_name(starget) = node_name;
  1450. }
  1451. static void
  1452. qla2x00_get_starget_port_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 port_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. port_name = wwn_to_u64(fcport->port_name);
  1462. break;
  1463. }
  1464. }
  1465. fc_starget_port_name(starget) = port_name;
  1466. }
  1467. static void
  1468. qla2x00_get_starget_port_id(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. uint32_t port_id = ~0U;
  1474. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1475. if (fcport->rport &&
  1476. starget->id == fcport->rport->scsi_target_id) {
  1477. port_id = fcport->d_id.b.domain << 16 |
  1478. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  1479. break;
  1480. }
  1481. }
  1482. fc_starget_port_id(starget) = port_id;
  1483. }
  1484. static void
  1485. qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  1486. {
  1487. if (timeout)
  1488. rport->dev_loss_tmo = timeout;
  1489. else
  1490. rport->dev_loss_tmo = 1;
  1491. }
  1492. static void
  1493. qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
  1494. {
  1495. struct Scsi_Host *host = rport_to_shost(rport);
  1496. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1497. unsigned long flags;
  1498. if (!fcport)
  1499. return;
  1500. /* Now that the rport has been deleted, set the fcport state to
  1501. FCS_DEVICE_DEAD */
  1502. qla2x00_set_fcport_state(fcport, FCS_DEVICE_DEAD);
  1503. /*
  1504. * Transport has effectively 'deleted' the rport, clear
  1505. * all local references.
  1506. */
  1507. spin_lock_irqsave(host->host_lock, flags);
  1508. fcport->rport = fcport->drport = NULL;
  1509. *((fc_port_t **)rport->dd_data) = NULL;
  1510. spin_unlock_irqrestore(host->host_lock, flags);
  1511. if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
  1512. return;
  1513. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1514. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1515. return;
  1516. }
  1517. }
  1518. static void
  1519. qla2x00_terminate_rport_io(struct fc_rport *rport)
  1520. {
  1521. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1522. if (!fcport)
  1523. return;
  1524. if (test_bit(UNLOADING, &fcport->vha->dpc_flags))
  1525. return;
  1526. if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
  1527. return;
  1528. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1529. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1530. return;
  1531. }
  1532. /*
  1533. * At this point all fcport's software-states are cleared. Perform any
  1534. * final cleanup of firmware resources (PCBs and XCBs).
  1535. */
  1536. if (fcport->loop_id != FC_NO_LOOP_ID) {
  1537. if (IS_FWI2_CAPABLE(fcport->vha->hw))
  1538. fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
  1539. fcport->loop_id, fcport->d_id.b.domain,
  1540. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  1541. else
  1542. qla2x00_port_logout(fcport->vha, fcport);
  1543. }
  1544. }
  1545. static int
  1546. qla2x00_issue_lip(struct Scsi_Host *shost)
  1547. {
  1548. scsi_qla_host_t *vha = shost_priv(shost);
  1549. if (IS_QLAFX00(vha->hw))
  1550. return 0;
  1551. qla2x00_loop_reset(vha);
  1552. return 0;
  1553. }
  1554. static struct fc_host_statistics *
  1555. qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
  1556. {
  1557. scsi_qla_host_t *vha = shost_priv(shost);
  1558. struct qla_hw_data *ha = vha->hw;
  1559. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  1560. int rval;
  1561. struct link_statistics *stats;
  1562. dma_addr_t stats_dma;
  1563. struct fc_host_statistics *p = &vha->fc_host_stat;
  1564. memset(p, -1, sizeof(*p));
  1565. if (IS_QLAFX00(vha->hw))
  1566. goto done;
  1567. if (test_bit(UNLOADING, &vha->dpc_flags))
  1568. goto done;
  1569. if (unlikely(pci_channel_offline(ha->pdev)))
  1570. goto done;
  1571. if (qla2x00_reset_active(vha))
  1572. goto done;
  1573. stats = dma_alloc_coherent(&ha->pdev->dev,
  1574. sizeof(*stats), &stats_dma, GFP_KERNEL);
  1575. if (!stats) {
  1576. ql_log(ql_log_warn, vha, 0x707d,
  1577. "Failed to allocate memory for stats.\n");
  1578. goto done;
  1579. }
  1580. memset(stats, 0, sizeof(*stats));
  1581. rval = QLA_FUNCTION_FAILED;
  1582. if (IS_FWI2_CAPABLE(ha)) {
  1583. rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma, 0);
  1584. } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
  1585. !ha->dpc_active) {
  1586. /* Must be in a 'READY' state for statistics retrieval. */
  1587. rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
  1588. stats, stats_dma);
  1589. }
  1590. if (rval != QLA_SUCCESS)
  1591. goto done_free;
  1592. p->link_failure_count = stats->link_fail_cnt;
  1593. p->loss_of_sync_count = stats->loss_sync_cnt;
  1594. p->loss_of_signal_count = stats->loss_sig_cnt;
  1595. p->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
  1596. p->invalid_tx_word_count = stats->inval_xmit_word_cnt;
  1597. p->invalid_crc_count = stats->inval_crc_cnt;
  1598. if (IS_FWI2_CAPABLE(ha)) {
  1599. p->lip_count = stats->lip_cnt;
  1600. p->tx_frames = stats->tx_frames;
  1601. p->rx_frames = stats->rx_frames;
  1602. p->dumped_frames = stats->discarded_frames;
  1603. p->nos_count = stats->nos_rcvd;
  1604. p->error_frames =
  1605. stats->dropped_frames + stats->discarded_frames;
  1606. p->rx_words = vha->qla_stats.input_bytes;
  1607. p->tx_words = vha->qla_stats.output_bytes;
  1608. }
  1609. p->fcp_control_requests = vha->qla_stats.control_requests;
  1610. p->fcp_input_requests = vha->qla_stats.input_requests;
  1611. p->fcp_output_requests = vha->qla_stats.output_requests;
  1612. p->fcp_input_megabytes = vha->qla_stats.input_bytes >> 20;
  1613. p->fcp_output_megabytes = vha->qla_stats.output_bytes >> 20;
  1614. p->seconds_since_last_reset =
  1615. get_jiffies_64() - vha->qla_stats.jiffies_at_last_reset;
  1616. do_div(p->seconds_since_last_reset, HZ);
  1617. done_free:
  1618. dma_free_coherent(&ha->pdev->dev, sizeof(struct link_statistics),
  1619. stats, stats_dma);
  1620. done:
  1621. return p;
  1622. }
  1623. static void
  1624. qla2x00_reset_host_stats(struct Scsi_Host *shost)
  1625. {
  1626. scsi_qla_host_t *vha = shost_priv(shost);
  1627. struct qla_hw_data *ha = vha->hw;
  1628. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  1629. struct link_statistics *stats;
  1630. dma_addr_t stats_dma;
  1631. memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
  1632. memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
  1633. vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
  1634. if (IS_FWI2_CAPABLE(ha)) {
  1635. stats = dma_alloc_coherent(&ha->pdev->dev,
  1636. sizeof(*stats), &stats_dma, GFP_KERNEL);
  1637. if (!stats) {
  1638. ql_log(ql_log_warn, vha, 0x70d7,
  1639. "Failed to allocate memory for stats.\n");
  1640. return;
  1641. }
  1642. /* reset firmware statistics */
  1643. qla24xx_get_isp_stats(base_vha, stats, stats_dma, BIT_0);
  1644. dma_free_coherent(&ha->pdev->dev, sizeof(*stats),
  1645. stats, stats_dma);
  1646. }
  1647. }
  1648. static void
  1649. qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
  1650. {
  1651. scsi_qla_host_t *vha = shost_priv(shost);
  1652. qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost),
  1653. sizeof(fc_host_symbolic_name(shost)));
  1654. }
  1655. static void
  1656. qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
  1657. {
  1658. scsi_qla_host_t *vha = shost_priv(shost);
  1659. set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
  1660. }
  1661. static void
  1662. qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
  1663. {
  1664. scsi_qla_host_t *vha = shost_priv(shost);
  1665. uint8_t node_name[WWN_SIZE] = { 0xFF, 0xFF, 0xFF, 0xFF, \
  1666. 0xFF, 0xFF, 0xFF, 0xFF};
  1667. u64 fabric_name = wwn_to_u64(node_name);
  1668. if (vha->device_flags & SWITCH_FOUND)
  1669. fabric_name = wwn_to_u64(vha->fabric_node_name);
  1670. fc_host_fabric_name(shost) = fabric_name;
  1671. }
  1672. static void
  1673. qla2x00_get_host_port_state(struct Scsi_Host *shost)
  1674. {
  1675. scsi_qla_host_t *vha = shost_priv(shost);
  1676. struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
  1677. if (!base_vha->flags.online) {
  1678. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  1679. return;
  1680. }
  1681. switch (atomic_read(&base_vha->loop_state)) {
  1682. case LOOP_UPDATE:
  1683. fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
  1684. break;
  1685. case LOOP_DOWN:
  1686. if (test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags))
  1687. fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
  1688. else
  1689. fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
  1690. break;
  1691. case LOOP_DEAD:
  1692. fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
  1693. break;
  1694. case LOOP_READY:
  1695. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  1696. break;
  1697. default:
  1698. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  1699. break;
  1700. }
  1701. }
  1702. static int
  1703. qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
  1704. {
  1705. int ret = 0;
  1706. uint8_t qos = 0;
  1707. scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
  1708. scsi_qla_host_t *vha = NULL;
  1709. struct qla_hw_data *ha = base_vha->hw;
  1710. uint16_t options = 0;
  1711. int cnt;
  1712. struct req_que *req = ha->req_q_map[0];
  1713. ret = qla24xx_vport_create_req_sanity_check(fc_vport);
  1714. if (ret) {
  1715. ql_log(ql_log_warn, vha, 0x707e,
  1716. "Vport sanity check failed, status %x\n", ret);
  1717. return (ret);
  1718. }
  1719. vha = qla24xx_create_vhost(fc_vport);
  1720. if (vha == NULL) {
  1721. ql_log(ql_log_warn, vha, 0x707f, "Vport create host failed.\n");
  1722. return FC_VPORT_FAILED;
  1723. }
  1724. if (disable) {
  1725. atomic_set(&vha->vp_state, VP_OFFLINE);
  1726. fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
  1727. } else
  1728. atomic_set(&vha->vp_state, VP_FAILED);
  1729. /* ready to create vport */
  1730. ql_log(ql_log_info, vha, 0x7080,
  1731. "VP entry id %d assigned.\n", vha->vp_idx);
  1732. /* initialized vport states */
  1733. atomic_set(&vha->loop_state, LOOP_DOWN);
  1734. vha->vp_err_state= VP_ERR_PORTDWN;
  1735. vha->vp_prev_err_state= VP_ERR_UNKWN;
  1736. /* Check if physical ha port is Up */
  1737. if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
  1738. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  1739. /* Don't retry or attempt login of this virtual port */
  1740. ql_dbg(ql_dbg_user, vha, 0x7081,
  1741. "Vport loop state is not UP.\n");
  1742. atomic_set(&vha->loop_state, LOOP_DEAD);
  1743. if (!disable)
  1744. fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
  1745. }
  1746. if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
  1747. if (ha->fw_attributes & BIT_4) {
  1748. int prot = 0, guard;
  1749. vha->flags.difdix_supported = 1;
  1750. ql_dbg(ql_dbg_user, vha, 0x7082,
  1751. "Registered for DIF/DIX type 1 and 3 protection.\n");
  1752. if (ql2xenabledif == 1)
  1753. prot = SHOST_DIX_TYPE0_PROTECTION;
  1754. scsi_host_set_prot(vha->host,
  1755. prot | SHOST_DIF_TYPE1_PROTECTION
  1756. | SHOST_DIF_TYPE2_PROTECTION
  1757. | SHOST_DIF_TYPE3_PROTECTION
  1758. | SHOST_DIX_TYPE1_PROTECTION
  1759. | SHOST_DIX_TYPE2_PROTECTION
  1760. | SHOST_DIX_TYPE3_PROTECTION);
  1761. guard = SHOST_DIX_GUARD_CRC;
  1762. if (IS_PI_IPGUARD_CAPABLE(ha) &&
  1763. (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
  1764. guard |= SHOST_DIX_GUARD_IP;
  1765. scsi_host_set_guard(vha->host, guard);
  1766. } else
  1767. vha->flags.difdix_supported = 0;
  1768. }
  1769. if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
  1770. &ha->pdev->dev)) {
  1771. ql_dbg(ql_dbg_user, vha, 0x7083,
  1772. "scsi_add_host failure for VP[%d].\n", vha->vp_idx);
  1773. goto vport_create_failed_2;
  1774. }
  1775. /* initialize attributes */
  1776. fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
  1777. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1778. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1779. fc_host_supported_classes(vha->host) =
  1780. fc_host_supported_classes(base_vha->host);
  1781. fc_host_supported_speeds(vha->host) =
  1782. fc_host_supported_speeds(base_vha->host);
  1783. qlt_vport_create(vha, ha);
  1784. qla24xx_vport_disable(fc_vport, disable);
  1785. if (ha->flags.cpu_affinity_enabled) {
  1786. req = ha->req_q_map[1];
  1787. ql_dbg(ql_dbg_multiq, vha, 0xc000,
  1788. "Request queue %p attached with "
  1789. "VP[%d], cpu affinity =%d\n",
  1790. req, vha->vp_idx, ha->flags.cpu_affinity_enabled);
  1791. goto vport_queue;
  1792. } else if (ql2xmaxqueues == 1 || !ha->npiv_info)
  1793. goto vport_queue;
  1794. /* Create a request queue in QoS mode for the vport */
  1795. for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
  1796. if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
  1797. && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
  1798. 8) == 0) {
  1799. qos = ha->npiv_info[cnt].q_qos;
  1800. break;
  1801. }
  1802. }
  1803. if (qos) {
  1804. ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, 0,
  1805. qos);
  1806. if (!ret)
  1807. ql_log(ql_log_warn, vha, 0x7084,
  1808. "Can't create request queue for VP[%d]\n",
  1809. vha->vp_idx);
  1810. else {
  1811. ql_dbg(ql_dbg_multiq, vha, 0xc001,
  1812. "Request Que:%d Q0s: %d) created for VP[%d]\n",
  1813. ret, qos, vha->vp_idx);
  1814. ql_dbg(ql_dbg_user, vha, 0x7085,
  1815. "Request Que:%d Q0s: %d) created for VP[%d]\n",
  1816. ret, qos, vha->vp_idx);
  1817. req = ha->req_q_map[ret];
  1818. }
  1819. }
  1820. vport_queue:
  1821. vha->req = req;
  1822. return 0;
  1823. vport_create_failed_2:
  1824. qla24xx_disable_vp(vha);
  1825. qla24xx_deallocate_vp_id(vha);
  1826. scsi_host_put(vha->host);
  1827. return FC_VPORT_FAILED;
  1828. }
  1829. static int
  1830. qla24xx_vport_delete(struct fc_vport *fc_vport)
  1831. {
  1832. scsi_qla_host_t *vha = fc_vport->dd_data;
  1833. struct qla_hw_data *ha = vha->hw;
  1834. uint16_t id = vha->vp_idx;
  1835. while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
  1836. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
  1837. msleep(1000);
  1838. qla24xx_disable_vp(vha);
  1839. vha->flags.delete_progress = 1;
  1840. qlt_remove_target(ha, vha);
  1841. fc_remove_host(vha->host);
  1842. scsi_remove_host(vha->host);
  1843. /* Allow timer to run to drain queued items, when removing vp */
  1844. qla24xx_deallocate_vp_id(vha);
  1845. if (vha->timer_active) {
  1846. qla2x00_vp_stop_timer(vha);
  1847. ql_dbg(ql_dbg_user, vha, 0x7086,
  1848. "Timer for the VP[%d] has stopped\n", vha->vp_idx);
  1849. }
  1850. qla2x00_free_fcports(vha);
  1851. mutex_lock(&ha->vport_lock);
  1852. ha->cur_vport_count--;
  1853. clear_bit(vha->vp_idx, ha->vp_idx_map);
  1854. mutex_unlock(&ha->vport_lock);
  1855. if (vha->req->id && !ha->flags.cpu_affinity_enabled) {
  1856. if (qla25xx_delete_req_que(vha, vha->req) != QLA_SUCCESS)
  1857. ql_log(ql_log_warn, vha, 0x7087,
  1858. "Queue delete failed.\n");
  1859. }
  1860. ql_log(ql_log_info, vha, 0x7088, "VP[%d] deleted.\n", id);
  1861. scsi_host_put(vha->host);
  1862. return 0;
  1863. }
  1864. static int
  1865. qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
  1866. {
  1867. scsi_qla_host_t *vha = fc_vport->dd_data;
  1868. if (disable)
  1869. qla24xx_disable_vp(vha);
  1870. else
  1871. qla24xx_enable_vp(vha);
  1872. return 0;
  1873. }
  1874. struct fc_function_template qla2xxx_transport_functions = {
  1875. .show_host_node_name = 1,
  1876. .show_host_port_name = 1,
  1877. .show_host_supported_classes = 1,
  1878. .show_host_supported_speeds = 1,
  1879. .get_host_port_id = qla2x00_get_host_port_id,
  1880. .show_host_port_id = 1,
  1881. .get_host_speed = qla2x00_get_host_speed,
  1882. .show_host_speed = 1,
  1883. .get_host_port_type = qla2x00_get_host_port_type,
  1884. .show_host_port_type = 1,
  1885. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1886. .show_host_symbolic_name = 1,
  1887. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1888. .show_host_system_hostname = 1,
  1889. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1890. .show_host_fabric_name = 1,
  1891. .get_host_port_state = qla2x00_get_host_port_state,
  1892. .show_host_port_state = 1,
  1893. .dd_fcrport_size = sizeof(struct fc_port *),
  1894. .show_rport_supported_classes = 1,
  1895. .get_starget_node_name = qla2x00_get_starget_node_name,
  1896. .show_starget_node_name = 1,
  1897. .get_starget_port_name = qla2x00_get_starget_port_name,
  1898. .show_starget_port_name = 1,
  1899. .get_starget_port_id = qla2x00_get_starget_port_id,
  1900. .show_starget_port_id = 1,
  1901. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1902. .show_rport_dev_loss_tmo = 1,
  1903. .issue_fc_host_lip = qla2x00_issue_lip,
  1904. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  1905. .terminate_rport_io = qla2x00_terminate_rport_io,
  1906. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1907. .reset_fc_host_stats = qla2x00_reset_host_stats,
  1908. .vport_create = qla24xx_vport_create,
  1909. .vport_disable = qla24xx_vport_disable,
  1910. .vport_delete = qla24xx_vport_delete,
  1911. .bsg_request = qla24xx_bsg_request,
  1912. .bsg_timeout = qla24xx_bsg_timeout,
  1913. };
  1914. struct fc_function_template qla2xxx_transport_vport_functions = {
  1915. .show_host_node_name = 1,
  1916. .show_host_port_name = 1,
  1917. .show_host_supported_classes = 1,
  1918. .get_host_port_id = qla2x00_get_host_port_id,
  1919. .show_host_port_id = 1,
  1920. .get_host_speed = qla2x00_get_host_speed,
  1921. .show_host_speed = 1,
  1922. .get_host_port_type = qla2x00_get_host_port_type,
  1923. .show_host_port_type = 1,
  1924. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1925. .show_host_symbolic_name = 1,
  1926. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1927. .show_host_system_hostname = 1,
  1928. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1929. .show_host_fabric_name = 1,
  1930. .get_host_port_state = qla2x00_get_host_port_state,
  1931. .show_host_port_state = 1,
  1932. .dd_fcrport_size = sizeof(struct fc_port *),
  1933. .show_rport_supported_classes = 1,
  1934. .get_starget_node_name = qla2x00_get_starget_node_name,
  1935. .show_starget_node_name = 1,
  1936. .get_starget_port_name = qla2x00_get_starget_port_name,
  1937. .show_starget_port_name = 1,
  1938. .get_starget_port_id = qla2x00_get_starget_port_id,
  1939. .show_starget_port_id = 1,
  1940. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1941. .show_rport_dev_loss_tmo = 1,
  1942. .issue_fc_host_lip = qla2x00_issue_lip,
  1943. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  1944. .terminate_rport_io = qla2x00_terminate_rport_io,
  1945. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1946. .reset_fc_host_stats = qla2x00_reset_host_stats,
  1947. .bsg_request = qla24xx_bsg_request,
  1948. .bsg_timeout = qla24xx_bsg_timeout,
  1949. };
  1950. void
  1951. qla2x00_init_host_attr(scsi_qla_host_t *vha)
  1952. {
  1953. struct qla_hw_data *ha = vha->hw;
  1954. u32 speed = FC_PORTSPEED_UNKNOWN;
  1955. fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
  1956. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1957. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1958. fc_host_supported_classes(vha->host) = ha->tgt.enable_class_2 ?
  1959. (FC_COS_CLASS2|FC_COS_CLASS3) : FC_COS_CLASS3;
  1960. fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
  1961. fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
  1962. if (IS_CNA_CAPABLE(ha))
  1963. speed = FC_PORTSPEED_10GBIT;
  1964. else if (IS_QLA2031(ha))
  1965. speed = FC_PORTSPEED_16GBIT | FC_PORTSPEED_8GBIT |
  1966. FC_PORTSPEED_4GBIT;
  1967. else if (IS_QLA25XX(ha))
  1968. speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
  1969. FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1970. else if (IS_QLA24XX_TYPE(ha))
  1971. speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
  1972. FC_PORTSPEED_1GBIT;
  1973. else if (IS_QLA23XX(ha))
  1974. speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1975. else if (IS_QLAFX00(ha))
  1976. speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
  1977. FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1978. else if (IS_QLA27XX(ha))
  1979. speed = FC_PORTSPEED_32GBIT | FC_PORTSPEED_16GBIT |
  1980. FC_PORTSPEED_8GBIT;
  1981. else
  1982. speed = FC_PORTSPEED_1GBIT;
  1983. fc_host_supported_speeds(vha->host) = speed;
  1984. }