zfcp_fsf.c 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518
  1. /*
  2. * zfcp device driver
  3. *
  4. * Implementation of FSF commands.
  5. *
  6. * Copyright IBM Corporation 2002, 2008
  7. */
  8. #include "zfcp_ext.h"
  9. static void zfcp_fsf_request_timeout_handler(unsigned long data)
  10. {
  11. struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
  12. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, 62,
  13. NULL);
  14. }
  15. static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
  16. unsigned long timeout)
  17. {
  18. fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
  19. fsf_req->timer.data = (unsigned long) fsf_req->adapter;
  20. fsf_req->timer.expires = jiffies + timeout;
  21. add_timer(&fsf_req->timer);
  22. }
  23. static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
  24. {
  25. BUG_ON(!fsf_req->erp_action);
  26. fsf_req->timer.function = zfcp_erp_timeout_handler;
  27. fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
  28. fsf_req->timer.expires = jiffies + 30 * HZ;
  29. add_timer(&fsf_req->timer);
  30. }
  31. /* association between FSF command and FSF QTCB type */
  32. static u32 fsf_qtcb_type[] = {
  33. [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
  34. [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
  35. [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
  36. [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
  37. [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
  38. [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
  39. [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
  40. [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
  41. [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
  42. [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
  43. [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
  44. [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
  45. [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
  46. };
  47. static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
  48. {
  49. u16 subtable = table >> 16;
  50. u16 rule = table & 0xffff;
  51. const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
  52. if (subtable && subtable < ARRAY_SIZE(act_type))
  53. dev_warn(&adapter->ccw_device->dev,
  54. "Access denied according to ACT rule type %s, "
  55. "rule %d\n", act_type[subtable], rule);
  56. }
  57. static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
  58. struct zfcp_port *port)
  59. {
  60. struct fsf_qtcb_header *header = &req->qtcb->header;
  61. dev_warn(&req->adapter->ccw_device->dev,
  62. "Access denied to port 0x%016Lx\n",
  63. (unsigned long long)port->wwpn);
  64. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
  65. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
  66. zfcp_erp_port_access_denied(port, 55, req);
  67. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  68. }
  69. static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
  70. struct zfcp_unit *unit)
  71. {
  72. struct fsf_qtcb_header *header = &req->qtcb->header;
  73. dev_warn(&req->adapter->ccw_device->dev,
  74. "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
  75. (unsigned long long)unit->fcp_lun,
  76. (unsigned long long)unit->port->wwpn);
  77. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
  78. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
  79. zfcp_erp_unit_access_denied(unit, 59, req);
  80. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  81. }
  82. static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
  83. {
  84. dev_err(&req->adapter->ccw_device->dev, "FCP device not "
  85. "operational because of an unsupported FC class\n");
  86. zfcp_erp_adapter_shutdown(req->adapter, 0, 123, req);
  87. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  88. }
  89. /**
  90. * zfcp_fsf_req_free - free memory used by fsf request
  91. * @fsf_req: pointer to struct zfcp_fsf_req
  92. */
  93. void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
  94. {
  95. if (likely(req->pool)) {
  96. mempool_free(req, req->pool);
  97. return;
  98. }
  99. if (req->qtcb) {
  100. kmem_cache_free(zfcp_data.fsf_req_qtcb_cache, req);
  101. return;
  102. }
  103. }
  104. /**
  105. * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
  106. * @adapter: pointer to struct zfcp_adapter
  107. *
  108. * Never ever call this without shutting down the adapter first.
  109. * Otherwise the adapter would continue using and corrupting s390 storage.
  110. * Included BUG_ON() call to ensure this is done.
  111. * ERP is supposed to be the only user of this function.
  112. */
  113. void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
  114. {
  115. struct zfcp_fsf_req *req, *tmp;
  116. unsigned long flags;
  117. LIST_HEAD(remove_queue);
  118. unsigned int i;
  119. BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
  120. spin_lock_irqsave(&adapter->req_list_lock, flags);
  121. for (i = 0; i < REQUEST_LIST_SIZE; i++)
  122. list_splice_init(&adapter->req_list[i], &remove_queue);
  123. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  124. list_for_each_entry_safe(req, tmp, &remove_queue, list) {
  125. list_del(&req->list);
  126. req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
  127. zfcp_fsf_req_complete(req);
  128. }
  129. }
  130. static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
  131. {
  132. struct fsf_status_read_buffer *sr_buf = req->data;
  133. struct zfcp_adapter *adapter = req->adapter;
  134. struct zfcp_port *port;
  135. int d_id = sr_buf->d_id & ZFCP_DID_MASK;
  136. unsigned long flags;
  137. read_lock_irqsave(&zfcp_data.config_lock, flags);
  138. list_for_each_entry(port, &adapter->port_list_head, list)
  139. if (port->d_id == d_id) {
  140. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  141. switch (sr_buf->status_subtype) {
  142. case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
  143. zfcp_erp_port_reopen(port, 0, 101, req);
  144. break;
  145. case FSF_STATUS_READ_SUB_ERROR_PORT:
  146. zfcp_erp_port_shutdown(port, 0, 122, req);
  147. break;
  148. }
  149. return;
  150. }
  151. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  152. }
  153. static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, u8 id,
  154. struct fsf_link_down_info *link_down)
  155. {
  156. struct zfcp_adapter *adapter = req->adapter;
  157. if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
  158. return;
  159. atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
  160. if (!link_down)
  161. goto out;
  162. switch (link_down->error_code) {
  163. case FSF_PSQ_LINK_NO_LIGHT:
  164. dev_warn(&req->adapter->ccw_device->dev,
  165. "There is no light signal from the local "
  166. "fibre channel cable\n");
  167. break;
  168. case FSF_PSQ_LINK_WRAP_PLUG:
  169. dev_warn(&req->adapter->ccw_device->dev,
  170. "There is a wrap plug instead of a fibre "
  171. "channel cable\n");
  172. break;
  173. case FSF_PSQ_LINK_NO_FCP:
  174. dev_warn(&req->adapter->ccw_device->dev,
  175. "The adjacent fibre channel node does not "
  176. "support FCP\n");
  177. break;
  178. case FSF_PSQ_LINK_FIRMWARE_UPDATE:
  179. dev_warn(&req->adapter->ccw_device->dev,
  180. "The FCP device is suspended because of a "
  181. "firmware update\n");
  182. break;
  183. case FSF_PSQ_LINK_INVALID_WWPN:
  184. dev_warn(&req->adapter->ccw_device->dev,
  185. "The FCP device detected a WWPN that is "
  186. "duplicate or not valid\n");
  187. break;
  188. case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
  189. dev_warn(&req->adapter->ccw_device->dev,
  190. "The fibre channel fabric does not support NPIV\n");
  191. break;
  192. case FSF_PSQ_LINK_NO_FCP_RESOURCES:
  193. dev_warn(&req->adapter->ccw_device->dev,
  194. "The FCP adapter cannot support more NPIV ports\n");
  195. break;
  196. case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
  197. dev_warn(&req->adapter->ccw_device->dev,
  198. "The adjacent switch cannot support "
  199. "more NPIV ports\n");
  200. break;
  201. case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
  202. dev_warn(&req->adapter->ccw_device->dev,
  203. "The FCP adapter could not log in to the "
  204. "fibre channel fabric\n");
  205. break;
  206. case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
  207. dev_warn(&req->adapter->ccw_device->dev,
  208. "The WWPN assignment file on the FCP adapter "
  209. "has been damaged\n");
  210. break;
  211. case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
  212. dev_warn(&req->adapter->ccw_device->dev,
  213. "The mode table on the FCP adapter "
  214. "has been damaged\n");
  215. break;
  216. case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
  217. dev_warn(&req->adapter->ccw_device->dev,
  218. "All NPIV ports on the FCP adapter have "
  219. "been assigned\n");
  220. break;
  221. default:
  222. dev_warn(&req->adapter->ccw_device->dev,
  223. "The link between the FCP adapter and "
  224. "the FC fabric is down\n");
  225. }
  226. out:
  227. zfcp_erp_adapter_failed(adapter, id, req);
  228. }
  229. static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
  230. {
  231. struct fsf_status_read_buffer *sr_buf = req->data;
  232. struct fsf_link_down_info *ldi =
  233. (struct fsf_link_down_info *) &sr_buf->payload;
  234. switch (sr_buf->status_subtype) {
  235. case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
  236. zfcp_fsf_link_down_info_eval(req, 38, ldi);
  237. break;
  238. case FSF_STATUS_READ_SUB_FDISC_FAILED:
  239. zfcp_fsf_link_down_info_eval(req, 39, ldi);
  240. break;
  241. case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
  242. zfcp_fsf_link_down_info_eval(req, 40, NULL);
  243. };
  244. }
  245. static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
  246. {
  247. struct zfcp_adapter *adapter = req->adapter;
  248. struct fsf_status_read_buffer *sr_buf = req->data;
  249. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  250. zfcp_hba_dbf_event_fsf_unsol("dism", adapter, sr_buf);
  251. mempool_free(sr_buf, adapter->pool.data_status_read);
  252. zfcp_fsf_req_free(req);
  253. return;
  254. }
  255. zfcp_hba_dbf_event_fsf_unsol("read", adapter, sr_buf);
  256. switch (sr_buf->status_type) {
  257. case FSF_STATUS_READ_PORT_CLOSED:
  258. zfcp_fsf_status_read_port_closed(req);
  259. break;
  260. case FSF_STATUS_READ_INCOMING_ELS:
  261. zfcp_fc_incoming_els(req);
  262. break;
  263. case FSF_STATUS_READ_SENSE_DATA_AVAIL:
  264. break;
  265. case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
  266. dev_warn(&adapter->ccw_device->dev,
  267. "The error threshold for checksum statistics "
  268. "has been exceeded\n");
  269. zfcp_hba_dbf_event_berr(adapter, req);
  270. break;
  271. case FSF_STATUS_READ_LINK_DOWN:
  272. zfcp_fsf_status_read_link_down(req);
  273. break;
  274. case FSF_STATUS_READ_LINK_UP:
  275. dev_info(&adapter->ccw_device->dev,
  276. "The local link has been restored\n");
  277. /* All ports should be marked as ready to run again */
  278. zfcp_erp_modify_adapter_status(adapter, 30, NULL,
  279. ZFCP_STATUS_COMMON_RUNNING,
  280. ZFCP_SET);
  281. zfcp_erp_adapter_reopen(adapter,
  282. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  283. ZFCP_STATUS_COMMON_ERP_FAILED,
  284. 102, req);
  285. break;
  286. case FSF_STATUS_READ_NOTIFICATION_LOST:
  287. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
  288. zfcp_erp_adapter_access_changed(adapter, 135, req);
  289. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
  290. schedule_work(&adapter->scan_work);
  291. break;
  292. case FSF_STATUS_READ_CFDC_UPDATED:
  293. zfcp_erp_adapter_access_changed(adapter, 136, req);
  294. break;
  295. case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
  296. adapter->adapter_features = sr_buf->payload.word[0];
  297. break;
  298. }
  299. mempool_free(sr_buf, adapter->pool.data_status_read);
  300. zfcp_fsf_req_free(req);
  301. atomic_inc(&adapter->stat_miss);
  302. queue_work(zfcp_data.work_queue, &adapter->stat_work);
  303. }
  304. static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
  305. {
  306. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  307. case FSF_SQ_FCP_RSP_AVAILABLE:
  308. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  309. case FSF_SQ_NO_RETRY_POSSIBLE:
  310. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  311. return;
  312. case FSF_SQ_COMMAND_ABORTED:
  313. req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
  314. break;
  315. case FSF_SQ_NO_RECOM:
  316. dev_err(&req->adapter->ccw_device->dev,
  317. "The FCP adapter reported a problem "
  318. "that cannot be recovered\n");
  319. zfcp_erp_adapter_shutdown(req->adapter, 0, 121, req);
  320. break;
  321. }
  322. /* all non-return stats set FSFREQ_ERROR*/
  323. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  324. }
  325. static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
  326. {
  327. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  328. return;
  329. switch (req->qtcb->header.fsf_status) {
  330. case FSF_UNKNOWN_COMMAND:
  331. dev_err(&req->adapter->ccw_device->dev,
  332. "The FCP adapter does not recognize the command 0x%x\n",
  333. req->qtcb->header.fsf_command);
  334. zfcp_erp_adapter_shutdown(req->adapter, 0, 120, req);
  335. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  336. break;
  337. case FSF_ADAPTER_STATUS_AVAILABLE:
  338. zfcp_fsf_fsfstatus_qual_eval(req);
  339. break;
  340. }
  341. }
  342. static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
  343. {
  344. struct zfcp_adapter *adapter = req->adapter;
  345. struct fsf_qtcb *qtcb = req->qtcb;
  346. union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
  347. zfcp_hba_dbf_event_fsf_response(req);
  348. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  349. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  350. ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
  351. return;
  352. }
  353. switch (qtcb->prefix.prot_status) {
  354. case FSF_PROT_GOOD:
  355. case FSF_PROT_FSF_STATUS_PRESENTED:
  356. return;
  357. case FSF_PROT_QTCB_VERSION_ERROR:
  358. dev_err(&adapter->ccw_device->dev,
  359. "QTCB version 0x%x not supported by FCP adapter "
  360. "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
  361. psq->word[0], psq->word[1]);
  362. zfcp_erp_adapter_shutdown(adapter, 0, 117, req);
  363. break;
  364. case FSF_PROT_ERROR_STATE:
  365. case FSF_PROT_SEQ_NUMB_ERROR:
  366. zfcp_erp_adapter_reopen(adapter, 0, 98, req);
  367. req->status |= ZFCP_STATUS_FSFREQ_RETRY;
  368. break;
  369. case FSF_PROT_UNSUPP_QTCB_TYPE:
  370. dev_err(&adapter->ccw_device->dev,
  371. "The QTCB type is not supported by the FCP adapter\n");
  372. zfcp_erp_adapter_shutdown(adapter, 0, 118, req);
  373. break;
  374. case FSF_PROT_HOST_CONNECTION_INITIALIZING:
  375. atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  376. &adapter->status);
  377. break;
  378. case FSF_PROT_DUPLICATE_REQUEST_ID:
  379. dev_err(&adapter->ccw_device->dev,
  380. "0x%Lx is an ambiguous request identifier\n",
  381. (unsigned long long)qtcb->bottom.support.req_handle);
  382. zfcp_erp_adapter_shutdown(adapter, 0, 78, req);
  383. break;
  384. case FSF_PROT_LINK_DOWN:
  385. zfcp_fsf_link_down_info_eval(req, 37, &psq->link_down_info);
  386. /* FIXME: reopening adapter now? better wait for link up */
  387. zfcp_erp_adapter_reopen(adapter, 0, 79, req);
  388. break;
  389. case FSF_PROT_REEST_QUEUE:
  390. /* All ports should be marked as ready to run again */
  391. zfcp_erp_modify_adapter_status(adapter, 28, NULL,
  392. ZFCP_STATUS_COMMON_RUNNING,
  393. ZFCP_SET);
  394. zfcp_erp_adapter_reopen(adapter,
  395. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  396. ZFCP_STATUS_COMMON_ERP_FAILED, 99, req);
  397. break;
  398. default:
  399. dev_err(&adapter->ccw_device->dev,
  400. "0x%x is not a valid transfer protocol status\n",
  401. qtcb->prefix.prot_status);
  402. zfcp_erp_adapter_shutdown(adapter, 0, 119, req);
  403. }
  404. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  405. }
  406. /**
  407. * zfcp_fsf_req_complete - process completion of a FSF request
  408. * @fsf_req: The FSF request that has been completed.
  409. *
  410. * When a request has been completed either from the FCP adapter,
  411. * or it has been dismissed due to a queue shutdown, this function
  412. * is called to process the completion status and trigger further
  413. * events related to the FSF request.
  414. */
  415. void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
  416. {
  417. if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
  418. zfcp_fsf_status_read_handler(req);
  419. return;
  420. }
  421. del_timer(&req->timer);
  422. zfcp_fsf_protstatus_eval(req);
  423. zfcp_fsf_fsfstatus_eval(req);
  424. req->handler(req);
  425. if (req->erp_action)
  426. zfcp_erp_notify(req->erp_action, 0);
  427. req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
  428. if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
  429. zfcp_fsf_req_free(req);
  430. else
  431. /* notify initiator waiting for the requests completion */
  432. /*
  433. * FIXME: Race! We must not access fsf_req here as it might have been
  434. * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
  435. * flag. It's an improbable case. But, we have the same paranoia for
  436. * the cleanup flag already.
  437. * Might better be handled using complete()?
  438. * (setting the flag and doing wakeup ought to be atomic
  439. * with regard to checking the flag as long as waitqueue is
  440. * part of the to be released structure)
  441. */
  442. wake_up(&req->completion_wq);
  443. }
  444. static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
  445. {
  446. struct fsf_qtcb_bottom_config *bottom;
  447. struct zfcp_adapter *adapter = req->adapter;
  448. struct Scsi_Host *shost = adapter->scsi_host;
  449. bottom = &req->qtcb->bottom.config;
  450. if (req->data)
  451. memcpy(req->data, bottom, sizeof(*bottom));
  452. fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
  453. fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
  454. fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
  455. fc_host_speed(shost) = bottom->fc_link_speed;
  456. fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
  457. adapter->hydra_version = bottom->adapter_type;
  458. adapter->timer_ticks = bottom->timer_interval;
  459. if (fc_host_permanent_port_name(shost) == -1)
  460. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  461. switch (bottom->fc_topology) {
  462. case FSF_TOPO_P2P:
  463. adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
  464. adapter->peer_wwpn = bottom->plogi_payload.wwpn;
  465. adapter->peer_wwnn = bottom->plogi_payload.wwnn;
  466. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  467. break;
  468. case FSF_TOPO_FABRIC:
  469. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  470. break;
  471. case FSF_TOPO_AL:
  472. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  473. default:
  474. dev_err(&adapter->ccw_device->dev,
  475. "Unknown or unsupported arbitrated loop "
  476. "fibre channel topology detected\n");
  477. zfcp_erp_adapter_shutdown(adapter, 0, 127, req);
  478. return -EIO;
  479. }
  480. return 0;
  481. }
  482. static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
  483. {
  484. struct zfcp_adapter *adapter = req->adapter;
  485. struct fsf_qtcb *qtcb = req->qtcb;
  486. struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
  487. struct Scsi_Host *shost = adapter->scsi_host;
  488. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  489. return;
  490. adapter->fsf_lic_version = bottom->lic_version;
  491. adapter->adapter_features = bottom->adapter_features;
  492. adapter->connection_features = bottom->connection_features;
  493. adapter->peer_wwpn = 0;
  494. adapter->peer_wwnn = 0;
  495. adapter->peer_d_id = 0;
  496. switch (qtcb->header.fsf_status) {
  497. case FSF_GOOD:
  498. if (zfcp_fsf_exchange_config_evaluate(req))
  499. return;
  500. if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
  501. dev_err(&adapter->ccw_device->dev,
  502. "FCP adapter maximum QTCB size (%d bytes) "
  503. "is too small\n",
  504. bottom->max_qtcb_size);
  505. zfcp_erp_adapter_shutdown(adapter, 0, 129, req);
  506. return;
  507. }
  508. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  509. &adapter->status);
  510. break;
  511. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  512. fc_host_node_name(shost) = 0;
  513. fc_host_port_name(shost) = 0;
  514. fc_host_port_id(shost) = 0;
  515. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  516. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  517. adapter->hydra_version = 0;
  518. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  519. &adapter->status);
  520. zfcp_fsf_link_down_info_eval(req, 42,
  521. &qtcb->header.fsf_status_qual.link_down_info);
  522. break;
  523. default:
  524. zfcp_erp_adapter_shutdown(adapter, 0, 130, req);
  525. return;
  526. }
  527. if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
  528. adapter->hardware_version = bottom->hardware_version;
  529. memcpy(fc_host_serial_number(shost), bottom->serial_number,
  530. min(FC_SERIAL_NUMBER_SIZE, 17));
  531. EBCASC(fc_host_serial_number(shost),
  532. min(FC_SERIAL_NUMBER_SIZE, 17));
  533. }
  534. if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
  535. dev_err(&adapter->ccw_device->dev,
  536. "The FCP adapter only supports newer "
  537. "control block versions\n");
  538. zfcp_erp_adapter_shutdown(adapter, 0, 125, req);
  539. return;
  540. }
  541. if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
  542. dev_err(&adapter->ccw_device->dev,
  543. "The FCP adapter only supports older "
  544. "control block versions\n");
  545. zfcp_erp_adapter_shutdown(adapter, 0, 126, req);
  546. }
  547. }
  548. static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
  549. {
  550. struct zfcp_adapter *adapter = req->adapter;
  551. struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
  552. struct Scsi_Host *shost = adapter->scsi_host;
  553. if (req->data)
  554. memcpy(req->data, bottom, sizeof(*bottom));
  555. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
  556. fc_host_permanent_port_name(shost) = bottom->wwpn;
  557. else
  558. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  559. fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
  560. fc_host_supported_speeds(shost) = bottom->supported_speed;
  561. }
  562. static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
  563. {
  564. struct fsf_qtcb *qtcb = req->qtcb;
  565. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  566. return;
  567. switch (qtcb->header.fsf_status) {
  568. case FSF_GOOD:
  569. zfcp_fsf_exchange_port_evaluate(req);
  570. break;
  571. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  572. zfcp_fsf_exchange_port_evaluate(req);
  573. zfcp_fsf_link_down_info_eval(req, 43,
  574. &qtcb->header.fsf_status_qual.link_down_info);
  575. break;
  576. }
  577. }
  578. static int zfcp_fsf_sbal_check(struct zfcp_adapter *adapter)
  579. {
  580. struct zfcp_qdio_queue *req_q = &adapter->req_q;
  581. spin_lock_bh(&adapter->req_q_lock);
  582. if (atomic_read(&req_q->count))
  583. return 1;
  584. spin_unlock_bh(&adapter->req_q_lock);
  585. return 0;
  586. }
  587. static int zfcp_fsf_sbal_available(struct zfcp_adapter *adapter)
  588. {
  589. unsigned int count = atomic_read(&adapter->req_q.count);
  590. if (!count)
  591. atomic_inc(&adapter->qdio_outb_full);
  592. return count > 0;
  593. }
  594. static int zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter)
  595. {
  596. long ret;
  597. spin_unlock_bh(&adapter->req_q_lock);
  598. ret = wait_event_interruptible_timeout(adapter->request_wq,
  599. zfcp_fsf_sbal_check(adapter), 5 * HZ);
  600. if (ret > 0)
  601. return 0;
  602. if (!ret)
  603. atomic_inc(&adapter->qdio_outb_full);
  604. spin_lock_bh(&adapter->req_q_lock);
  605. return -EIO;
  606. }
  607. static struct zfcp_fsf_req *zfcp_fsf_alloc_noqtcb(mempool_t *pool)
  608. {
  609. struct zfcp_fsf_req *req;
  610. req = mempool_alloc(pool, GFP_ATOMIC);
  611. if (!req)
  612. return NULL;
  613. memset(req, 0, sizeof(*req));
  614. return req;
  615. }
  616. static struct zfcp_fsf_req *zfcp_fsf_alloc_qtcb(mempool_t *pool)
  617. {
  618. struct zfcp_fsf_req_qtcb *qtcb;
  619. if (likely(pool))
  620. qtcb = mempool_alloc(pool, GFP_ATOMIC);
  621. else
  622. qtcb = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache,
  623. GFP_ATOMIC);
  624. if (unlikely(!qtcb))
  625. return NULL;
  626. memset(qtcb, 0, sizeof(*qtcb));
  627. qtcb->fsf_req.qtcb = &qtcb->qtcb;
  628. qtcb->fsf_req.pool = pool;
  629. return &qtcb->fsf_req;
  630. }
  631. static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_adapter *adapter,
  632. u32 fsf_cmd, int req_flags,
  633. mempool_t *pool)
  634. {
  635. struct qdio_buffer_element *sbale;
  636. struct zfcp_fsf_req *req;
  637. struct zfcp_qdio_queue *req_q = &adapter->req_q;
  638. if (req_flags & ZFCP_REQ_NO_QTCB)
  639. req = zfcp_fsf_alloc_noqtcb(pool);
  640. else
  641. req = zfcp_fsf_alloc_qtcb(pool);
  642. if (unlikely(!req))
  643. return ERR_PTR(-EIO);
  644. if (adapter->req_no == 0)
  645. adapter->req_no++;
  646. INIT_LIST_HEAD(&req->list);
  647. init_timer(&req->timer);
  648. init_waitqueue_head(&req->completion_wq);
  649. req->adapter = adapter;
  650. req->fsf_command = fsf_cmd;
  651. req->req_id = adapter->req_no++;
  652. req->sbal_number = 1;
  653. req->sbal_first = req_q->first;
  654. req->sbal_last = req_q->first;
  655. req->sbale_curr = 1;
  656. sbale = zfcp_qdio_sbale_req(req);
  657. sbale[0].addr = (void *) req->req_id;
  658. sbale[0].flags |= SBAL_FLAGS0_COMMAND;
  659. if (likely(req->qtcb)) {
  660. req->qtcb->prefix.req_seq_no = req->adapter->fsf_req_seq_no;
  661. req->qtcb->prefix.req_id = req->req_id;
  662. req->qtcb->prefix.ulp_info = 26;
  663. req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
  664. req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
  665. req->qtcb->header.req_handle = req->req_id;
  666. req->qtcb->header.fsf_command = req->fsf_command;
  667. req->seq_no = adapter->fsf_req_seq_no;
  668. req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  669. sbale[1].addr = (void *) req->qtcb;
  670. sbale[1].length = sizeof(struct fsf_qtcb);
  671. }
  672. if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
  673. zfcp_fsf_req_free(req);
  674. return ERR_PTR(-EIO);
  675. }
  676. if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP))
  677. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  678. return req;
  679. }
  680. static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
  681. {
  682. struct zfcp_adapter *adapter = req->adapter;
  683. struct zfcp_qdio_queue *req_q = &adapter->req_q;
  684. int idx;
  685. /* put allocated FSF request into hash table */
  686. spin_lock(&adapter->req_list_lock);
  687. idx = zfcp_reqlist_hash(req->req_id);
  688. list_add_tail(&req->list, &adapter->req_list[idx]);
  689. spin_unlock(&adapter->req_list_lock);
  690. req->issued = get_clock();
  691. if (zfcp_qdio_send(req)) {
  692. /* Queues are down..... */
  693. del_timer(&req->timer);
  694. spin_lock(&adapter->req_list_lock);
  695. zfcp_reqlist_remove(adapter, req);
  696. spin_unlock(&adapter->req_list_lock);
  697. /* undo changes in request queue made for this request */
  698. atomic_add(req->sbal_number, &req_q->count);
  699. req_q->first -= req->sbal_number;
  700. req_q->first += QDIO_MAX_BUFFERS_PER_Q;
  701. req_q->first %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
  702. zfcp_erp_adapter_reopen(adapter, 0, 116, req);
  703. return -EIO;
  704. }
  705. /* Don't increase for unsolicited status */
  706. if (req->qtcb)
  707. adapter->fsf_req_seq_no++;
  708. return 0;
  709. }
  710. /**
  711. * zfcp_fsf_status_read - send status read request
  712. * @adapter: pointer to struct zfcp_adapter
  713. * @req_flags: request flags
  714. * Returns: 0 on success, ERROR otherwise
  715. */
  716. int zfcp_fsf_status_read(struct zfcp_adapter *adapter)
  717. {
  718. struct zfcp_fsf_req *req;
  719. struct fsf_status_read_buffer *sr_buf;
  720. struct qdio_buffer_element *sbale;
  721. int retval = -EIO;
  722. spin_lock_bh(&adapter->req_q_lock);
  723. if (zfcp_fsf_req_sbal_get(adapter))
  724. goto out;
  725. req = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
  726. ZFCP_REQ_NO_QTCB,
  727. adapter->pool.fsf_req_status_read);
  728. if (IS_ERR(req)) {
  729. retval = PTR_ERR(req);
  730. goto out;
  731. }
  732. sbale = zfcp_qdio_sbale_req(req);
  733. sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
  734. sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
  735. req->sbale_curr = 2;
  736. sr_buf = mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
  737. if (!sr_buf) {
  738. retval = -ENOMEM;
  739. goto failed_buf;
  740. }
  741. memset(sr_buf, 0, sizeof(*sr_buf));
  742. req->data = sr_buf;
  743. sbale = zfcp_qdio_sbale_curr(req);
  744. sbale->addr = (void *) sr_buf;
  745. sbale->length = sizeof(*sr_buf);
  746. retval = zfcp_fsf_req_send(req);
  747. if (retval)
  748. goto failed_req_send;
  749. goto out;
  750. failed_req_send:
  751. mempool_free(sr_buf, adapter->pool.data_status_read);
  752. failed_buf:
  753. zfcp_fsf_req_free(req);
  754. zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
  755. out:
  756. spin_unlock_bh(&adapter->req_q_lock);
  757. return retval;
  758. }
  759. static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
  760. {
  761. struct zfcp_unit *unit = req->data;
  762. union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
  763. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  764. return;
  765. switch (req->qtcb->header.fsf_status) {
  766. case FSF_PORT_HANDLE_NOT_VALID:
  767. if (fsq->word[0] == fsq->word[1]) {
  768. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 104,
  769. req);
  770. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  771. }
  772. break;
  773. case FSF_LUN_HANDLE_NOT_VALID:
  774. if (fsq->word[0] == fsq->word[1]) {
  775. zfcp_erp_port_reopen(unit->port, 0, 105, req);
  776. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  777. }
  778. break;
  779. case FSF_FCP_COMMAND_DOES_NOT_EXIST:
  780. req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
  781. break;
  782. case FSF_PORT_BOXED:
  783. zfcp_erp_port_boxed(unit->port, 47, req);
  784. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  785. ZFCP_STATUS_FSFREQ_RETRY;
  786. break;
  787. case FSF_LUN_BOXED:
  788. zfcp_erp_unit_boxed(unit, 48, req);
  789. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  790. ZFCP_STATUS_FSFREQ_RETRY;
  791. break;
  792. case FSF_ADAPTER_STATUS_AVAILABLE:
  793. switch (fsq->word[0]) {
  794. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  795. zfcp_test_link(unit->port);
  796. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  797. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  798. break;
  799. }
  800. break;
  801. case FSF_GOOD:
  802. req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
  803. break;
  804. }
  805. }
  806. /**
  807. * zfcp_fsf_abort_fcp_command - abort running SCSI command
  808. * @old_req_id: unsigned long
  809. * @adapter: pointer to struct zfcp_adapter
  810. * @unit: pointer to struct zfcp_unit
  811. * @req_flags: integer specifying the request flags
  812. * Returns: pointer to struct zfcp_fsf_req
  813. *
  814. * FIXME(design): should be watched by a timeout !!!
  815. */
  816. struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
  817. struct zfcp_adapter *adapter,
  818. struct zfcp_unit *unit,
  819. int req_flags)
  820. {
  821. struct qdio_buffer_element *sbale;
  822. struct zfcp_fsf_req *req = NULL;
  823. spin_lock(&adapter->req_q_lock);
  824. if (!zfcp_fsf_sbal_available(adapter))
  825. goto out;
  826. req = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
  827. req_flags, adapter->pool.fsf_req_abort);
  828. if (IS_ERR(req))
  829. goto out;
  830. if (unlikely(!(atomic_read(&unit->status) &
  831. ZFCP_STATUS_COMMON_UNBLOCKED)))
  832. goto out_error_free;
  833. sbale = zfcp_qdio_sbale_req(req);
  834. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  835. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  836. req->data = unit;
  837. req->handler = zfcp_fsf_abort_fcp_command_handler;
  838. req->qtcb->header.lun_handle = unit->handle;
  839. req->qtcb->header.port_handle = unit->port->handle;
  840. req->qtcb->bottom.support.req_handle = (u64) old_req_id;
  841. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  842. if (!zfcp_fsf_req_send(req))
  843. goto out;
  844. out_error_free:
  845. zfcp_fsf_req_free(req);
  846. req = NULL;
  847. out:
  848. spin_unlock(&adapter->req_q_lock);
  849. return req;
  850. }
  851. static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
  852. {
  853. struct zfcp_adapter *adapter = req->adapter;
  854. struct zfcp_send_ct *send_ct = req->data;
  855. struct fsf_qtcb_header *header = &req->qtcb->header;
  856. send_ct->status = -EINVAL;
  857. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  858. goto skip_fsfstatus;
  859. switch (header->fsf_status) {
  860. case FSF_GOOD:
  861. zfcp_san_dbf_event_ct_response(req);
  862. send_ct->status = 0;
  863. break;
  864. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  865. zfcp_fsf_class_not_supp(req);
  866. break;
  867. case FSF_ADAPTER_STATUS_AVAILABLE:
  868. switch (header->fsf_status_qual.word[0]){
  869. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  870. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  871. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  872. break;
  873. }
  874. break;
  875. case FSF_ACCESS_DENIED:
  876. break;
  877. case FSF_PORT_BOXED:
  878. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  879. ZFCP_STATUS_FSFREQ_RETRY;
  880. break;
  881. case FSF_PORT_HANDLE_NOT_VALID:
  882. zfcp_erp_adapter_reopen(adapter, 0, 106, req);
  883. case FSF_GENERIC_COMMAND_REJECTED:
  884. case FSF_PAYLOAD_SIZE_MISMATCH:
  885. case FSF_REQUEST_SIZE_TOO_LARGE:
  886. case FSF_RESPONSE_SIZE_TOO_LARGE:
  887. case FSF_SBAL_MISMATCH:
  888. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  889. break;
  890. }
  891. skip_fsfstatus:
  892. if (send_ct->handler)
  893. send_ct->handler(send_ct->handler_data);
  894. }
  895. static int zfcp_fsf_setup_sbals(struct zfcp_fsf_req *req,
  896. struct scatterlist *sg_req,
  897. struct scatterlist *sg_resp, int max_sbals)
  898. {
  899. int bytes;
  900. bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
  901. sg_req, max_sbals);
  902. if (bytes <= 0)
  903. return -ENOMEM;
  904. req->qtcb->bottom.support.req_buf_length = bytes;
  905. req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
  906. bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
  907. sg_resp, max_sbals);
  908. if (bytes <= 0)
  909. return -ENOMEM;
  910. req->qtcb->bottom.support.resp_buf_length = bytes;
  911. return 0;
  912. }
  913. /**
  914. * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
  915. * @ct: pointer to struct zfcp_send_ct with data for request
  916. * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
  917. * @erp_action: if non-null the Generic Service request sent within ERP
  918. */
  919. int zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
  920. struct zfcp_erp_action *erp_action)
  921. {
  922. struct zfcp_wka_port *wka_port = ct->wka_port;
  923. struct zfcp_adapter *adapter = wka_port->adapter;
  924. struct zfcp_fsf_req *req;
  925. int ret = -EIO;
  926. spin_lock_bh(&adapter->req_q_lock);
  927. if (zfcp_fsf_req_sbal_get(adapter))
  928. goto out;
  929. req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
  930. ZFCP_REQ_AUTO_CLEANUP, pool);
  931. if (IS_ERR(req)) {
  932. ret = PTR_ERR(req);
  933. goto out;
  934. }
  935. ret = zfcp_fsf_setup_sbals(req, ct->req, ct->resp,
  936. FSF_MAX_SBALS_PER_REQ);
  937. if (ret)
  938. goto failed_send;
  939. req->handler = zfcp_fsf_send_ct_handler;
  940. req->qtcb->header.port_handle = wka_port->handle;
  941. req->qtcb->bottom.support.service_class = FSF_CLASS_3;
  942. req->qtcb->bottom.support.timeout = ct->timeout;
  943. req->data = ct;
  944. zfcp_san_dbf_event_ct_request(req);
  945. if (erp_action) {
  946. erp_action->fsf_req = req;
  947. req->erp_action = erp_action;
  948. zfcp_fsf_start_erp_timer(req);
  949. } else
  950. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  951. ret = zfcp_fsf_req_send(req);
  952. if (ret)
  953. goto failed_send;
  954. goto out;
  955. failed_send:
  956. zfcp_fsf_req_free(req);
  957. if (erp_action)
  958. erp_action->fsf_req = NULL;
  959. out:
  960. spin_unlock_bh(&adapter->req_q_lock);
  961. return ret;
  962. }
  963. static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
  964. {
  965. struct zfcp_send_els *send_els = req->data;
  966. struct zfcp_port *port = send_els->port;
  967. struct fsf_qtcb_header *header = &req->qtcb->header;
  968. send_els->status = -EINVAL;
  969. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  970. goto skip_fsfstatus;
  971. switch (header->fsf_status) {
  972. case FSF_GOOD:
  973. zfcp_san_dbf_event_els_response(req);
  974. send_els->status = 0;
  975. break;
  976. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  977. zfcp_fsf_class_not_supp(req);
  978. break;
  979. case FSF_ADAPTER_STATUS_AVAILABLE:
  980. switch (header->fsf_status_qual.word[0]){
  981. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  982. if (port && (send_els->ls_code != ZFCP_LS_ADISC))
  983. zfcp_test_link(port);
  984. /*fall through */
  985. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  986. case FSF_SQ_RETRY_IF_POSSIBLE:
  987. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  988. break;
  989. }
  990. break;
  991. case FSF_ELS_COMMAND_REJECTED:
  992. case FSF_PAYLOAD_SIZE_MISMATCH:
  993. case FSF_REQUEST_SIZE_TOO_LARGE:
  994. case FSF_RESPONSE_SIZE_TOO_LARGE:
  995. break;
  996. case FSF_ACCESS_DENIED:
  997. zfcp_fsf_access_denied_port(req, port);
  998. break;
  999. case FSF_SBAL_MISMATCH:
  1000. /* should never occure, avoided in zfcp_fsf_send_els */
  1001. /* fall through */
  1002. default:
  1003. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1004. break;
  1005. }
  1006. skip_fsfstatus:
  1007. if (send_els->handler)
  1008. send_els->handler(send_els->handler_data);
  1009. }
  1010. /**
  1011. * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
  1012. * @els: pointer to struct zfcp_send_els with data for the command
  1013. */
  1014. int zfcp_fsf_send_els(struct zfcp_send_els *els)
  1015. {
  1016. struct zfcp_fsf_req *req;
  1017. struct zfcp_adapter *adapter = els->adapter;
  1018. struct fsf_qtcb_bottom_support *bottom;
  1019. int ret = -EIO;
  1020. if (unlikely(!(atomic_read(&els->port->status) &
  1021. ZFCP_STATUS_COMMON_UNBLOCKED)))
  1022. return -EBUSY;
  1023. spin_lock(&adapter->req_q_lock);
  1024. if (!zfcp_fsf_sbal_available(adapter))
  1025. goto out;
  1026. req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
  1027. ZFCP_REQ_AUTO_CLEANUP, NULL);
  1028. if (IS_ERR(req)) {
  1029. ret = PTR_ERR(req);
  1030. goto out;
  1031. }
  1032. ret = zfcp_fsf_setup_sbals(req, els->req, els->resp, 2);
  1033. if (ret)
  1034. goto failed_send;
  1035. bottom = &req->qtcb->bottom.support;
  1036. req->handler = zfcp_fsf_send_els_handler;
  1037. bottom->d_id = els->d_id;
  1038. bottom->service_class = FSF_CLASS_3;
  1039. bottom->timeout = 2 * R_A_TOV;
  1040. req->data = els;
  1041. zfcp_san_dbf_event_els_request(req);
  1042. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1043. ret = zfcp_fsf_req_send(req);
  1044. if (ret)
  1045. goto failed_send;
  1046. goto out;
  1047. failed_send:
  1048. zfcp_fsf_req_free(req);
  1049. out:
  1050. spin_unlock(&adapter->req_q_lock);
  1051. return ret;
  1052. }
  1053. int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
  1054. {
  1055. struct qdio_buffer_element *sbale;
  1056. struct zfcp_fsf_req *req;
  1057. struct zfcp_adapter *adapter = erp_action->adapter;
  1058. int retval = -EIO;
  1059. spin_lock_bh(&adapter->req_q_lock);
  1060. if (!zfcp_fsf_sbal_available(adapter))
  1061. goto out;
  1062. req = zfcp_fsf_req_create(adapter,
  1063. FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1064. ZFCP_REQ_AUTO_CLEANUP,
  1065. adapter->pool.fsf_req_erp);
  1066. if (IS_ERR(req)) {
  1067. retval = PTR_ERR(req);
  1068. goto out;
  1069. }
  1070. sbale = zfcp_qdio_sbale_req(req);
  1071. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1072. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1073. req->qtcb->bottom.config.feature_selection =
  1074. FSF_FEATURE_CFDC |
  1075. FSF_FEATURE_LUN_SHARING |
  1076. FSF_FEATURE_NOTIFICATION_LOST |
  1077. FSF_FEATURE_UPDATE_ALERT;
  1078. req->erp_action = erp_action;
  1079. req->handler = zfcp_fsf_exchange_config_data_handler;
  1080. erp_action->fsf_req = req;
  1081. zfcp_fsf_start_erp_timer(req);
  1082. retval = zfcp_fsf_req_send(req);
  1083. if (retval) {
  1084. zfcp_fsf_req_free(req);
  1085. erp_action->fsf_req = NULL;
  1086. }
  1087. out:
  1088. spin_unlock_bh(&adapter->req_q_lock);
  1089. return retval;
  1090. }
  1091. int zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
  1092. struct fsf_qtcb_bottom_config *data)
  1093. {
  1094. struct qdio_buffer_element *sbale;
  1095. struct zfcp_fsf_req *req = NULL;
  1096. int retval = -EIO;
  1097. spin_lock_bh(&adapter->req_q_lock);
  1098. if (zfcp_fsf_req_sbal_get(adapter))
  1099. goto out;
  1100. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1101. 0, NULL);
  1102. if (IS_ERR(req)) {
  1103. retval = PTR_ERR(req);
  1104. goto out;
  1105. }
  1106. sbale = zfcp_qdio_sbale_req(req);
  1107. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1108. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1109. req->handler = zfcp_fsf_exchange_config_data_handler;
  1110. req->qtcb->bottom.config.feature_selection =
  1111. FSF_FEATURE_CFDC |
  1112. FSF_FEATURE_LUN_SHARING |
  1113. FSF_FEATURE_NOTIFICATION_LOST |
  1114. FSF_FEATURE_UPDATE_ALERT;
  1115. if (data)
  1116. req->data = data;
  1117. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1118. retval = zfcp_fsf_req_send(req);
  1119. out:
  1120. spin_unlock_bh(&adapter->req_q_lock);
  1121. if (!retval)
  1122. wait_event(req->completion_wq,
  1123. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  1124. zfcp_fsf_req_free(req);
  1125. return retval;
  1126. }
  1127. /**
  1128. * zfcp_fsf_exchange_port_data - request information about local port
  1129. * @erp_action: ERP action for the adapter for which port data is requested
  1130. * Returns: 0 on success, error otherwise
  1131. */
  1132. int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
  1133. {
  1134. struct qdio_buffer_element *sbale;
  1135. struct zfcp_fsf_req *req;
  1136. struct zfcp_adapter *adapter = erp_action->adapter;
  1137. int retval = -EIO;
  1138. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1139. return -EOPNOTSUPP;
  1140. spin_lock_bh(&adapter->req_q_lock);
  1141. if (!zfcp_fsf_sbal_available(adapter))
  1142. goto out;
  1143. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
  1144. ZFCP_REQ_AUTO_CLEANUP,
  1145. adapter->pool.fsf_req_erp);
  1146. if (IS_ERR(req)) {
  1147. retval = PTR_ERR(req);
  1148. goto out;
  1149. }
  1150. sbale = zfcp_qdio_sbale_req(req);
  1151. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1152. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1153. req->handler = zfcp_fsf_exchange_port_data_handler;
  1154. req->erp_action = erp_action;
  1155. erp_action->fsf_req = req;
  1156. zfcp_fsf_start_erp_timer(req);
  1157. retval = zfcp_fsf_req_send(req);
  1158. if (retval) {
  1159. zfcp_fsf_req_free(req);
  1160. erp_action->fsf_req = NULL;
  1161. }
  1162. out:
  1163. spin_unlock_bh(&adapter->req_q_lock);
  1164. return retval;
  1165. }
  1166. /**
  1167. * zfcp_fsf_exchange_port_data_sync - request information about local port
  1168. * @adapter: pointer to struct zfcp_adapter
  1169. * @data: pointer to struct fsf_qtcb_bottom_port
  1170. * Returns: 0 on success, error otherwise
  1171. */
  1172. int zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
  1173. struct fsf_qtcb_bottom_port *data)
  1174. {
  1175. struct qdio_buffer_element *sbale;
  1176. struct zfcp_fsf_req *req = NULL;
  1177. int retval = -EIO;
  1178. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1179. return -EOPNOTSUPP;
  1180. spin_lock_bh(&adapter->req_q_lock);
  1181. if (!zfcp_fsf_sbal_available(adapter))
  1182. goto out;
  1183. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, 0,
  1184. NULL);
  1185. if (IS_ERR(req)) {
  1186. retval = PTR_ERR(req);
  1187. goto out;
  1188. }
  1189. if (data)
  1190. req->data = data;
  1191. sbale = zfcp_qdio_sbale_req(req);
  1192. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1193. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1194. req->handler = zfcp_fsf_exchange_port_data_handler;
  1195. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1196. retval = zfcp_fsf_req_send(req);
  1197. out:
  1198. spin_unlock_bh(&adapter->req_q_lock);
  1199. if (!retval)
  1200. wait_event(req->completion_wq,
  1201. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  1202. zfcp_fsf_req_free(req);
  1203. return retval;
  1204. }
  1205. static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
  1206. {
  1207. struct zfcp_port *port = req->data;
  1208. struct fsf_qtcb_header *header = &req->qtcb->header;
  1209. struct fsf_plogi *plogi;
  1210. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1211. return;
  1212. switch (header->fsf_status) {
  1213. case FSF_PORT_ALREADY_OPEN:
  1214. break;
  1215. case FSF_ACCESS_DENIED:
  1216. zfcp_fsf_access_denied_port(req, port);
  1217. break;
  1218. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1219. dev_warn(&req->adapter->ccw_device->dev,
  1220. "Not enough FCP adapter resources to open "
  1221. "remote port 0x%016Lx\n",
  1222. (unsigned long long)port->wwpn);
  1223. zfcp_erp_port_failed(port, 31, req);
  1224. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1225. break;
  1226. case FSF_ADAPTER_STATUS_AVAILABLE:
  1227. switch (header->fsf_status_qual.word[0]) {
  1228. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1229. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1230. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1231. break;
  1232. case FSF_SQ_NO_RETRY_POSSIBLE:
  1233. dev_warn(&req->adapter->ccw_device->dev,
  1234. "Remote port 0x%016Lx could not be opened\n",
  1235. (unsigned long long)port->wwpn);
  1236. zfcp_erp_port_failed(port, 32, req);
  1237. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1238. break;
  1239. }
  1240. break;
  1241. case FSF_GOOD:
  1242. port->handle = header->port_handle;
  1243. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
  1244. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1245. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1246. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1247. &port->status);
  1248. /* check whether D_ID has changed during open */
  1249. /*
  1250. * FIXME: This check is not airtight, as the FCP channel does
  1251. * not monitor closures of target port connections caused on
  1252. * the remote side. Thus, they might miss out on invalidating
  1253. * locally cached WWPNs (and other N_Port parameters) of gone
  1254. * target ports. So, our heroic attempt to make things safe
  1255. * could be undermined by 'open port' response data tagged with
  1256. * obsolete WWPNs. Another reason to monitor potential
  1257. * connection closures ourself at least (by interpreting
  1258. * incoming ELS' and unsolicited status). It just crosses my
  1259. * mind that one should be able to cross-check by means of
  1260. * another GID_PN straight after a port has been opened.
  1261. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  1262. */
  1263. plogi = (struct fsf_plogi *) req->qtcb->bottom.support.els;
  1264. if (req->qtcb->bottom.support.els1_length >= sizeof(*plogi)) {
  1265. if (plogi->serv_param.wwpn != port->wwpn)
  1266. atomic_clear_mask(ZFCP_STATUS_PORT_DID_DID,
  1267. &port->status);
  1268. else {
  1269. port->wwnn = plogi->serv_param.wwnn;
  1270. zfcp_fc_plogi_evaluate(port, plogi);
  1271. }
  1272. }
  1273. break;
  1274. case FSF_UNKNOWN_OP_SUBTYPE:
  1275. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1276. break;
  1277. }
  1278. }
  1279. /**
  1280. * zfcp_fsf_open_port - create and send open port request
  1281. * @erp_action: pointer to struct zfcp_erp_action
  1282. * Returns: 0 on success, error otherwise
  1283. */
  1284. int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  1285. {
  1286. struct qdio_buffer_element *sbale;
  1287. struct zfcp_adapter *adapter = erp_action->adapter;
  1288. struct zfcp_fsf_req *req;
  1289. int retval = -EIO;
  1290. spin_lock_bh(&adapter->req_q_lock);
  1291. if (zfcp_fsf_req_sbal_get(adapter))
  1292. goto out;
  1293. req = zfcp_fsf_req_create(adapter,
  1294. FSF_QTCB_OPEN_PORT_WITH_DID,
  1295. ZFCP_REQ_AUTO_CLEANUP,
  1296. adapter->pool.fsf_req_erp);
  1297. if (IS_ERR(req)) {
  1298. retval = PTR_ERR(req);
  1299. goto out;
  1300. }
  1301. sbale = zfcp_qdio_sbale_req(req);
  1302. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1303. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1304. req->handler = zfcp_fsf_open_port_handler;
  1305. req->qtcb->bottom.support.d_id = erp_action->port->d_id;
  1306. req->data = erp_action->port;
  1307. req->erp_action = erp_action;
  1308. erp_action->fsf_req = req;
  1309. zfcp_fsf_start_erp_timer(req);
  1310. retval = zfcp_fsf_req_send(req);
  1311. if (retval) {
  1312. zfcp_fsf_req_free(req);
  1313. erp_action->fsf_req = NULL;
  1314. }
  1315. out:
  1316. spin_unlock_bh(&adapter->req_q_lock);
  1317. return retval;
  1318. }
  1319. static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
  1320. {
  1321. struct zfcp_port *port = req->data;
  1322. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1323. return;
  1324. switch (req->qtcb->header.fsf_status) {
  1325. case FSF_PORT_HANDLE_NOT_VALID:
  1326. zfcp_erp_adapter_reopen(port->adapter, 0, 107, req);
  1327. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1328. break;
  1329. case FSF_ADAPTER_STATUS_AVAILABLE:
  1330. break;
  1331. case FSF_GOOD:
  1332. zfcp_erp_modify_port_status(port, 33, req,
  1333. ZFCP_STATUS_COMMON_OPEN,
  1334. ZFCP_CLEAR);
  1335. break;
  1336. }
  1337. }
  1338. /**
  1339. * zfcp_fsf_close_port - create and send close port request
  1340. * @erp_action: pointer to struct zfcp_erp_action
  1341. * Returns: 0 on success, error otherwise
  1342. */
  1343. int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  1344. {
  1345. struct qdio_buffer_element *sbale;
  1346. struct zfcp_adapter *adapter = erp_action->adapter;
  1347. struct zfcp_fsf_req *req;
  1348. int retval = -EIO;
  1349. spin_lock_bh(&adapter->req_q_lock);
  1350. if (zfcp_fsf_req_sbal_get(adapter))
  1351. goto out;
  1352. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
  1353. ZFCP_REQ_AUTO_CLEANUP,
  1354. adapter->pool.fsf_req_erp);
  1355. if (IS_ERR(req)) {
  1356. retval = PTR_ERR(req);
  1357. goto out;
  1358. }
  1359. sbale = zfcp_qdio_sbale_req(req);
  1360. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1361. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1362. req->handler = zfcp_fsf_close_port_handler;
  1363. req->data = erp_action->port;
  1364. req->erp_action = erp_action;
  1365. req->qtcb->header.port_handle = erp_action->port->handle;
  1366. erp_action->fsf_req = req;
  1367. zfcp_fsf_start_erp_timer(req);
  1368. retval = zfcp_fsf_req_send(req);
  1369. if (retval) {
  1370. zfcp_fsf_req_free(req);
  1371. erp_action->fsf_req = NULL;
  1372. }
  1373. out:
  1374. spin_unlock_bh(&adapter->req_q_lock);
  1375. return retval;
  1376. }
  1377. static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
  1378. {
  1379. struct zfcp_wka_port *wka_port = req->data;
  1380. struct fsf_qtcb_header *header = &req->qtcb->header;
  1381. if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  1382. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1383. goto out;
  1384. }
  1385. switch (header->fsf_status) {
  1386. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1387. dev_warn(&req->adapter->ccw_device->dev,
  1388. "Opening WKA port 0x%x failed\n", wka_port->d_id);
  1389. case FSF_ADAPTER_STATUS_AVAILABLE:
  1390. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1391. case FSF_ACCESS_DENIED:
  1392. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1393. break;
  1394. case FSF_PORT_ALREADY_OPEN:
  1395. case FSF_GOOD:
  1396. wka_port->handle = header->port_handle;
  1397. wka_port->status = ZFCP_WKA_PORT_ONLINE;
  1398. }
  1399. out:
  1400. wake_up(&wka_port->completion_wq);
  1401. }
  1402. /**
  1403. * zfcp_fsf_open_wka_port - create and send open wka-port request
  1404. * @wka_port: pointer to struct zfcp_wka_port
  1405. * Returns: 0 on success, error otherwise
  1406. */
  1407. int zfcp_fsf_open_wka_port(struct zfcp_wka_port *wka_port)
  1408. {
  1409. struct qdio_buffer_element *sbale;
  1410. struct zfcp_adapter *adapter = wka_port->adapter;
  1411. struct zfcp_fsf_req *req;
  1412. int retval = -EIO;
  1413. spin_lock_bh(&adapter->req_q_lock);
  1414. if (zfcp_fsf_req_sbal_get(adapter))
  1415. goto out;
  1416. req = zfcp_fsf_req_create(adapter,
  1417. FSF_QTCB_OPEN_PORT_WITH_DID,
  1418. ZFCP_REQ_AUTO_CLEANUP,
  1419. adapter->pool.fsf_req_erp);
  1420. if (unlikely(IS_ERR(req))) {
  1421. retval = PTR_ERR(req);
  1422. goto out;
  1423. }
  1424. sbale = zfcp_qdio_sbale_req(req);
  1425. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1426. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1427. req->handler = zfcp_fsf_open_wka_port_handler;
  1428. req->qtcb->bottom.support.d_id = wka_port->d_id;
  1429. req->data = wka_port;
  1430. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1431. retval = zfcp_fsf_req_send(req);
  1432. if (retval)
  1433. zfcp_fsf_req_free(req);
  1434. out:
  1435. spin_unlock_bh(&adapter->req_q_lock);
  1436. return retval;
  1437. }
  1438. static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
  1439. {
  1440. struct zfcp_wka_port *wka_port = req->data;
  1441. if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
  1442. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1443. zfcp_erp_adapter_reopen(wka_port->adapter, 0, 84, req);
  1444. }
  1445. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1446. wake_up(&wka_port->completion_wq);
  1447. }
  1448. /**
  1449. * zfcp_fsf_close_wka_port - create and send close wka port request
  1450. * @erp_action: pointer to struct zfcp_erp_action
  1451. * Returns: 0 on success, error otherwise
  1452. */
  1453. int zfcp_fsf_close_wka_port(struct zfcp_wka_port *wka_port)
  1454. {
  1455. struct qdio_buffer_element *sbale;
  1456. struct zfcp_adapter *adapter = wka_port->adapter;
  1457. struct zfcp_fsf_req *req;
  1458. int retval = -EIO;
  1459. spin_lock_bh(&adapter->req_q_lock);
  1460. if (zfcp_fsf_req_sbal_get(adapter))
  1461. goto out;
  1462. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
  1463. ZFCP_REQ_AUTO_CLEANUP,
  1464. adapter->pool.fsf_req_erp);
  1465. if (unlikely(IS_ERR(req))) {
  1466. retval = PTR_ERR(req);
  1467. goto out;
  1468. }
  1469. sbale = zfcp_qdio_sbale_req(req);
  1470. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1471. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1472. req->handler = zfcp_fsf_close_wka_port_handler;
  1473. req->data = wka_port;
  1474. req->qtcb->header.port_handle = wka_port->handle;
  1475. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1476. retval = zfcp_fsf_req_send(req);
  1477. if (retval)
  1478. zfcp_fsf_req_free(req);
  1479. out:
  1480. spin_unlock_bh(&adapter->req_q_lock);
  1481. return retval;
  1482. }
  1483. static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
  1484. {
  1485. struct zfcp_port *port = req->data;
  1486. struct fsf_qtcb_header *header = &req->qtcb->header;
  1487. struct zfcp_unit *unit;
  1488. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1489. goto skip_fsfstatus;
  1490. switch (header->fsf_status) {
  1491. case FSF_PORT_HANDLE_NOT_VALID:
  1492. zfcp_erp_adapter_reopen(port->adapter, 0, 108, req);
  1493. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1494. break;
  1495. case FSF_ACCESS_DENIED:
  1496. zfcp_fsf_access_denied_port(req, port);
  1497. break;
  1498. case FSF_PORT_BOXED:
  1499. zfcp_erp_port_boxed(port, 50, req);
  1500. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1501. ZFCP_STATUS_FSFREQ_RETRY;
  1502. /* can't use generic zfcp_erp_modify_port_status because
  1503. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
  1504. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1505. list_for_each_entry(unit, &port->unit_list_head, list)
  1506. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1507. &unit->status);
  1508. break;
  1509. case FSF_ADAPTER_STATUS_AVAILABLE:
  1510. switch (header->fsf_status_qual.word[0]) {
  1511. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1512. /* fall through */
  1513. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1514. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1515. break;
  1516. }
  1517. break;
  1518. case FSF_GOOD:
  1519. /* can't use generic zfcp_erp_modify_port_status because
  1520. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  1521. */
  1522. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1523. list_for_each_entry(unit, &port->unit_list_head, list)
  1524. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1525. &unit->status);
  1526. break;
  1527. }
  1528. skip_fsfstatus:
  1529. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
  1530. }
  1531. /**
  1532. * zfcp_fsf_close_physical_port - close physical port
  1533. * @erp_action: pointer to struct zfcp_erp_action
  1534. * Returns: 0 on success
  1535. */
  1536. int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  1537. {
  1538. struct qdio_buffer_element *sbale;
  1539. struct zfcp_adapter *adapter = erp_action->adapter;
  1540. struct zfcp_fsf_req *req;
  1541. int retval = -EIO;
  1542. spin_lock_bh(&adapter->req_q_lock);
  1543. if (zfcp_fsf_req_sbal_get(adapter))
  1544. goto out;
  1545. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PHYSICAL_PORT,
  1546. ZFCP_REQ_AUTO_CLEANUP,
  1547. adapter->pool.fsf_req_erp);
  1548. if (IS_ERR(req)) {
  1549. retval = PTR_ERR(req);
  1550. goto out;
  1551. }
  1552. sbale = zfcp_qdio_sbale_req(req);
  1553. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1554. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1555. req->data = erp_action->port;
  1556. req->qtcb->header.port_handle = erp_action->port->handle;
  1557. req->erp_action = erp_action;
  1558. req->handler = zfcp_fsf_close_physical_port_handler;
  1559. erp_action->fsf_req = req;
  1560. atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
  1561. &erp_action->port->status);
  1562. zfcp_fsf_start_erp_timer(req);
  1563. retval = zfcp_fsf_req_send(req);
  1564. if (retval) {
  1565. zfcp_fsf_req_free(req);
  1566. erp_action->fsf_req = NULL;
  1567. }
  1568. out:
  1569. spin_unlock_bh(&adapter->req_q_lock);
  1570. return retval;
  1571. }
  1572. static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
  1573. {
  1574. struct zfcp_adapter *adapter = req->adapter;
  1575. struct zfcp_unit *unit = req->data;
  1576. struct fsf_qtcb_header *header = &req->qtcb->header;
  1577. struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
  1578. struct fsf_queue_designator *queue_designator =
  1579. &header->fsf_status_qual.fsf_queue_designator;
  1580. int exclusive, readwrite;
  1581. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1582. return;
  1583. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1584. ZFCP_STATUS_COMMON_ACCESS_BOXED |
  1585. ZFCP_STATUS_UNIT_SHARED |
  1586. ZFCP_STATUS_UNIT_READONLY,
  1587. &unit->status);
  1588. switch (header->fsf_status) {
  1589. case FSF_PORT_HANDLE_NOT_VALID:
  1590. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 109, req);
  1591. /* fall through */
  1592. case FSF_LUN_ALREADY_OPEN:
  1593. break;
  1594. case FSF_ACCESS_DENIED:
  1595. zfcp_fsf_access_denied_unit(req, unit);
  1596. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1597. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1598. break;
  1599. case FSF_PORT_BOXED:
  1600. zfcp_erp_port_boxed(unit->port, 51, req);
  1601. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1602. ZFCP_STATUS_FSFREQ_RETRY;
  1603. break;
  1604. case FSF_LUN_SHARING_VIOLATION:
  1605. if (header->fsf_status_qual.word[0])
  1606. dev_warn(&adapter->ccw_device->dev,
  1607. "LUN 0x%Lx on port 0x%Lx is already in "
  1608. "use by CSS%d, MIF Image ID %x\n",
  1609. (unsigned long long)unit->fcp_lun,
  1610. (unsigned long long)unit->port->wwpn,
  1611. queue_designator->cssid,
  1612. queue_designator->hla);
  1613. else
  1614. zfcp_act_eval_err(adapter,
  1615. header->fsf_status_qual.word[2]);
  1616. zfcp_erp_unit_access_denied(unit, 60, req);
  1617. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1618. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1619. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1620. break;
  1621. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  1622. dev_warn(&adapter->ccw_device->dev,
  1623. "No handle is available for LUN "
  1624. "0x%016Lx on port 0x%016Lx\n",
  1625. (unsigned long long)unit->fcp_lun,
  1626. (unsigned long long)unit->port->wwpn);
  1627. zfcp_erp_unit_failed(unit, 34, req);
  1628. /* fall through */
  1629. case FSF_INVALID_COMMAND_OPTION:
  1630. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1631. break;
  1632. case FSF_ADAPTER_STATUS_AVAILABLE:
  1633. switch (header->fsf_status_qual.word[0]) {
  1634. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1635. zfcp_test_link(unit->port);
  1636. /* fall through */
  1637. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1638. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1639. break;
  1640. }
  1641. break;
  1642. case FSF_GOOD:
  1643. unit->handle = header->lun_handle;
  1644. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1645. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
  1646. (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
  1647. (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
  1648. exclusive = (bottom->lun_access_info &
  1649. FSF_UNIT_ACCESS_EXCLUSIVE);
  1650. readwrite = (bottom->lun_access_info &
  1651. FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
  1652. if (!exclusive)
  1653. atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
  1654. &unit->status);
  1655. if (!readwrite) {
  1656. atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
  1657. &unit->status);
  1658. dev_info(&adapter->ccw_device->dev,
  1659. "SCSI device at LUN 0x%016Lx on port "
  1660. "0x%016Lx opened read-only\n",
  1661. (unsigned long long)unit->fcp_lun,
  1662. (unsigned long long)unit->port->wwpn);
  1663. }
  1664. if (exclusive && !readwrite) {
  1665. dev_err(&adapter->ccw_device->dev,
  1666. "Exclusive read-only access not "
  1667. "supported (unit 0x%016Lx, "
  1668. "port 0x%016Lx)\n",
  1669. (unsigned long long)unit->fcp_lun,
  1670. (unsigned long long)unit->port->wwpn);
  1671. zfcp_erp_unit_failed(unit, 35, req);
  1672. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1673. zfcp_erp_unit_shutdown(unit, 0, 80, req);
  1674. } else if (!exclusive && readwrite) {
  1675. dev_err(&adapter->ccw_device->dev,
  1676. "Shared read-write access not "
  1677. "supported (unit 0x%016Lx, port "
  1678. "0x%016Lx\n)",
  1679. (unsigned long long)unit->fcp_lun,
  1680. (unsigned long long)unit->port->wwpn);
  1681. zfcp_erp_unit_failed(unit, 36, req);
  1682. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1683. zfcp_erp_unit_shutdown(unit, 0, 81, req);
  1684. }
  1685. }
  1686. break;
  1687. }
  1688. }
  1689. /**
  1690. * zfcp_fsf_open_unit - open unit
  1691. * @erp_action: pointer to struct zfcp_erp_action
  1692. * Returns: 0 on success, error otherwise
  1693. */
  1694. int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
  1695. {
  1696. struct qdio_buffer_element *sbale;
  1697. struct zfcp_adapter *adapter = erp_action->adapter;
  1698. struct zfcp_fsf_req *req;
  1699. int retval = -EIO;
  1700. spin_lock_bh(&adapter->req_q_lock);
  1701. if (zfcp_fsf_req_sbal_get(adapter))
  1702. goto out;
  1703. req = zfcp_fsf_req_create(adapter, FSF_QTCB_OPEN_LUN,
  1704. ZFCP_REQ_AUTO_CLEANUP,
  1705. adapter->pool.fsf_req_erp);
  1706. if (IS_ERR(req)) {
  1707. retval = PTR_ERR(req);
  1708. goto out;
  1709. }
  1710. sbale = zfcp_qdio_sbale_req(req);
  1711. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1712. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1713. req->qtcb->header.port_handle = erp_action->port->handle;
  1714. req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
  1715. req->handler = zfcp_fsf_open_unit_handler;
  1716. req->data = erp_action->unit;
  1717. req->erp_action = erp_action;
  1718. erp_action->fsf_req = req;
  1719. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  1720. req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
  1721. zfcp_fsf_start_erp_timer(req);
  1722. retval = zfcp_fsf_req_send(req);
  1723. if (retval) {
  1724. zfcp_fsf_req_free(req);
  1725. erp_action->fsf_req = NULL;
  1726. }
  1727. out:
  1728. spin_unlock_bh(&adapter->req_q_lock);
  1729. return retval;
  1730. }
  1731. static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
  1732. {
  1733. struct zfcp_unit *unit = req->data;
  1734. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1735. return;
  1736. switch (req->qtcb->header.fsf_status) {
  1737. case FSF_PORT_HANDLE_NOT_VALID:
  1738. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 110, req);
  1739. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1740. break;
  1741. case FSF_LUN_HANDLE_NOT_VALID:
  1742. zfcp_erp_port_reopen(unit->port, 0, 111, req);
  1743. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1744. break;
  1745. case FSF_PORT_BOXED:
  1746. zfcp_erp_port_boxed(unit->port, 52, req);
  1747. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1748. ZFCP_STATUS_FSFREQ_RETRY;
  1749. break;
  1750. case FSF_ADAPTER_STATUS_AVAILABLE:
  1751. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  1752. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1753. zfcp_test_link(unit->port);
  1754. /* fall through */
  1755. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1756. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1757. break;
  1758. }
  1759. break;
  1760. case FSF_GOOD:
  1761. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1762. break;
  1763. }
  1764. }
  1765. /**
  1766. * zfcp_fsf_close_unit - close zfcp unit
  1767. * @erp_action: pointer to struct zfcp_unit
  1768. * Returns: 0 on success, error otherwise
  1769. */
  1770. int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
  1771. {
  1772. struct qdio_buffer_element *sbale;
  1773. struct zfcp_adapter *adapter = erp_action->adapter;
  1774. struct zfcp_fsf_req *req;
  1775. int retval = -EIO;
  1776. spin_lock_bh(&adapter->req_q_lock);
  1777. if (zfcp_fsf_req_sbal_get(adapter))
  1778. goto out;
  1779. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_LUN,
  1780. ZFCP_REQ_AUTO_CLEANUP,
  1781. adapter->pool.fsf_req_erp);
  1782. if (IS_ERR(req)) {
  1783. retval = PTR_ERR(req);
  1784. goto out;
  1785. }
  1786. sbale = zfcp_qdio_sbale_req(req);
  1787. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1788. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1789. req->qtcb->header.port_handle = erp_action->port->handle;
  1790. req->qtcb->header.lun_handle = erp_action->unit->handle;
  1791. req->handler = zfcp_fsf_close_unit_handler;
  1792. req->data = erp_action->unit;
  1793. req->erp_action = erp_action;
  1794. erp_action->fsf_req = req;
  1795. zfcp_fsf_start_erp_timer(req);
  1796. retval = zfcp_fsf_req_send(req);
  1797. if (retval) {
  1798. zfcp_fsf_req_free(req);
  1799. erp_action->fsf_req = NULL;
  1800. }
  1801. out:
  1802. spin_unlock_bh(&adapter->req_q_lock);
  1803. return retval;
  1804. }
  1805. static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
  1806. {
  1807. lat_rec->sum += lat;
  1808. lat_rec->min = min(lat_rec->min, lat);
  1809. lat_rec->max = max(lat_rec->max, lat);
  1810. }
  1811. static void zfcp_fsf_req_latency(struct zfcp_fsf_req *req)
  1812. {
  1813. struct fsf_qual_latency_info *lat_inf;
  1814. struct latency_cont *lat;
  1815. struct zfcp_unit *unit = req->unit;
  1816. unsigned long flags;
  1817. lat_inf = &req->qtcb->prefix.prot_status_qual.latency_info;
  1818. switch (req->qtcb->bottom.io.data_direction) {
  1819. case FSF_DATADIR_READ:
  1820. lat = &unit->latencies.read;
  1821. break;
  1822. case FSF_DATADIR_WRITE:
  1823. lat = &unit->latencies.write;
  1824. break;
  1825. case FSF_DATADIR_CMND:
  1826. lat = &unit->latencies.cmd;
  1827. break;
  1828. default:
  1829. return;
  1830. }
  1831. spin_lock_irqsave(&unit->latencies.lock, flags);
  1832. zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
  1833. zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
  1834. lat->counter++;
  1835. spin_unlock_irqrestore(&unit->latencies.lock, flags);
  1836. }
  1837. static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
  1838. {
  1839. struct scsi_cmnd *scpnt = req->data;
  1840. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  1841. &(req->qtcb->bottom.io.fcp_rsp);
  1842. u32 sns_len;
  1843. char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
  1844. unsigned long flags;
  1845. if (unlikely(!scpnt))
  1846. return;
  1847. read_lock_irqsave(&req->adapter->abort_lock, flags);
  1848. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
  1849. set_host_byte(scpnt, DID_SOFT_ERROR);
  1850. set_driver_byte(scpnt, SUGGEST_RETRY);
  1851. goto skip_fsfstatus;
  1852. }
  1853. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1854. set_host_byte(scpnt, DID_ERROR);
  1855. goto skip_fsfstatus;
  1856. }
  1857. set_msg_byte(scpnt, COMMAND_COMPLETE);
  1858. scpnt->result |= fcp_rsp_iu->scsi_status;
  1859. if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
  1860. zfcp_fsf_req_latency(req);
  1861. if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
  1862. if (fcp_rsp_info[3] == RSP_CODE_GOOD)
  1863. set_host_byte(scpnt, DID_OK);
  1864. else {
  1865. set_host_byte(scpnt, DID_ERROR);
  1866. goto skip_fsfstatus;
  1867. }
  1868. }
  1869. if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
  1870. sns_len = FSF_FCP_RSP_SIZE - sizeof(struct fcp_rsp_iu) +
  1871. fcp_rsp_iu->fcp_rsp_len;
  1872. sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
  1873. sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
  1874. memcpy(scpnt->sense_buffer,
  1875. zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
  1876. }
  1877. if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
  1878. scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
  1879. if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
  1880. scpnt->underflow)
  1881. set_host_byte(scpnt, DID_ERROR);
  1882. }
  1883. skip_fsfstatus:
  1884. if (scpnt->result != 0)
  1885. zfcp_scsi_dbf_event_result("erro", 3, req->adapter, scpnt, req);
  1886. else if (scpnt->retries > 0)
  1887. zfcp_scsi_dbf_event_result("retr", 4, req->adapter, scpnt, req);
  1888. else
  1889. zfcp_scsi_dbf_event_result("norm", 6, req->adapter, scpnt, req);
  1890. scpnt->host_scribble = NULL;
  1891. (scpnt->scsi_done) (scpnt);
  1892. /*
  1893. * We must hold this lock until scsi_done has been called.
  1894. * Otherwise we may call scsi_done after abort regarding this
  1895. * command has completed.
  1896. * Note: scsi_done must not block!
  1897. */
  1898. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1899. }
  1900. static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
  1901. {
  1902. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  1903. &(req->qtcb->bottom.io.fcp_rsp);
  1904. char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
  1905. if ((fcp_rsp_info[3] != RSP_CODE_GOOD) ||
  1906. (req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1907. req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  1908. }
  1909. static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
  1910. {
  1911. struct zfcp_unit *unit;
  1912. struct fsf_qtcb_header *header = &req->qtcb->header;
  1913. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
  1914. unit = req->data;
  1915. else
  1916. unit = req->unit;
  1917. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1918. goto skip_fsfstatus;
  1919. switch (header->fsf_status) {
  1920. case FSF_HANDLE_MISMATCH:
  1921. case FSF_PORT_HANDLE_NOT_VALID:
  1922. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 112, req);
  1923. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1924. break;
  1925. case FSF_FCPLUN_NOT_VALID:
  1926. case FSF_LUN_HANDLE_NOT_VALID:
  1927. zfcp_erp_port_reopen(unit->port, 0, 113, req);
  1928. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1929. break;
  1930. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1931. zfcp_fsf_class_not_supp(req);
  1932. break;
  1933. case FSF_ACCESS_DENIED:
  1934. zfcp_fsf_access_denied_unit(req, unit);
  1935. break;
  1936. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  1937. dev_err(&req->adapter->ccw_device->dev,
  1938. "Incorrect direction %d, unit 0x%016Lx on port "
  1939. "0x%016Lx closed\n",
  1940. req->qtcb->bottom.io.data_direction,
  1941. (unsigned long long)unit->fcp_lun,
  1942. (unsigned long long)unit->port->wwpn);
  1943. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 133, req);
  1944. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1945. break;
  1946. case FSF_CMND_LENGTH_NOT_VALID:
  1947. dev_err(&req->adapter->ccw_device->dev,
  1948. "Incorrect CDB length %d, unit 0x%016Lx on "
  1949. "port 0x%016Lx closed\n",
  1950. req->qtcb->bottom.io.fcp_cmnd_length,
  1951. (unsigned long long)unit->fcp_lun,
  1952. (unsigned long long)unit->port->wwpn);
  1953. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 134, req);
  1954. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1955. break;
  1956. case FSF_PORT_BOXED:
  1957. zfcp_erp_port_boxed(unit->port, 53, req);
  1958. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1959. ZFCP_STATUS_FSFREQ_RETRY;
  1960. break;
  1961. case FSF_LUN_BOXED:
  1962. zfcp_erp_unit_boxed(unit, 54, req);
  1963. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1964. ZFCP_STATUS_FSFREQ_RETRY;
  1965. break;
  1966. case FSF_ADAPTER_STATUS_AVAILABLE:
  1967. if (header->fsf_status_qual.word[0] ==
  1968. FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
  1969. zfcp_test_link(unit->port);
  1970. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1971. break;
  1972. }
  1973. skip_fsfstatus:
  1974. if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
  1975. zfcp_fsf_send_fcp_ctm_handler(req);
  1976. else {
  1977. zfcp_fsf_send_fcp_command_task_handler(req);
  1978. req->unit = NULL;
  1979. zfcp_unit_put(unit);
  1980. }
  1981. }
  1982. static void zfcp_set_fcp_dl(struct fcp_cmnd_iu *fcp_cmd, u32 fcp_dl)
  1983. {
  1984. u32 *fcp_dl_ptr;
  1985. /*
  1986. * fcp_dl_addr = start address of fcp_cmnd structure +
  1987. * size of fixed part + size of dynamically sized add_dcp_cdb field
  1988. * SEE FCP-2 documentation
  1989. */
  1990. fcp_dl_ptr = (u32 *) ((unsigned char *) &fcp_cmd[1] +
  1991. (fcp_cmd->add_fcp_cdb_length << 2));
  1992. *fcp_dl_ptr = fcp_dl;
  1993. }
  1994. /**
  1995. * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
  1996. * @adapter: adapter where scsi command is issued
  1997. * @unit: unit where command is sent to
  1998. * @scsi_cmnd: scsi command to be sent
  1999. * @timer: timer to be started when request is initiated
  2000. * @req_flags: flags for fsf_request
  2001. */
  2002. int zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
  2003. struct zfcp_unit *unit,
  2004. struct scsi_cmnd *scsi_cmnd,
  2005. int use_timer, int req_flags)
  2006. {
  2007. struct zfcp_fsf_req *req;
  2008. struct fcp_cmnd_iu *fcp_cmnd_iu;
  2009. unsigned int sbtype;
  2010. int real_bytes, retval = -EIO;
  2011. if (unlikely(!(atomic_read(&unit->status) &
  2012. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2013. return -EBUSY;
  2014. spin_lock(&adapter->req_q_lock);
  2015. if (!zfcp_fsf_sbal_available(adapter))
  2016. goto out;
  2017. req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
  2018. adapter->pool.fsf_req_scsi);
  2019. if (IS_ERR(req)) {
  2020. retval = PTR_ERR(req);
  2021. goto out;
  2022. }
  2023. zfcp_unit_get(unit);
  2024. req->unit = unit;
  2025. req->data = scsi_cmnd;
  2026. req->handler = zfcp_fsf_send_fcp_command_handler;
  2027. req->qtcb->header.lun_handle = unit->handle;
  2028. req->qtcb->header.port_handle = unit->port->handle;
  2029. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2030. scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
  2031. fcp_cmnd_iu = (struct fcp_cmnd_iu *) &(req->qtcb->bottom.io.fcp_cmnd);
  2032. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  2033. /*
  2034. * set depending on data direction:
  2035. * data direction bits in SBALE (SB Type)
  2036. * data direction bits in QTCB
  2037. * data direction bits in FCP_CMND IU
  2038. */
  2039. switch (scsi_cmnd->sc_data_direction) {
  2040. case DMA_NONE:
  2041. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2042. sbtype = SBAL_FLAGS0_TYPE_READ;
  2043. break;
  2044. case DMA_FROM_DEVICE:
  2045. req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
  2046. sbtype = SBAL_FLAGS0_TYPE_READ;
  2047. fcp_cmnd_iu->rddata = 1;
  2048. break;
  2049. case DMA_TO_DEVICE:
  2050. req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
  2051. sbtype = SBAL_FLAGS0_TYPE_WRITE;
  2052. fcp_cmnd_iu->wddata = 1;
  2053. break;
  2054. case DMA_BIDIRECTIONAL:
  2055. default:
  2056. retval = -EIO;
  2057. goto failed_scsi_cmnd;
  2058. }
  2059. if (likely((scsi_cmnd->device->simple_tags) ||
  2060. ((atomic_read(&unit->status) & ZFCP_STATUS_UNIT_READONLY) &&
  2061. (atomic_read(&unit->status) & ZFCP_STATUS_UNIT_SHARED))))
  2062. fcp_cmnd_iu->task_attribute = SIMPLE_Q;
  2063. else
  2064. fcp_cmnd_iu->task_attribute = UNTAGGED;
  2065. if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH))
  2066. fcp_cmnd_iu->add_fcp_cdb_length =
  2067. (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
  2068. memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
  2069. req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
  2070. fcp_cmnd_iu->add_fcp_cdb_length + sizeof(u32);
  2071. real_bytes = zfcp_qdio_sbals_from_sg(req, sbtype,
  2072. scsi_sglist(scsi_cmnd),
  2073. FSF_MAX_SBALS_PER_REQ);
  2074. if (unlikely(real_bytes < 0)) {
  2075. if (req->sbal_number < FSF_MAX_SBALS_PER_REQ)
  2076. retval = -EIO;
  2077. else {
  2078. dev_err(&adapter->ccw_device->dev,
  2079. "Oversize data package, unit 0x%016Lx "
  2080. "on port 0x%016Lx closed\n",
  2081. (unsigned long long)unit->fcp_lun,
  2082. (unsigned long long)unit->port->wwpn);
  2083. zfcp_erp_unit_shutdown(unit, 0, 131, req);
  2084. retval = -EINVAL;
  2085. }
  2086. goto failed_scsi_cmnd;
  2087. }
  2088. zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
  2089. if (use_timer)
  2090. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  2091. retval = zfcp_fsf_req_send(req);
  2092. if (unlikely(retval))
  2093. goto failed_scsi_cmnd;
  2094. goto out;
  2095. failed_scsi_cmnd:
  2096. zfcp_unit_put(unit);
  2097. zfcp_fsf_req_free(req);
  2098. scsi_cmnd->host_scribble = NULL;
  2099. out:
  2100. spin_unlock(&adapter->req_q_lock);
  2101. return retval;
  2102. }
  2103. /**
  2104. * zfcp_fsf_send_fcp_ctm - send SCSI task management command
  2105. * @adapter: pointer to struct zfcp-adapter
  2106. * @unit: pointer to struct zfcp_unit
  2107. * @tm_flags: unsigned byte for task management flags
  2108. * @req_flags: int request flags
  2109. * Returns: on success pointer to struct fsf_req, NULL otherwise
  2110. */
  2111. struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_adapter *adapter,
  2112. struct zfcp_unit *unit,
  2113. u8 tm_flags, int req_flags)
  2114. {
  2115. struct qdio_buffer_element *sbale;
  2116. struct zfcp_fsf_req *req = NULL;
  2117. struct fcp_cmnd_iu *fcp_cmnd_iu;
  2118. if (unlikely(!(atomic_read(&unit->status) &
  2119. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2120. return NULL;
  2121. spin_lock(&adapter->req_q_lock);
  2122. if (!zfcp_fsf_sbal_available(adapter))
  2123. goto out;
  2124. req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
  2125. adapter->pool.fsf_req_scsi);
  2126. if (IS_ERR(req))
  2127. goto out;
  2128. req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
  2129. req->data = unit;
  2130. req->handler = zfcp_fsf_send_fcp_command_handler;
  2131. req->qtcb->header.lun_handle = unit->handle;
  2132. req->qtcb->header.port_handle = unit->port->handle;
  2133. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2134. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2135. req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
  2136. sizeof(u32);
  2137. sbale = zfcp_qdio_sbale_req(req);
  2138. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
  2139. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2140. fcp_cmnd_iu = (struct fcp_cmnd_iu *) &req->qtcb->bottom.io.fcp_cmnd;
  2141. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  2142. fcp_cmnd_iu->task_management_flags = tm_flags;
  2143. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  2144. if (!zfcp_fsf_req_send(req))
  2145. goto out;
  2146. zfcp_fsf_req_free(req);
  2147. req = NULL;
  2148. out:
  2149. spin_unlock(&adapter->req_q_lock);
  2150. return req;
  2151. }
  2152. static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
  2153. {
  2154. if (req->qtcb->header.fsf_status != FSF_GOOD)
  2155. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2156. }
  2157. /**
  2158. * zfcp_fsf_control_file - control file upload/download
  2159. * @adapter: pointer to struct zfcp_adapter
  2160. * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
  2161. * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
  2162. */
  2163. struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
  2164. struct zfcp_fsf_cfdc *fsf_cfdc)
  2165. {
  2166. struct qdio_buffer_element *sbale;
  2167. struct zfcp_fsf_req *req = NULL;
  2168. struct fsf_qtcb_bottom_support *bottom;
  2169. int direction, retval = -EIO, bytes;
  2170. if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
  2171. return ERR_PTR(-EOPNOTSUPP);
  2172. switch (fsf_cfdc->command) {
  2173. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  2174. direction = SBAL_FLAGS0_TYPE_WRITE;
  2175. break;
  2176. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  2177. direction = SBAL_FLAGS0_TYPE_READ;
  2178. break;
  2179. default:
  2180. return ERR_PTR(-EINVAL);
  2181. }
  2182. spin_lock_bh(&adapter->req_q_lock);
  2183. if (zfcp_fsf_req_sbal_get(adapter))
  2184. goto out;
  2185. req = zfcp_fsf_req_create(adapter, fsf_cfdc->command, 0, NULL);
  2186. if (IS_ERR(req)) {
  2187. retval = -EPERM;
  2188. goto out;
  2189. }
  2190. req->handler = zfcp_fsf_control_file_handler;
  2191. sbale = zfcp_qdio_sbale_req(req);
  2192. sbale[0].flags |= direction;
  2193. bottom = &req->qtcb->bottom.support;
  2194. bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
  2195. bottom->option = fsf_cfdc->option;
  2196. bytes = zfcp_qdio_sbals_from_sg(req, direction, fsf_cfdc->sg,
  2197. FSF_MAX_SBALS_PER_REQ);
  2198. if (bytes != ZFCP_CFDC_MAX_SIZE) {
  2199. retval = -ENOMEM;
  2200. zfcp_fsf_req_free(req);
  2201. goto out;
  2202. }
  2203. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  2204. retval = zfcp_fsf_req_send(req);
  2205. out:
  2206. spin_unlock_bh(&adapter->req_q_lock);
  2207. if (!retval) {
  2208. wait_event(req->completion_wq,
  2209. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  2210. return req;
  2211. }
  2212. return ERR_PTR(retval);
  2213. }