zfcp_fsf.c 68 KB

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